{"id":17801,"date":"2016-07-12T13:58:24","date_gmt":"2016-07-12T13:58:24","guid":{"rendered":"http:\/\/apidocs.kore.com\/?post_type=docs&#038;p=3754"},"modified":"2023-09-11T07:16:08","modified_gmt":"2023-09-11T06:16:08","slug":"bots-platform-api-reference","status":"publish","type":"post","link":"https:\/\/developer.kore.ai\/v10-1\/docs\/bots\/sdks\/bots-platform-api-reference\/","title":{"rendered":"Web Socket Connect &amp; RTM"},"content":{"rendered":"<section class=\"l-section wpb_row height_auto\"><div class=\"l-section-h i-cf\"><div class=\"g-cols vc_row type_default valign_top\"><div class=\"vc_col-sm-12 wpb_column vc_column_container\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<p>Kore.ai SDK libraries use the WebSocket channel to communicate with the Kore.ai XO Platform. When using the Kore.ai XO Platform SDKs, only the JWT token must be generated and passed to the client SDK.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"Initializing\">Initializing<\/span><\/h2>\n<p>This section describes how the Kore.ai SDKs initialize a WebSocket session and is for reference only.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Prerequisites\">Prerequisites<\/span><\/h3>\n<ul>\n<li>Make sure to register the client app.<\/li>\n<li>Generate the Client ID and Secret Key in the Kore.ai XO Platform.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Step1\"><strong>Step1<\/strong><\/span><\/h3>\n<p>The JWT is generated on the server side using client app credentials and user information. The JWT is passed to the client app.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"Step_2\"><strong>Step 2<\/strong><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">The client app exchanges the JWT token for the <code>accessToken<\/code>\u00a0on the XO Platform using the following XO Platform endpoint.<br \/>\n<code>POST<br \/>\nhttps:\/\/{{APIHost}}\/api\/1.1\/oAuth\/token\/jwtgrant<\/code><\/span><\/p>\n<p>This section describes how to format the request to post a message in a chat\u00a0with the <code><span style=\"font-weight: 400;\">\/api\/1.1\/<\/span><span style=\"font-weight: 400;\">oAuth<\/span><span style=\"font-weight: 400;\">\/token\/jwtgrant<\/span><\/code>\u00a0endpoint based on\u00a0the following JSON syntax.<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">{\r\n    \"assertion\": \u201c{{JWT Token}}\u201d,\r\n    \"botInfo\": {\r\n        \"chatBot\": \"{{Bot Name}}\",\r\n        \"taskBotId\": \"st-f74a3430-3b19-55a3-be41-1ab1a35c4685\"\r\n    }\r\n)<\/pre>\n<h4><strong>Sample cURL<\/strong><\/h4>\n<pre>curl 'https:\/\/{{APIHost}}\/api\/1.1\/oAuth\/token\/jwtgrant' \\\r\n  -H 'content-type: application\/json' \u00a0\\\r\n  --data-binary '{\"assertion\":\"{JWT Token}}\",\"botInfo\":{\"chatBot\":\"{{Bot Name}}\",\"taskBotId\":\"st-f74a3430-3b19-55a3-be41-1ab1a35c4685\"}}<\/pre>\n<h4>Response<\/h4>\n<p>The following sample JSON response shows the <code>accessToken<\/code> and the user associated with that token.<\/p>\n<pre class=\"lang:JSON decode:true \">{\r\n   \"authorization\": {\r\n\t\"accessToken\": \"ZdV2OL_UZ_MvHog-rs8k9KJFNWBICvquSc3jpeaRDE_-\",\r\n                 \/\/ access token to user at \/api\/rtm\r\n\t\"token_type\": \"bearer\",\r\n\t\"expiresDate\": \"2019-06-28T06:52:23.160Z\",\r\n                \/\/expiry date for access token\r\n\t\"issuedDate\": \"2019-02-28T06:52:23.160Z\" \r\n               \/\/access token issuedDate\r\n\t},\r\n   \"userInfo\": {\r\n\t\"userId\": \"u-4f6c68e0-551a-5dd9-a33a-1af3dc9cadcc\", \r\n                 \/\/ user id which is unique for the user and can be used at bot messages api\r\n\t\"accountId\": \"5c66514d09ab3565deb2e30a\", \r\n                 \/\/ account id in which the user is present\r\n\t\"orgId\": \"o-88aad7f1-0d32-5765-93d7-f40c80402114\",\r\n                \/\/ organization id of the user\r\n\t\"identity\": \"cs-5b08ed1e-5fa7-5aaa-9c21-28bf8c90b739\/admin1212@qakore.xyz\", \r\n                \/\/identity of user from the channel perspective\r\n\t\"enrollType\": \"free\", \r\n                \/\/Enrollment type (Free\/ Paid etc)\r\n\t\"managedBy\": \"5c66514d09ab3565deb2e30a\", \r\n                \/\/(The account id)\r\n\t\"fName\": \"\", \r\n                \/\/first name of the user\r\n                \/\/ (fetched if the user is registered on the Platform)\r\n\t\"lName\": \"\" \r\n                \/\/last name of the user\r\n                \/\/ (fetched if the user is registered on the Platform)\r\n\t}\r\n}<\/pre>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"Step_3\"><strong>Step 3<\/strong><\/span><\/h3>\n<p>The client app acquires the WebSocket URL using the following endpoint.<\/p>\n<p><code>POST<br \/>\nhttps:\/\/{{APIHost}}\/api\/1.1\/rtm\/start<\/code><\/p>\n<p>This section describes how to format the request to get the web socket URL\u00a0with the <code>\/api\/1.1\/rtm\/start<\/code>\u00a0endpoint based on\u00a0the following JSON syntax.<\/p>\n<p class=\"note\"><strong>Note:<\/strong> This URL is short-lived and expires in 30 seconds. You must ensure it is used to connect before\u00a0expiration.<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">{\r\n    \"botInfo\": {\r\n        \"chatBot\": \"Twitter\",\r\n        \"taskBotId\": \"st-f74a3430-3b19-55a3-be41-1ab1a35c4685\"\r\n    }\r\n}<\/pre>\n<p>The <code>accessToken<\/code>\u00a0is passed in the <code>bearer<\/code> parameter in the Authorization header.<\/p>\n<h4><strong>Sample cURL<\/strong><\/h4>\n<pre>curl 'https:\/\/{{APIHost}}\/api\/1.1\/rtm\/start' \\\r\n  -H 'content-type: application\/json' \\\r\n  -H 'Authorization: bearer {{accessToken}}' \\\r\n  --data-binary '{\"botInfo\":{\"chatBot\":\"{{Bot Name}}\",\"taskBotId\":\"st-f74a3430-3b19-55a3-be41-1ab1a35c4685\"}'<\/pre>\n<h4>Response<\/h4>\n<p>The following sample JSON response shows the WebSocket URL.<\/p>\n<pre class=\"lang:default decode:true \">{\"url\":\"wss:\/\/xxx.yyy.com:443\/rtm\/bot?sid=GhKrtrEC61g7hAnmvKAVnJIHG0DS1Lzv\"}<\/pre>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"RTM_Channel_Events\"><span style=\"font-weight: 400;\">RTM Channel Events <\/span><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">The following real-time events can be exchanged between the client app\u00a0and the Kore.ai XO Platform<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"RTM_Client_Events\"><span style=\"font-weight: 400;\">RTM Client Events<\/span><\/span><\/h3>\n<p>This section describes the RTM Client Event JSON responses sent to the Kore.ai XO Platform from the client app over a WebSocket.<\/p>\n<p><strong>Event Type:<\/strong>\u00a0<code>\/bot.message<\/code><\/p>\n<p><strong>Description:<\/strong> Triggered when a user posts a message. The following payload is used to send a user-typed message to the XO Platform.<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">{\r\n    \"clientMessageId\": 1466692440896,\r\n    \"message\": {\r\n        \"body\": \"Here is the message.\",\r\n        \"attachments\": [\r\n\r\n      ]\r\n    },\r\n    \"resourceid\": \"\/bot.message\",\r\n    \"botInfo\": {\r\n        \"chatBot\": \"CNN\",\r\n        \"taskBotId\": \"st-8aaf0939-c34a-5976-8e2e-5c91e685b2ce\"\r\n    },\r\n    \"id\": 1466692440896\r\n}<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"RTM_Server_Events\"><span style=\"font-weight: 400;\">RTM Server Events<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">This section describes the RTM Server Event JSON responses sent to the client app over a WebSocket.<\/span><\/p>\n<p><strong>Event Type:<\/strong><code>ack<\/code><\/p>\n<p><strong>Description:<\/strong> An acknowledgment is sent whenever an event is received from the client app.<\/p>\n<p>The following payload is used to acknowledge an event from the client app.<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">{\r\n    \"ok\": true,\r\n    \"replyto\": 1466692440896,\r\n    \"message\": \"delivered\",\r\n    \"type\": \"ack\"\r\n}<\/pre>\n<p><strong>Event Type:<\/strong>\u00a0<code>bot_response<\/code><\/p>\n<p><strong>Description:<\/strong> An acknowledgment is sent whenever a message is processed from the client app.<\/p>\n<p>The following payload is sent when a message from the client app is processed.<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">{\r\n    \"type\": \"bot_response\",\r\n    \"from\": \"bot\",\r\n    \"message\": [\r\n        {\r\n            \"type\": \"text\",\r\n            \"cInfo\": {\r\n                \"body\": \" Hi.  \"\r\n            }\r\n      }\r\n   ],\r\n    \"botInfo\": {\r\n        \"chatBot\": \"CNN\",\r\n        \"taskBotId\": \"st-8aaf0939-c34a-5976-8e2e-5c91e685b2ce\"\r\n    },\r\n    \"createdOn\": \"2016-06-23T14:34:00.025Z\",\r\n    \"icon\": \"https:\/\/devbots.kore.com\/api\/getMediaStream\/market\/f-683e82be-fc25-5921-bf41-4104780f71c2.png\"\r\n}<\/pre>\n<p><strong>Event Type:<\/strong>\u00a0<code>user_message<\/code><\/p>\n<p><strong>Description:<\/strong>\u00a0Sent to the client app when a user enters and sends a message to the server from another simultaneous session.<\/p>\n<p>The following sample payload is sent to the client app.<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">{\r\n    \"botInfo\": {\r\n        \"chatBot\": \"CNN\",\r\n        \"taskBotId\": \"st-8aaf0939-c34a-5976-8e2e-5c91e685b2ce\"\r\n    },\r\n    \"from\": \"self\",\r\n    \"message\": {\r\n        \"body\": \"how are you doing \",\r\n        \"attachments\": []\r\n    },\r\n    \"id\": 1466692871803,\r\n    \"type\": \"user_message\"\r\n}<\/pre>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"Bot_Status_Event\"><span style=\"font-weight: 400;\">Bot Status Event<\/span><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">The following bot user event is exchanged and triggered between the client app and the Kore.ai XO Platform when a bot is active.<\/span><\/p>\n<p>This section describes the Bot Status Event JSON responses sent to the Kore.ai XO Platform from the client app over a WebSocket.<\/p>\n<p><strong>Event Type:<\/strong>\u00a0<code>\/bot_active<\/code><\/p>\n<p><strong>Description:<\/strong>Triggered when a WebSocket connection is established with the bot.<\/p>\n<p>The following payload is used to send a response message to the XO Platform.<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">{ \r\n  \"type\": \"bot_active\", \r\n  \"from\": \"bot\", \r\n   \"botInfo\": { \"chatBot\": \"Natasha\", \r\n   \"taskBotId\": \"st-2e2663f4-bc07-583a-b244-3d8e41d3d2ac\" }, \r\n   \"sessionId\": \"642d2f34f7eb45387a7be64e\", \"formMetaInfo\": \r\n{ \r\n   \"isSecured\": true, \r\n    \"formLinkExpiry\": 300, \r\n     \"submitExpiry\": 600\r\n}, \r\n\"traceId\": \"4a663e27051cd294\" \r\n}\r\n<\/pre>\n<p><b>Event Type:<\/b> <span style=\"font-weight: 400;\">\/<code>botKitUnreachable<\/code><\/span><\/p>\n<p><b>Description:<\/b><span style=\"font-weight: 400;\"> Send notification to the WebSDK channel as a WebSocket event when the BotKit is unreachable.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">By default, the notification says, \u201c\u2018Sorry, there was an error in continuing the conversation. Please retry.\u201d Developers can customize the message to make it more contextual or language specific for the end users.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The following payload is used to send a response message to the XO Platform.<\/span><\/p>\n<pre>{\r\n  \"type\": \"botKitUnreachable\",\r\n  \"from\": \"bot\",\r\n  \"botInfo\": {\r\n    \"chatBot\": \"new bot hangouts\",\r\n    \"taskBotId\": \"st-f3ad01a6-a034-519a-84ab-40043a4c368f\",\r\n    \"botType\": \"default\",\r\n    \"remoteAddress\": \"115.114.88.222\",\r\n    \"hostDomain\": \"https:\/\/bots.kore.ai\",\r\n    \"os\": \"Linux\",\r\n    \"device\": \"Other\",\r\n    \"userId\": \"u-f6b20c0b-c7bd-57e1-a762-d9a0590acefc\"\r\n  }\r\n  \"message\": \"Sorry, there was an error in continuing the conversation. Please retry.\",\r\n  \"traceId\": \"c070f2b7de24920a\",\r\n  \"timestamp\": 1693394943443\r\n} \r\n<\/pre>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"Form_Events\"><span style=\"font-weight: 400;\">Form Events<\/span><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">The following form events are exchanged and triggered between the client app and the Kore.ai XO Platform when a form based dialog task is invoked.<\/span><\/p>\n<p>This section describes the Form Event JSON responses sent to the Kore.ai XO Platform from the client app over a WebSocket.<\/p>\n<p><strong>Event Type:<\/strong>\u00a0<code>\/form_delivered<\/code><\/p>\n<p><strong>Description:<\/strong>Triggered when a form is delivered to a user.<\/p>\n<p>The following payload is used to send a response message to the XO Platform.<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">{ \r\n  \"type\": \"form_delivered\", \r\n  \"from\": \"bot\", \r\n   \"botInfo\": { \"chatBot\": \"Natasha\", \r\n   \"taskBotId\": \"st-2e2663f4-bc07-583a-b244-3d8e41d3d2ac\" }, \r\n   \"sessionId\": \"642d2f34f7eb45387a7be64e\", \"formMetaInfo\": \r\n{ \r\n   \"isSecured\": true, \r\n    \"formLinkExpiry\": 300, \r\n     \"submitExpiry\": 600\r\n}, \r\n\"traceId\": \"4a663e27051cd294\" \r\n} \r\n<\/pre>\n<p><strong>Event Type:<\/strong>\u00a0<code>\/form_submitted<\/code><\/p>\n<p><strong>Description:<\/strong>Triggered when a form is submitted by a user.<\/p>\n<p>The following payload is used to send a response message to the XO Platform.<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">{ \r\n  \"type\": \"form_submitted\", \r\n  \"from\": \"bot\", \r\n   \"botInfo\": { \"chatBot\": \"Natasha\", \r\n   \"taskBotId\": \"st-2e2663f4-bc07-583a-b244-3d8e41d3d2ac\" }, \r\n   \"sessionId\": \"642d2f34f7eb45387a7be64e\", \"formMetaInfo\": \r\n{ \r\n   \"isSecured\": true, \r\n    \"formLinkExpiry\": 300, \r\n     \"submitExpiry\": 600\r\n}, \r\n\"traceId\": \"4a663e27051cd294\" \r\n} \r\n<\/pre>\n<p><strong>Event Type:<\/strong>\u00a0<code>\/form_failure<\/code><\/p>\n<p><strong>Description:<\/strong> Triggered when a form fails for any reason.<\/p>\n<p>The following payload is used to send a response message to the XO Platform.<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">{ \r\n  \"type\": \"form_failure\", \r\n  \"from\": \"bot\", \r\n   \"botInfo\": { \"chatBot\": \"Natasha\", \r\n   \"taskBotId\": \"st-2e2663f4-bc07-583a-b244-3d8e41d3d2ac\" }, \r\n   \"sessionId\": \"642d2f34f7eb45387a7be64e\", \"formMetaInfo\": \r\n{ \r\n   \"isSecured\": true, \r\n    \"formLinkExpiry\": 300, \r\n     \"submitExpiry\": 600\r\n}, \r\n\"traceId\": \"4a663e27051cd294\" \r\n}\r\n<\/pre>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"Session_Events\"><span style=\"font-weight: 400;\">Session Events<\/span><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">The following session events are exchanged and triggered between the client app and the Kore.ai XO Platform when a session is invoked.<\/span><\/p>\n<p>This section describes the Session Event JSON responses sent to the Kore.ai XO Platform from the client app over a WebSocket.<\/p>\n<p><strong>Event Type:<\/strong>\u00a0<code>\/session_start<\/code><\/p>\n<p><strong>Description:<\/strong>Triggered when a session starts using an On-Connect event or message.<\/p>\n<p>The session starts in the following scenarios:<\/p>\n<ul>\n<li>When the On-Connect is enabled to open, refresh and disable a chat window.<\/li>\n<li>A message sent after 15 mins.<\/li>\n<li>A message is sent after the idle timeout mentioned in Manage Sessions.<\/li>\n<\/ul>\n<p>The following payload is used to send a response message to the XO Platform.<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">{ \r\n  \"type\": \"session_start\", \r\n  \"from\": \"bot\", \r\n  \"botInfo\": \r\n  { \r\n    \"chatBot\": \"jarvis_new_import\", \r\n    \"taskBotId\": \"st-496bf3e4-63de-5635-8fcb-db1f9356def8\", \r\n\"hostDomain\": \"http:\/\/localhost\", \r\n\"os\": \"Linux\", \r\n\"device\": \"Other\" \r\n}, \r\n\"sessionId\": \"6426bf7e916562382331ba89\", \r\n\"traceId\": \"a33d81825f3b1a77\" \r\n} \r\n<\/pre>\n<p><strong>Event Type:<\/strong>\u00a0<code>\/session_end<\/code><\/p>\n<p><strong>Description:<\/strong>Triggered when a session ends using an On-Connect event.<\/p>\n<p>The session ends in the following scenarios:<\/p>\n<ul>\n<li>When the On-Connect is enabled to close, refresh and disable a chat window.<\/li>\n<li>A session timeout after 15 mins.<\/li>\n<\/ul>\n<p>The following payload is used to send a response message to the XO Platform.<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">{ \r\n  \"type\": \"session_end\", \r\n  \"from\": \"bot\", \r\n  \"botInfo\": \r\n  { \r\n    \"chatBot\": \"jarvis_new_import\", \r\n    \"taskBotId\": \"st-496bf3e4-63de-5635-8fcb-db1f9356def8\", \r\n\"hostDomain\": \"http:\/\/localhost\", \r\n\"os\": \"Linux\", \r\n\"device\": \"Other\" \r\n}, \r\n\"sessionId\": \"6426bf7e916562382331ba89\", \r\n\"traceId\": \"a33d81825f3b1a77\" \r\n} \r\n<\/pre>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"Agent_Transfer_Events\"><span style=\"font-weight: 400;\">Agent Transfer Events<\/span><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">The following agent transfer events are exchanged and triggered between the client app and the Kore.ai XO Platform when an agent is invoked. For more information, see the <a href=\"https:\/\/developer.kore.ai\/v10-1\/integrations\/agent-transfer-integrations\/\">Agent Transfer Overview<\/a> article.<\/span><\/p>\n<p>This section describes the Agent Transfer Event JSON responses sent to the Kore.ai XO Platform from the client app over a WebSocket.<\/p>\n<p><strong>Event Type:<\/strong>\u00a0<code>\/agent_session_start<\/code><\/p>\n<p><strong>Description:<\/strong> Triggered when the chat is handed off to an agent.<\/p>\n<p>The following payload is used to send a response message to the XO Platform.<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">{ \r\n  \"type\": \"agent_session_start\", \r\n  \"from\": \"bot\", \r\n   \"botInfo\": { \"chatBot\": \"Natasha\", \r\n   \"taskBotId\": \"st-2e2663f4-bc07-583a-b244-3d8e41d3d2ac\" }, \r\n   \"sessionId\": \"642d2f34f7eb45387a7be64e\", \"formMetaInfo\": \r\n{ \r\n   \"isSecured\": true, \r\n    \"formLinkExpiry\": 300, \r\n     \"submitExpiry\": 600\r\n}, \r\n\"traceId\": \"4a663e27051cd294\" \r\n} \r\n<\/pre>\n<p><strong>Event Type:<\/strong>\u00a0<code>\/agent_session_end<\/code><\/p>\n<p><strong>Description:<\/strong>Triggered when the conversation with the agent is ended.<\/p>\n<p>The following payload is used to send a response message to the XO Platform.<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">{ \r\n  \"type\": \"agent_session_end\", \r\n  \"from\": \"bot\", \r\n   \"botInfo\": { \"chatBot\": \"Natasha\", \r\n   \"taskBotId\": \"st-2e2663f4-bc07-583a-b244-3d8e41d3d2ac\" }, \r\n   \"sessionId\": \"642d2f34f7eb45387a7be64e\", \"formMetaInfo\": \r\n{ \r\n   \"isSecured\": true, \r\n    \"formLinkExpiry\": 300, \r\n     \"submitExpiry\": 600\r\n}, \r\n\"traceId\": \"4a663e27051cd294\" \r\n} \r\n<\/pre>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"User_Input_Event\"><span style=\"font-weight: 400;\">User Input Event<\/span><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">The following user input event is exchanged and triggered between the client app and the Kore.ai XO Platform when the user input is required.<\/span><\/p>\n<p>This section describes the User Input Event JSON responses sent to the Kore.ai XO Platform from the client app over a WebSocket.<\/p>\n<p><strong>Event Type:<\/strong>\u00a0<code>\/waiting_for_user_input <\/code><\/p>\n<p><strong>Description:<\/strong>Triggered when the VA is waiting for user input. The input can come from an Entity, Confirmation, and Standard Responses.<\/p>\n<p>The following payload is used to send a response message to the XO Platform.<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">{ \r\n  \"type\": \"waiting_for_user_input\", \r\n  \"from\": \"bot\", \r\n   \"botInfo\": { \"chatBot\": \"Natasha\", \r\n   \"taskBotId\": \"st-2e2663f4-bc07-583a-b244-3d8e41d3d2ac\" }, \r\n   \"sessionId\": \"642d2f34f7eb45387a7be64e\", \"formMetaInfo\": \r\n{ \r\n   \"isSecured\": true, \r\n    \"formLinkExpiry\": 300, \r\n     \"submitExpiry\": 600\r\n}, \r\n\"traceId\": \"4a663e27051cd294\" \r\n}\r\n<\/pre>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"Get_Conversation_History\">Get Conversation History<\/span><\/h2>\n<p>The client app requests the XO Platform endpoint <code>\/api\/botmessages\/rtm?botId={{botId}}<\/code> using the access token as generated in Step 2 above to get the previous messages exchanged between the user and the chatbot. The response from the mentioned endpoint can be used to display the conversation history in the chat window. This section describes how to format the request to get the web socket URL with the <code>\/api\/botmessages\/rtm<\/code> endpoint based on the following JSON syntax.<\/p>\n<pre>GET\r\nhttps:\/\/{{APIHost}}\/api\/botmessages\/rtm?botId={{botId}}<\/pre>\n<p><strong>Query Parameters<\/strong>:<\/p>\n<ul>\n<li>botId(mandatory) : Bot ID, can be accessed from the bot\u2019s General Settings page.<\/li>\n<li>skip\/offset (optional) : The number of messages to be skipped.<\/li>\n<li>limit (optional) : The number of messages to be fetched.<\/li>\n<li>The <code>accessToken<\/code> to be passed along with bearer as the Authorization parameter in the header<\/li>\n<\/ul>\n<p><strong>Sample cURL<\/strong><\/p>\n<pre>curl 'https:\/\/{{APIHost}}\/api\/botmessages\/rtm?botId={{botId}}&amp;limit=10' \\\r\n  -H 'accept: application\/json' \\\r\n  -H 'Authorization: bearer -{{accessToken}}' \\\r\n  -H 'content-type: application\/json'<\/pre>\n<p><strong>Sample Response<\/strong><\/p>\n<pre>{\r\n  \"total\": 2,\r\n  \"moreAvailable\": false,\r\n  \"messages\": [\r\n    {\r\n      \"_id\": \"ms-8a83d099-dd93-5b6b-836b-ac77bdfe9d4a\",\r\n      \"channels\": [\r\n        {\r\n          \"type\": \"rtm\"\r\n        }\r\n      ],\r\n      \"type\": \"incoming\",\r\n      \"status\": \"sent to cs\",\r\n      \"createdBy\": \"u-211f287f-17c8-51ac-b768-15c68e19afb2\",\r\n      \"lmodifiedBy\": \"u-211f287f-17c8-51ac-b768-15c68e19afb2\",\r\n      \"lmodifiedOn\": \"2019-12-03T05:07:44.008Z\",\r\n      \"botId\": \"st-2f579dbf-9dc1-548c-972f-f19d33160a07\",\r\n      \"orgId\": \"o-44741779-1971-5ab9-a0f7-aaf4e21dbe4e\",\r\n      \"accountId\": \"5a675150ff600b3d7665d2a6\",\r\n      \"isBB\": 0,\r\n      \"ms\": 1,\r\n      \"chnl\": \"rtm\",\r\n      \"components\": [\r\n        {\r\n          \"_id\": \"cp-1edc5033-a9cb-5011-8b2b-5986b7fa45cc\",\r\n          \"cT\": \"text\",\r\n          \"data\": {\r\n            \"text\": \"Hi\"\r\n          },\r\n          \"thumbnails\": [\r\n           \r\n          ]\r\n        }\r\n      ],\r\n      \"createdOn\": \"2019-12-03T05:07:44.097Z\",\r\n      \"timestampValue\": 1575349664097,\r\n      \"__v\": 0,\r\n      \"lang\": \"en\",\r\n      \"sessionId\": \"5de5eda04cdcff145752dbf6\",\r\n      \"nodeType\": 0,\r\n      \"tr0_I\": \"dg-61e5609f-76e7-5c42-b66f-7bb8b3af2433:intent0\",\r\n      \"tr0_O\": \"dg-61e5609f-76e7-5c42-b66f-7bb8b3af2433:entity1:4a04988ee640428d1847fc433081be0b\",\r\n      \"tr0_T\": \"0\",\r\n      \"tr_isSS\": 1,\r\n      \"resourceid\": \"messagestore\",\r\n      \"tags\": {\r\n        \"messageTags\": [\r\n         \r\n        ],\r\n        \"userTags\": [\r\n         \r\n        ],\r\n        \"sessionTags\": [\r\n         \r\n        ]\r\n      }\r\n    },\r\n    {\r\n      \"_id\": \"ms-80e8dbf3-ca69-5ee2-a2c1-1c6a70100c08\",\r\n      \"channels\": [\r\n        {\r\n          \"type\": \"rtm\"\r\n        }\r\n      ],\r\n      \"type\": \"outgoing\",\r\n      \"status\": \"pending\",\r\n      \"lmodifiedOn\": \"2019-12-03T05:07:45.165Z\",\r\n      \"createdBy\": \"u-211f287f-17c8-51ac-b768-15c68e19afb2\",\r\n      \"components\": [\r\n        {\r\n          \"_id\": \"cp-209a0641-130b-57ce-b0d3-d651691084bb\",\r\n          \"cT\": \"text\",\r\n          \"data\": {\r\n            \"text\": \"Please enter the text to comment on the issue\"\r\n          },\r\n          \"thumbnails\": [\r\n           \r\n          ]\r\n        }\r\n      ],\r\n      \"botId\": \"st-2f579dbf-9dc1-548c-972f-f19d33160a07\",\r\n      \"orgId\": \"o-44741779-1971-5ab9-a0f7-aaf4e21dbe4e\",\r\n      \"accountId\": \"5a675150ff600b3d7665d2a6\",\r\n      \"tN\": \"Add Comment to Issue\",\r\n      \"isBB\": 0,\r\n      \"ms\": 1,\r\n      \"chnl\": \"rtm\",\r\n      \"lang\": \"en\",\r\n      \"createdOn\": \"2019-12-03T05:07:45.171Z\",\r\n      \"timestampValue\": 1575349665171,\r\n      \"__v\": 0,\r\n      \"sessionId\": \"5de5eda04cdcff145752dbf6\",\r\n      \"resourceid\": \"messagestore\",\r\n      \"tags\": {\r\n        \"messageTags\": [\r\n         \r\n        ],\r\n        \"userTags\": [\r\n         \r\n        ],\r\n        \"sessionTags\": [\r\n         \r\n        ]\r\n      }\r\n    }\r\n  ]\r\n}<\/pre>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"WebSocket_Error_Scenarios\">WebSocket Error Scenarios<\/span><\/h2>\n<p>This section describes the various error code responses sent to the Kore.ai XO Platform from the client app over a WebSocket.<\/p>\n<table>\n<tbody>\n<tr>\n<th width=\"30%\">Error Code<\/th>\n<th>Reason<\/th>\n<\/tr>\n<tr>\n<td>1002<\/td>\n<td>When protocol error occurs.<\/td>\n<\/tr>\n<tr>\n<td>1005<\/td>\n<td>When a user closes the chat window or reconnects with the bot.<\/td>\n<\/tr>\n<tr>\n<td>1006<\/td>\n<td>When the server restarts.<\/td>\n<\/tr>\n<tr>\n<td>1007<\/td>\n<td>When VA finds non utf-8 kind of messages instead of text messages.<\/td>\n<\/tr>\n<tr>\n<td>1008<\/td>\n<td>When any of the following scenarios occurs:<\/p>\n<ul>\n<li>Exceeds user rate limit<\/li>\n<li>Bot suspended<\/li>\n<li>User blocked<\/li>\n<li>Channel user ID is blocked<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>1011<\/td>\n<td>When any unhandled exceptions come up when the WebSocket connection is up and running.<\/td>\n<\/tr>\n<tr>\n<td>1009<\/td>\n<td>When the payload size is larger than the maximum limit.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"Next_Steps\"><em>Next Steps<\/em><\/span><\/h2>\n<p>The XO Platform API endpoints and RTM events can be used with your client app or Kore.ai Bot SDKs. For more information, see the\u00a0<a href=\"\/docs\/bots\/kore-web-sdk\/\">Kore.ai Bots SDK<\/a>.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/section>\n","protected":false},"excerpt":{"rendered":"Kore.ai SDK libraries use the WebSocket channel to communicate with the Kore.ai XO Platform. When using the Kore.ai XO Platform SDKs, only the JWT token must be generated and passed to the client SDK. Initializing This section describes how the Kore.ai SDKs initialize a WebSocket session and is for reference only. Prerequisites Make sure to...","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-17801","post","type-post","status-publish","format-standard","hentry","category-sdks"],"_links":{"self":[{"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/posts\/17801","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/comments?post=17801"}],"version-history":[{"count":18,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/posts\/17801\/revisions"}],"predecessor-version":[{"id":59205,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/posts\/17801\/revisions\/59205"}],"wp:attachment":[{"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/media?parent=17801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/categories?post=17801"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/tags?post=17801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}