For full documentation, please head to LiveChat Docs.
The package can be installed directly from NPM.
npm i @livechat/chat-sdk
||Call a different API version than the default one.|
||Display all messages exchanged with the LiveChat API.|
||Specify a data center. Possible values:
const chatSDK = debug: true
To use Chat SDK, you will need to provide an access token authorizing you with the Agent Chat API.
If you don't know how to get one, make sure to check out these resources:
It intializes the WebSocket connection, attaches event listeners, and then logs in the Agent.
||See Authorization to learn how to get an access token. Optionally, you can acquire it directly from Accounts SDK and pass it in to the
It clears any stored resources, removes all listeners, and disconnects from the network. After using this method you won't be able to use the destroyed SDK instance.
It allows you to get information about the currently logged in Agent.
It sends a plain text message.
||Id of chat that you want to send a message to.|
const chatId = 'PJ0MRSHTDG'const message = 'Hello world'chatSDK
How to create other methods - methodFactory
This SDK supports the RTM transport. For that reason, make sure you use the Agent Chat API RTM reference. When creating your custom methods, base on the payloads from the Agent Chat RTM API methods.
In the example below, we're creating a custom method that returns chat thread summaries. As you can see in the documentation, only
chat_id is required, but you can include other optional parameters in your custom method.
const getChatThreadsSummary = chatSDK
The on method subscribes to emitted events.
Here's what you can listen for:
||You've been successfully logged in. You're now ready to use all API methods.|
|Pushes||Refer to documentation.|
The once method subscribes to emitted events and unsubscribes right after the callback function has been called.
The off method unsubsribes from emitted events.
Simple Agent - Example
To show you Chat SDK in action, we've prepared a sample app, Simple Agent . It's primary function is to send text messages. Apart from that, it gives you access to previous conversations, as well as the info about the current Agent.
To run the app, follow these 3 steps:
Create an app Building Blocks -> Authorization in Developer Console.
Paste your Client Id into the
Run Simple Agent with the following commands:
npm run install-example //install dependenciesnpm run start-example //start the app
To start a chat, log in to you LiveChat account and choose the Preview live option available in the Settings tab. You'll now be able to receive messages and respond to them from within Simple Agent.
It's worth mentioning that all functions invoked before logging in are queued. Once you're logged in, they are executed in the same order as they were invoked.
If you find some bugs or have trobules implementing the code on your own, please create an issue on this repo.
If you're new to LiveChat
LiveChat is an online customer service software with live support, help desk software, and web analytics capabilities. It's used by more than 28,000 companies all over the world. For more info, check out LiveChat for Developers.