@cognigy/webchat-client
TypeScript icon, indicating that this package has built-in type declarations

4.3.1 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @cognigy/webchat-client

Weekly Downloads

1

Version

4.3.1

License

SEE LICENSE IN LICENSE

Unpacked Size

9.32 kB

Total Files

10

Last publish

Collaborators

  • kwinto
  • x.jorda
  • lkolapp
  • dshire
  • mayrbenjamin92
  • pedily