Private Conversations

Introduction

In Index Network, you can engage in conversations with one or multiple Indexes. This interaction is facilitated by our storage system, which processes and stores information to allow natural, meaningful dialogue. Whether it's querying for specific information or engaging in an ongoing conversation, the Index Network enables seamless communication with its indexed data.

To start a conversation and interact with the data, follow these steps:

// Create a conversation
const conversationParams = {
  sources: [index.id],
  summary: "Mock summary",
  members: [indexClient.wallet.address],
};
const conversation = await indexClient.createConversation(conversationParams);

// Add a message to the conversation
const messageParams = {
  role: "user",
  content: "How do you do this?",
};
const message = await indexClient.createMessage(conversation.id, messageParams);

// Retrieve messages from the conversation
const { messages } = await indexClient.getConversation(conversation.id);
console.log(messages);

The response should look something like this:

{
  "id": "message-id",
  "content": "How do you do this?",
  "role": "user",
  "createdAt": "timestamp"
}

Listening to Conversation Updates

The Index Client SDK allows you to listen for updates to a conversation in real-time. This is useful for applications that need to react to new messages or changes in a conversation.

Here is an example of how you can use the listenToConversationUpdates method to handle real-time updates in a conversation:

const conversationId = "your-conversation-id";

const handleMessage = (data: any) => {
  console.log("New message received:", data);
  // Handle the new message data
};

const handleError = (error: any) => {
  console.error("Error receiving updates:", error);
  // Handle the error
};

const stopListening = indexClient.listenToConversationUpdates(
  conversationId,
  handleMessage,
  handleError,
);

Interacting Through Conversations

Get indexes by DID

GEThttps://dev.index.network/api/dids/{did}/indexes
Path parameters
did*string

Decentralized Identifier

Response

Successful operation

Request
const response = await fetch('https://dev.index.network/api/dids/{did}/indexes', {
    method: 'GET',
    headers: {},
});
const data = await response.json();

Create Conversation

POSThttps://dev.index.network/api/api/conversations
Authorization
Body
object
Response

Successful response

Body
any
Request
const response = await fetch('https://dev.index.network/api/api/conversations', {
    method: 'POST',
    headers: {
      "Authorization": "Bearer DID_SESSION_SERIALIZED",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      "sources": [
        "did:pkh:eip155:1:0x1b9Aceb609a62bae0c0a9682A9268138Faff4F5f",
        "kjzl6kcym7w8yaa2ylkzbqzcgh8str1hnofps4bfganauuk2v90uom48nddcog3"
      ],
      "members": [
        "did:key:z6Mkvrp9jeDqftYPzknEPnSb6majnfak8LqQfXZhYtF8vSFX",
        "did:key:z6Mki5MGUYbXFNYiVisA9rhjqjJvd1ikBAf2u4qhnKPM5k3a"
      ]
    }),
});
const data = await response.json();

Get Conversation

GEThttps://dev.index.network/api/api/conversations/{conversationId}
Authorization
Path parameters
conversationId*string

Conversation ID

Response

Successful response

Body
any
Request
const response = await fetch('https://dev.index.network/api/api/conversations/{conversationId}', {
    method: 'GET',
    headers: {
      "Authorization": "Bearer DID_SESSION_SERIALIZED"
    },
});
const data = await response.json();

Update Conversation

PUThttps://dev.index.network/api/api/conversations/{conversationId}
Authorization
Path parameters
conversationId*string

Conversation ID

Body
object
Response

Successful response

Body
any
Request
const response = await fetch('https://dev.index.network/api/api/conversations/{conversationId}', {
    method: 'PUT',
    headers: {
      "Authorization": "Bearer DID_SESSION_SERIALIZED",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      "sources": [
        "did:pkh:eip155:1:0x1b9Aceb609a62bae0c0a9682A9268138Faff4F5f"
      ],
      "summary": "summary of the conversation, just for listing purposes."
    }),
});
const data = await response.json();

Delete Conversation

DELETEhttps://dev.index.network/api/api/conversations/{conversationId}
Authorization
Path parameters
conversationId*string

Conversation ID

Response

Successful response

Body
any
Request
const response = await fetch('https://dev.index.network/api/api/conversations/{conversationId}', {
    method: 'DELETE',
    headers: {
      "Authorization": "Bearer DID_SESSION_SERIALIZED"
    },
});
const data = await response.json();

Listen Conversation Updates

GEThttps://dev.index.network/api/api/conversations/{conversationId}/updates
Authorization
Path parameters
conversationId*string

Conversation ID

Query parameters
Response

Successful response

Body
any
Request
const response = await fetch('https://dev.index.network/api/api/conversations/{conversationId}/updates', {
    method: 'GET',
    headers: {
      "Authorization": "Bearer DID_SESSION_SERIALIZED"
    },
});
const data = await response.json();

Create Message

POSThttps://dev.index.network/api/api/conversations/{conversationId}/messages
Authorization
Path parameters
conversationId*string

Conversation ID

Body
object
Response

Successful response

Body
any
Request
const response = await fetch('https://dev.index.network/api/api/conversations/{conversationId}/messages', {
    method: 'POST',
    headers: {
      "Authorization": "Bearer DID_SESSION_SERIALIZED",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      "role": "user",
      "content": "give me a very long hello world python code"
    }),
});
const data = await response.json();

Update Message with Delete After

PUThttps://dev.index.network/api/api/conversations/{conversationId}/messages/{messageId}
Authorization
Path parameters
conversationId*string

Conversation ID

messageId*string

Message ID

Query parameters
Body
object
Response

Successful response

Body
any
Request
const response = await fetch('https://dev.index.network/api/api/conversations/{conversationId}/messages/{messageId}', {
    method: 'PUT',
    headers: {
      "Authorization": "Bearer DID_SESSION_SERIALIZED",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      "role": "user",
      "content": "What is Index Network and how is it related to Ceramic?"
    }),
});
const data = await response.json();

Delete Message with Delete After

DELETEhttps://dev.index.network/api/api/conversations/{conversationId}/messages/{messageId}
Authorization
Path parameters
conversationId*string

Conversation ID

messageId*string

Message ID

Query parameters
Response

Successful response

Body
any
Request
const response = await fetch('https://dev.index.network/api/api/conversations/{conversationId}/messages/{messageId}', {
    method: 'DELETE',
    headers: {
      "Authorization": "Bearer DID_SESSION_SERIALIZED"
    },
});
const data = await response.json();

Last updated