The chat conversation with the bot is triggered by the sequence illustrated in the diagram below:
A chat conversation is initiated the moment a user clicks on the "Test" button to start the conversation. Below, we will cover:
Requests made by the FE
Once clicked, the following requests are made by the FE:
- (OPTIONAL) GET /webbot/api/webchat/{botId}/config/
If needed, the chat client can get the Bot configuration info or settings, persistent menu, etc. The JSON returned by this endpoint is as follows:{
"image_url":null,
"persistent_menu":[
],
"styles":{
"header":{
"backgroundColor":"#0000ff"
},
"send_button":{
"backgroundColor":"#2ab4c0",
"color":"#ffffff"
},
"messages":{
"other":{
"backgroundColor":"#f5f5f5",
"color":"#000000"
},
"me":{
"backgroundColor":"#e91e63",
"color":"#ffffff"
},
"button":{
"backgroundColor":"#f2f6f9",
"color":"#000000"
}
},
"font":{
"fontFamily":"'Roboto', sans-serif"
}
}
} - WebSocket connection (WS://) /webbot/api/webchat/{botId}/
The WebSocket connection allows for flawless asynchronous interaction between the Client and the bot. At the very start of a conversation, the chat Client automatically (in most instances) sends an empty message to the bot in order to receive back the beginning message from the bot. Once the beginning message is received and seen in the webchat, this implies the conversation has been successfully initiated.
The simplest JSON messages sent in the web socket between the Client and bot conform to the following scheme:{
"message": {
"from": "human",
"user_profile": {},
"ref": null,
"user_id": "webbot:2d6bdb10-b237-11ea-a038-abed322efde6",
"timestamp": 1592576064,
"attachments": [],
"id": "1592576064324",
"actions": [
{
"type": "text",
"text": ""
}
]
}
}From here onward, the conversation has been initiated, and the user can start interacting with the bot.
Whitelist domaining feature
This feature is used when interacting with the Chat API to control and validate access to a bot.
A bot may have a domain in its whitelist attribute within its configuration settings, like below:
{ "image_url":null, "persistent_menu":[ ], "styles":{...}, "send_button":{...}, "messages":{...}, "font":{...},
"whitelist": [] // whitelist list } }
This would mean that any other domains (with the exception of those accepted by the bot platform generally) other than those in the bot's whitelist attribute trying to access the Bot configuration settings would be denied access and hence would fail to interact with the Chat API with a 403 error.