{"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":"2021-03-17T10:36:26","modified_gmt":"2021-03-17T10:36:26","slug":"bots-platform-api-reference","status":"publish","type":"post","link":"https:\/\/developer.kore.ai\/v8-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 web socket channel to communicate with Kore.ai Bots Platform. To initialize a web socket session, the Kore.ai SDKs use the following Bots Platform endpoints. When using the Kore.ai Bots 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 web socket session and is for reference only.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Prerequisites\">Prerequisites<\/span><\/h3>\n<p>The client app is registered and Client ID and Secret Key are\u00a0generated in the Kore.ai Bot Builder tool.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Step1\"><strong>Step1<\/strong><\/span><\/h3>\n<p>The JWT is generated at server side using client app credentials and user information. The JWT is passed\u00a0to the client\u00a0app.<\/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\u00a0Bots Platform using the following Bots Platform endpoint.\u00a0<\/span>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<p><code>POST<br \/>\nhttps:\/\/{{APIHost}}\/api\/1.1\/oAuth\/token\/jwtgrant<\/code><\/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 follow sample JSON response shows the <code>accessToken<\/code> and 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 web socket URL using the following endpoint.\u00a0This 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<p><code>POST<br \/>\nhttps:\/\/{{APIHost}}\/api\/1.1\/rtm\/start<\/code><\/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 web socket 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_Events_Reference\"><span style=\"font-weight: 400\">RTM Events Reference<\/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 Bots 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\u00a0responses sent to the Kore.ai Bots Platform from the client app over a web socket. <strong>Event Type:<\/strong>\u00a0<code>\/bot.message<\/code> <strong>Description:<\/strong> Triggered when a user posts a message. The following payload is used to send a user-typed message to the Bots 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 web socket.<\/span><\/p>\n<p><strong>Event Type:<\/strong>\u00a0<code>ack<\/code><\/p>\n<p><strong>Description:<\/strong> An acknowledgment sent whenever an event is received from the client app. 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 sent whenever a message is processed from the client app. 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. 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=\"Get_Conversation_History\">Get Conversation History<\/span><\/h2>\n<p>The client app requests the Bots 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.<\/p>\n<p>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=\"Next_Steps\"><em>Next Steps<\/em><\/span><\/h2>\n<p>The Bots 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=\"\/v8-1\/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 web socket channel to communicate with Kore.ai Bots Platform. To initialize a web socket session, the Kore.ai SDKs use the following Bots Platform endpoints. When using the Kore.ai Bots Platform SDKs, only the JWT token must be generated and passed to the client SDK. Initializing This section describes how the...","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\/v8-1\/wp-json\/wp\/v2\/posts\/17801","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/comments?post=17801"}],"version-history":[{"count":10,"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/posts\/17801\/revisions"}],"predecessor-version":[{"id":27080,"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/posts\/17801\/revisions\/27080"}],"wp:attachment":[{"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/media?parent=17801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/categories?post=17801"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/tags?post=17801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}