How to use Chat API

Updated on September 20, 2022

Alli answers questions automatically – whether they are through the Dashboard, SDK, or through API calls. Accessing a Project Skill flow via API is particularly useful if you are building your own UI or integrating Alli with other services.

In this example, we will be using Postman to make API calls. To find more information on the API calls being used, please see our Alli API Documentation.

Starting a Conversation

Make a call to Start Conversation.

  1. Create a POST call to the URL given in the documentation
  2. Create a header key/value pair with ‘API-KEY’. This can be found in the Settings menu of the Alli Dashboard
  3. Create a header key/value pair with ‘OWN-USER-ID’. This can be any identifier you would like
  4. Create a header key/value pair with ‘Content-Type’ being ‘application/json’

Within the body, add raw JSON data for placement. If your Project Skill does not have any condition sets within the Placement tab on the Dashboard, simply leave placement blank as shown above. Once that is completed, send the call.

  1. From the response, we can see our conversation ID highlighted in yellow. You will need this ID in order to send chats and continue the conversation.
  2. Within “chats”, we can see the first two messages that the AnswerBot is sending highlighted in red.

The response is in Draft.js format. For more information and the library Alli is using, please see documentation here.

Send Chat

Once the conversation has been started, create a new call to Send a Chat.

  1. Create a POST call to the URL given in the documentation
  2. Create a header key/value pair with ‘API-KEY’. This can be found in the Settings menu of the Alli Dashboard
  3. Create a header key/value pair with ‘Content-Type’ being ‘application/json’

Within the body, add raw JSON data for the conversation ID that was created from starting a conversation as already mentioned before. Also include the message or question you would like to send to the AnswerBot. Once that is completed, send the call.

  1. Within “responses”, we can see the question that is asked highlighted in yellow
  2. Within “responses”, we can see the answer to our question. Since there is a “knowledgeBasePreview”, this answer came from the Documents knowledge base
  3. Within “responses”, we can see that the AnswerBot has responded highlighted in yellow and is waiting for another chat to be sent

The response is in Draft.js format. For more information and the library Alli is using, please see documentation here.

  1. To send another chat, simply change the message in the body highlighted in yellow
  2. Resend the call
  3. Within “responses”, we can see the question asked and the response given. Since there is no “knowledgeBasePreview”, this answer comes from the Q&A knowledge base

The response is in Draft.js format. For more information and the library Alli is using, please see documentation here.

End Conversation by Agent

If needed, create a new call to End Conversation by Agent.

  1. Create a POST call to the URL given in the documentation
  2. Create a header key/value pair with ‘API-KEY’. This can be found in the Settings menu of the Alli Dashboard
  3. Create a header key/value pair with ‘Content-Type’ being ‘application/json’
  1. Within the body, add raw JSON data for the conversation ID that was created from starting a conversation as already mentioned before
  2. Send the call
  3. Within the response, we can see that the state of the conversation has been changed to “END_BY_AGENT”

For a better understanding of the conversation that was just completed, navigate to the Conversations page within the Dashboard. The questions and answers, as well as the user ID, can be seen in a more traditional sense as shown above.