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

Last updated