Sermo JavaScript Bundle documentation
Events sent to the broker will be sent to all other clients. This will enable clients to listen to the events it needs to in order to fullfill its responsibility. It is important that all clients can handle new events without breaking.
All events are using the following attributes:
directionspecifies where the event is routed to. There are three different directions.inbound- sent from customer and routed to bot and agent applications.outbound- sent from bot or agent applications to all applications, including customer.internal- sent from and to all applications except for customer applications.
typesets which type of event it is, e.i. text, typing, heartbeat, handover, etc.userIdis an unique id for the customers/users.
The events are all listed below and described in more detail in following sections:
inbound/startinbound/textinbound/heartbeatinbound/messages_readinbound/client_leftinbound/client_unloadinbound/typingoutbound/queue_numberoutbound/textoutbound/infooutbound/carouseloutbound/typing_onoutbound/typing_offoutbound/platform_closedoutbound/end_sessioninternal/handover_to_agentinternal/handover_to_queueinternal/claim_sessioninternal/customer_identifiedinternal/agent_doneinternal/application_heartbeat
Following are example scenarios that are quite different to give a broad understanding on how the system works. Almost all are important to keep the AHT down so it is important that they are implemented.
The agent application needs to listen for all events to be able to take over the session.
- A new customer opens a chat sessions from the web client, a
startevent is sent followed byheartbeatevents. - When the customer is typing a message the inbound
typingevent is sent continuously enabling the agent application to show what the customer is typing before the message is sent. - When the customer sends the first message an inbound
textevent is sent. - The bot replies by sending an outbound
textevent. - The bot identifies the customer and sends a
customer_identifiedevent. - The bot identifies customer intent and hands the session over to the proper queue by sending
handover_to_queueevent. - The agent application sends the outbound
infoevent telling the customer that the session has been placed in queue. - The agent application sends the outbound
queue_numberevent to show the customer current queue number. Additionalqueue_numberevents can be sent to update the queue number. - When the agent starts typing in the agent GUI an outbound
typing_onevent is sent and when the agent stops typing an outboundtyping_offis sent. - When the agent wants to end the session either
- send an internal
agent_doneto enable the customer to be handed over to another agent. Note that this will not close the session and additional inbound events may be sent. - send an outbound
end_sessionto close the session permanently.
- send an internal
- When the customer closes the chat window an inbound
client_leftevent is sent.
- The bot identifies customer intent and who the customer is.
- The bot handover the session by sending an internal
handover_to_agentevent and the session is added to the queue. - The bot makes sure that the customer is still there and then handing the session back to the agent application by sending a
handover_to_agentevent. - The agent application assigns the session to an agent as it would be first in line.
- A customer wants help with an invoice.
- After agent has helped the customer the agent hands over the session to the bot to end the session in the name of the agent. The agent selects this option by clicking on a button dedicated for this purpose.
- The bot asks if the customer would like help with somethings and the customer have an additional question regarding the invoice.
- So the bot hands the session back to the agent sending the
handover_to_agentevent. The session pops back up for the same agent. The customer never noticed that he left the agent for a short while.
- After the agent has helped the customer the agent clicks down the session and an internal
agent_doneevent is sent out. - The customer receives a message that the agent has left the session and if the customer want to get in contact again, it is only to send a new message.
- The customer sends a new message generating an inbound
textevent. - The customer is put into the queue first in line.
- An agent is working on three sessions.
- The agent application calculate the probabilities that the customer is still there for all three sessions.
- Since the sum of all three probabilities add upp to 1.99 a new session is distributed to the agent.
Following attributes are used for almost all events.
typesets which type of event it is, e.i. text, typing, heartbeat, handover, etc.userIdis an unique id for the customers/users. For the web a new unique id is generated for every new visit while for Messenger the user id connected to the facebook account will be used which is persistent over time.
Inbound events are events sent from customer to the bot or the agent application.
Sent when a customer starts a new conversation. The params property will be an object representing some select query parameters that was used to open the conversation.
{
"type": "start",
"direction": "inbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d",
"params": {
// start parameters
}
}Inbound messages from the customer.
{
"type": "text",
"direction": "inbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d",
"text": "Jag vill ändra faktura 70557076"
}Inbound image from the customer with an appended text.
{
"type": "text",
"direction": "inbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d",
"text": "Some image related text",
"imageId": "some-image-id"
}The image can be retreived from http://sermo-api.comhem.com/images/IMAGE_ID
Inbound text events are sent from the client application as a response to a quick reply.
{
"type": "text",
"direction": "inbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d",
"text": "Selection 1",
"quickReplyPayload": "postback-alternative-1"
}Inbound heartbeat is sent from the customer client so that the system can track the stability of the connection and if the customer is still there.
{
"type": "heartbeat",
"direction": "inbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d"
}An inbound event with a timestamp on when the message was red by the customer.
{
"type": "messages_read",
"direction": "inbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d",
"text": "read",
"at": "2020-02-18T12:14:11.386Z"
}The customer has clicked down the chat window to close the chat.
{
"type": "client_left",
"direction": "inbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d",
"text": "Kunden har stängt chatten.",
"at": "2020-02-18T12:12:33.766Z"
}The customer has closed the browser, the tab, or refreshed to page. Using https://developer.mozilla.org/en-US/docs/Web/API/Window/unload_event to detect this.
{
"type": "client_unload",
"direction": "inbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d",
"at": "2020-02-18T12:10:18.968Z"
}The inbound typing_on event is sent continuously when the customer is typing. This will enable the agent to see what the customer is about to send.
{
"type": "typing_on",
"direction": "inbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d",
"text": "Hej, jag mitt na",
"at": "2020-02-18T14:41:37.571Z"
}Outbound events are events sent from the bot or the agent to the customer.
Is sent when the customer is in the queue enabling the customer client to display the queue number for the customer.
{
"type": "queue_number",
"direction": "outbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d",
"queueNumber": 1
}Outbound text from the agent to a customer.
The avatarId and avatarUrl property of the agent is optional. If none of these two are passed sermo will default to a icon-avatar.
{
"type": "text",
"direction": "outbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d",
"text": "Jag skickar ett SMS till dig nu med betalningsuppgifterna, det kommer plinga i din telefonen inom en minut.",
"agent": {
"id": "anan01",
"name": "Anders Andersson",
"type": "human",
"avatarId": "avatar1",
"avatarUrl": "https://some-url.png"
}
}Outbound text sent from the bot to the customer. The client will simulate the typing for given number of milliseconds before displaying the message.
{
"type": "text",
"direction": "outbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d",
"text": "Hej!",
"typing": 1000,
"agent": {
"id": "bot",
"name": "Bot",
"avatarId": "avatar1",
"avatarUrl": "https://some-url.png"
}
}Outbound image sent from the agent to the customer.
{
"type": "text",
"direction": "outbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d",
"text": "Some image related text",
"imageId": "some-image-id",
"agent": {
"id": "bot",
"name": "Bot",
"avatarId": "avatar1",
"avatarUrl": "https://some-url.png"
}
}The image can be retreived from http://sermo-api.comhem.com/images/IMAGE_ID
Outbound text messages can contain zero or more quick replies defined in the quickReplies property. Quick replies will be rendered as buttons in the client application and gives the customer a set of predefined actions.
{
"type": "text",
"direction": "outbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d",
"text": "Some image related text",
"imageId": "some-image-id",
"quickReplies": [
{
"type": "postback",
"text": "Alternativ 1",
"payload": "postback-alternative-1"
}
],
"agent": {
"id": "bot",
"name": "Bot",
"avatarId": "avatar1",
"avatarUrl": "https://some-url.png"
}
}There are two types of quick replies:
-
postback- when the customer clicks selections, an inboundtextevent will be sent with thequickReplyPayloadset to the corresponding payload."type": "postback", "text": "Button text", "payload": "postback-alternative-1"
Outbound info event from the agent or bot to a customer. These events can be sent at any time. They will be displayed differently from normal text messages.
{
"type": "info",
"direction": "outbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d",
"text": "Chatten har placerats i kön \"Com Hem allmänt\""
}Outbound event sent when the agent started typing a message.
{
"type": "typing_on",
"direction": "outbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d"
}Outbound event sent when the agent stopped typing a message.
{
"type": "typing_off",
"direction": "outbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d"
}Is sent by the agent application when a platform is closed to customer enabling the customer client to tell the customer.
{
"type": "platform_closed",
"direction": "outbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d"
}Is sent by the agent application when a chat session has ended. The customer is then forced to initialize a new session to continue writing. reasonText is an optional string that will be presented to the customer.
{
"type": "end_session",
"direction": "outbound",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d",
"reasonText": "Agenten har lämnat chatten"
}Internal events are events sent between internal broker clients, that is not sent to customer clients.
Internal event used when a session needs to be handed over from bot to agent.
{
"type": "handover_to_agent",
"direction": "internal",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d"
}Internal event used when a session needs to be transfered from one queue to another.
{
"type": "handover_to_queue",
"direction": "internal",
"queueId": "other_queue",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d"
}{
"type": "claim_session",
"direction": "internal",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d",
"agentId": "some-agent"
}Internal event when bot or agent system have identified the customer.
{
"type": "customer_identified",
"direction": "internal",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d",
"brandId": "comhem",
"customerId": "1234567"
}Internal event sent when the agent closes the session.
{
"type": "agent_done",
"direction": "internal",
"userId": "8a8b5c18-c0dd-467b-bd77-7e7685fadf6d"
}Internal event sent to notify sermo that the specified application is alive and ready. This event should be sent periodically with a period of 30s (unless otherwise agreed).
availablespecifies whether or not the application is currently available to receive chat sessions. I.e., set tofalseoutside of chat opening hours.
Example payload:
{
"type": "application_heartbeat",
"direction": "internal",
"available": true
}To upload images from the agent.
{
"image": "b64-image-content"
}This endpoint responds with the location of the image within it's location header. The id of the image is the last part of that url and that is the id that should be passed with the corresponding text event.
An api-key needs to be supplied as a query parameter.
Used to get images uploaded either by clients or agents.
