Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.
/ WebchatClient Public archive

A JavaScript client that can be used to connect to Cognigy.AI Webchat Endpoints

License

Notifications You must be signed in to change notification settings

Cognigy/WebchatClient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚨 Deprecation Notice: This Repository is Inactive and no longer maintained 🚨

Cognigy Webchat Client

This package is used to create a connection to Cognigy.AI via a Webchat Endpoint.
You can read about setting up a Webchat Endpoint in our platform documentation.
Internally, this package builds up opon the SocketClient.

Installation

Install this module using the following npm command

npm install @cognigy/webchat-client

Usage

const WebchatClient = require('webchat-client');

(async () => {
    // create a client instance with a webchat config url
    const client = new WebchatClient('https://webchat.config.url');

    // register a handler for messages
    client.on('output', output => {
        console.log("Text: " + output.text + "   Data: " + output.data);
    });

    // establish a socket connection (returns a promise)
    await client.connect();
    
    // send a message with text, text and data, data only
    client.sendMessage('hello there');
    client.sendMessage('hello there', { color: 'green' });
    client.sendMessage('', { color: 'green' });
})()

Internal Socket Events

You can subscribe to the following events from the WebchatClient:

client.on('finalPing', () => {
    console.log('bot is done processing a message');
});

You can read about the events you can subscribe to in the SocketClient repository

Options

You can pass a second argument to WebchatClient to set additional options as follows:

const client = new WebchatClient('https://webchat.config.url', {
    userId: 'user1234'
});
Name Type Default Description '
channel string "webchat-client" the name of the channel (can be used for analytics purposes)
forceWebsockets boolean true on IE and Safari, otherwise false if this is enabled, there will be no fallback to http polling

You can read about the rest of the options you can pass in the SocketClient repository.

About

A JavaScript client that can be used to connect to Cognigy.AI Webchat Endpoints

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published