JavaScript Socket API

JavaScript Socket API Chat Library that correspond to processes that transform your Custom Channel into a fully functional AI Chatbot.

This is the Chat Library of the JavaScript Socket API that is currently available and compatible with the Captivate Chat platform. These are all intended to create processes that will transform your Custom Channel into a full-blown AI Chatbot.

They are also available here.


Basic Setup

Import and initialize the API client:

import { CaptivateChatAPI } from 'captivate-chat-api';

const api = new CaptivateChatAPI('YOUR_API_KEY');

// Connect to the WebSocket server
await api.connect();

Create a Conversation

Create a new conversation with the following options:

  1. Basic setup with just a user ID:

    const conversation = await api.createConversation('user123');
  2. Include user information and custom data:

    const conversation = await api.createConversation(
      'user123',
      {
        name: 'John Doe',
        email: '[email protected]'
      },
      {
        customField: 'value'
      },
      'user-first' // Start the conversation with user-first or bot-first mode
    );

Send and Receive Messages

  1. Send a message to the conversation:

  2. Listen for responses:

Handle Events

Use event listeners to handle various updates, errors, or custom actions:

  1. Error handling:

  2. Updates on conversation status:

  3. Handling custom actions:

Get Conversation History

Retrieve the transcript of a conversation:

Delete Conversation

Delete the current conversation

Retrieve User Conversations

Fetch a list of conversations associated with a specific user ID:

Delete User Conversations

Delete list of conversations associated with a specific user ID:

Last updated

Was this helpful?