{"id":21333,"date":"2019-06-04T05:46:49","date_gmt":"2019-06-04T04:46:49","guid":{"rendered":"https:\/\/developer.kore.ai\/v8-1\/?p=21333"},"modified":"2021-02-05T11:01:51","modified_gmt":"2021-02-05T11:01:51","slug":"conversation-history-api","status":"publish","type":"post","link":"https:\/\/developer.kore.ai\/v8-1\/docs\/bots\/api-guide\/conversation-history-api\/","title":{"rendered":"Conversation History API"},"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>Fetches the conversational messages between the bot and user in reverse chronological order. This API supports pagination. You can provide offset\/skip and limit to get a certain number of messages at a time.<\/p>\n<p>This is a newer version of the <a href=\"\/v8-1\/docs\/bots\/api-guide\/conversation-history-api-old\/\">old API<\/a> which will soon be deprecated. This revised API addresses the limitation of the older version on enabling BotKit or Agent Transfer.<\/p>\n<p class=\"note\">To use this API, app needs the Bot Builder API scope of <em>Chat History<\/em>.<br \/>\nOR the Admin API Scope of <em>Chat History<\/em> under <em>Bot Analytics<\/em>.<\/p>\n<p><b>GET<\/b><code>https:\/\/{{host}}\/api\/public\/bot\/{{BotID}}\/getMessages?userId={{userID}}&amp;skip=10&amp;limit=10<\/code><\/p>\n<p>A POST API call can also be used to include Session-Id and MetaTags in the retrieved Conversation History.<\/p>\n<p><strong>POST<\/strong> <code>https:\/\/{{host}}\/api\/public\/bot\/{{BotID}}\/getMessages<\/code><br \/>\nand <code>https:\/\/{{host}}\/api\/public\/getMessages<\/code> for Bot Admin Console<\/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=\"Parameters\">Parameters<\/span><\/h3>\n<table>\n<thead>\n<tr>\n<th>Parameter<\/th>\n<th>Description<\/th>\n<\/tr>\n<tr>\n<td>BotID (optional)<\/td>\n<td>Bot ID. You can access it from the bot\u2019s General Settings page.<\/td>\n<\/tr>\n<tr>\n<td>userId (mandatory for GET call<br \/>\noptional for POST call)<\/td>\n<td>The ID of the user whose conversation history to access. Can be user email id or enterprise assigned unique id.<\/td>\n<\/tr>\n<tr>\n<td>skip\/offset (optional)<\/td>\n<td>The number of messages to be skipped.<\/td>\n<\/tr>\n<tr>\n<td>limit (optional)<\/td>\n<td>The number of messages to be shown on each page.<\/td>\n<\/tr>\n<tr>\n<td>forward (optional)<\/td>\n<td>Takes boolean values true\/false. <span style=\"font-family: inherit;font-size: inherit\">Specifies the direction of the messages to be retrieved.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">If the value is true, then the conversation history is retrieved in the order old to the most recent one.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">If the value is false, then the conversation history is retrieved in the reverse order i.e, the most recent to the oldest message<\/span><\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>dateFrom (optional)<\/td>\n<td>Takes the date format yyyy-mm-dd<br \/>\n(or) yyyy-mm-ddThh:mm:ss.msZ<br \/>\neg:2019-04-01 (or) 2019-04-01T13:25:58.515ZIf not provided, calculated as 7 days behind <em>dateTo<\/em>.<br \/>\n<u>Note<\/u>: This field cannot be used in combination with msgId.<\/td>\n<\/tr>\n<tr>\n<td>dateTo (optional)<\/td>\n<td>Takes the date format yyyy-mm-dd<br \/>\n(or) yyyy-mm-ddThh:mm:ss.msZ<br \/>\neg:2019-04-01 (or) 2019-04-01 T13:26:05.598ZIf not provided, calculated as 7 days from <em>dateFrom<\/em>. If <em>dateFrom<\/em> is also not provided then set to <strong>Today<\/strong>.<br \/>\n<u>Note<\/u>: This field cannot be used in combination with msgId<\/td>\n<\/tr>\n<tr>\n<td>channelType (optional)<\/td>\n<td>Name of the channel of whose conversation history is needed, default is <span style=\"font-weight: 400\">\u2018rtm\u2019 <\/span>.<\/p>\n<p>Accepted channel types are:<\/p>\n<ul>\n<li> &#8220;skypeforbusiness&#8221;,<\/li>\n<li> &#8220;msteams&#8221;, <\/li>\n<li>&#8220;twitter&#8221;, <\/li>\n<li>&#8220;spark&#8221;, <\/li>\n<li>&#8220;rtm&#8221;, <\/li>\n<li>&#8220;facebook&#8221;, <\/li>\n<li>&#8220;slack&#8221;, <\/li>\n<li>&#8220;skype&#8221;, <\/li>\n<li>&#8220;kore&#8221;, <\/li>\n<li>&#8220;email&#8221;, <\/li>\n<li>&#8220;sms&#8221;, <\/li>\n<li>&#8220;wfacebook&#8221;, <\/li>\n<li>&#8220;ringcentral&#8221;, <\/li>\n<li>&#8220;jabber&#8221;, <\/li>\n<li>&#8220;yammer&#8221;, <\/li>\n<li>&#8220;alexa&#8221;, <\/li>\n<li>&#8220;twiliovoice&#8221;, <\/li>\n<li>&#8220;telegram&#8221;, <\/li>\n<li>&#8220;ivr&#8221;, <\/li>\n<li>&#8220;ivrVoice&#8221;, <\/li>\n<li>&#8220;line&#8221;, <\/li>\n<li>&#8220;liveperson&#8221;, <\/li>\n<li>&#8220;googleactions&#8221;, <\/li>\n<li>&#8220;hangoutchat&#8221;, <\/li>\n<li>&#8220;mattermost&#8221;, <\/li>\n<li>&#8220;rcs&#8221;.<\/li>\n<\/ul>\n<p><u>Note<\/u>: In case of multi-webhook channel configuration, &#8220;ivr&#8221; will give the conversations for the first WebHook instance. For those related to other instance, specify the <code>ivrInstID<\/code>, you can get it from the WebHook URL which is of the form: <code>{{host_url}}\/chatbot\/hooks\/{{BotId}}\/hookInstance\/{{ivrInstID}}<\/code>)<\/td>\n<\/tr>\n<tr>\n<td>msgId (optional)<\/td>\n<td>A specific Message-Id if known. This would fetch the records starting from that message either forward or backward depending upon the direction (see below) requested. <\/p>\n<p>In case only the specific conversation is required, set the limit to 1<\/p>\n<p><u>Note<\/u>: This field cannot be used in combination with dateFrom and dateTo.<\/td>\n<\/tr>\n<tr>\n<td>direction (optional when msgId is given)<\/td>\n<td>\n<ul>\n<li>&lt;0 reverse<\/li>\n<li>=0 bidirectional<\/li>\n<li>&gt;0 forward<\/li>\n<\/ul>\n<p>Default direction is forward.<\/td>\n<\/tr>\n<tr>\n<td>sessionId (optional)<\/td>\n<td>A specific Session-Id if known. <a href=\"\/v8-1\/docs\/bots\/api-guide\/sessions-api\/\">Refer here to obtain the session id<\/a><\/td>\n<\/tr>\n<tr>\n<td>tags (optional)<\/td>\n<td>Meta tags to filter the conversations.<\/td>\n<\/tr>\n<\/thead>\n<\/table>\n<p><strong>Note<\/strong>: The duration between <em>dateTo<\/em> and <em>dateFrom<\/em> should be less than 7 days, else an error will be thrown.<\/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=\"Authorization\">Authorization<\/span><\/h3>\n<p>Invoke the API with JWT in the header with the following syntax:<\/p>\n<p><code>auth: {{JWT}}<\/code><\/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=\"Response_content_type\">Response content type<\/span><\/h3>\n<p><code>application\/JSON<\/code><\/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=\"Sample_Request\">Sample Request<\/span><\/h3>\n<pre class=\"\">curl -X GET \\\r\n'https:\/\/bots.kore.ai\/api\/public\/bot\/{{BotId}}\/getMessages?userId=u-XXX-XXX&amp;\r\nchannelType=facebook&amp;dateFrom=2019-04-01&amp;dateTo=2019-04-05' \\ \r\n-H 'auth: {{YOUR_JWT_ACCESS_TOKEN}}'<\/pre>\n<p><strong>Sample Request for POST call<\/strong><\/p>\n<pre>curl -X POST \\\r\n  https:\/\/bots.kore.ai\/api\/public\/getMessages \\\r\n  -H 'auth: {{YOUR_JWT_ACCESS_TOKEN}}' \\\r\n  -d '{\r\n        userId           : u-xxxx-xxxxx-xxxx\r\n\tskip             : 0,                           \r\n\tlimit            : 100,                       \r\n\tdateFrom         : \u201c2019-04-01\u201d  (or)  \u201c2019-04-01T13:25:58.515Z\u201d,\r\n\tdateTo           : \u201c2019-04-01\u201d  (or)  \u201c2019-04-01T13:25:58.515Z\u201d,\r\n\tchannelType      : \u201crcs\u201d,\r\n\tsessionId        : [\u201c5eadxxxxxxxxxxxxx\u201d,\u201d5ebxxxxxxxxxxxxxxx\u201d],\r\n\ttags\t         : {\r\n\t\t          and   : [\r\n\t\t\t            {\r\n\t\t\t              \u201cname\u201d  : \u201dtagname\u201d,\r\n\t\t\t              \u201cvalues\u201d  : [\u201ctagvalue1\u201d,\u201dtagvalue2\u201d],\r\n                                      \u201ctype\u201d    : \u201ctagtype\u201d \/\/ user\/message\/session\t\r\n                                     },\r\n                                   {\r\n                                    \u201cname\u201d  : \u201dtagname\u201d,\r\n    \t\t\t            \u201cvalues\u201d  : [\u201ctagvalue1\u201d,\u201dtagvalue2\u201d],\r\n                                    \u201ctype\u201d    : \u201ctagtype\u201d  \/\/ user\/message\/session\t\r\n                                   }\r\n                                  ]\t\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<h3><span class=\"ez-toc-section\" id=\"Sample_Response\">Sample Response<\/span><\/h3>\n<pre>{\r\n    \"total\": 1,\r\n    \"moreAvailable\": false,\r\n    \"messages\": [\r\n        {\r\n            \"_id\": \"ms-e172XXXXXX9a492cd2\",\r\n            \"type\": \"outgoing\",\r\n            \"status\": \"pending\",\r\n            \"lmodifiedOn\": \"2019-04-01T13:25:58.512Z\",\r\n            \"createdBy\": \"u-dfb0a15XXXXXXXXX6afa4c74d\",\r\n            \"channels\": [\r\n                {\r\n                    \"type\": \"rcs\"\r\n                }\r\n            ],\r\n            \"components\": [\r\n                {\r\n                    \"_id\": \"cp-4fbXXXXXXXXXX6ebdd586531\",\r\n                    \"cT\": \"text\",\r\n                    \"data\": {\r\n                        \"text\": \"Thanks! I now have access to your Kore Assistant account. Don\u2019t worry, I never access your account without you asking me to do something for you.\"\r\n                    },\r\n                    \"thumbnails\": []\r\n                }\r\n            ],\r\n            \"botId\": \"st-fe7XXXXXX6e115e94c\",\r\n            \"orgId\": \"o-5a64XXXXXXXXXa58cd43460c3\",\r\n            \"accountId\": \"5c9c95bXXXXX23c523dbc\",\r\n            \"isBB\": 1,\r\n            \"ms\": 1,\r\n            \"chnl\": \"rcs\",\r\n            \"createdOn\": \"2019-04-01T13:25:58.515Z\",\r\n            \"timestampValue\": 1554125158515,\r\n            \"__v\": 0,\r\n            \"resourceid\": \"messagestore\",\r\n            \"tags\": {\r\n                \"messageTags\": [],\r\n                \"userTags\": [\r\n                    {\r\n                        \"value\": \"+919346804623\",\r\n                        \"name\": \"RCSID\"\r\n                    }\r\n                ],\r\n                \"sessionTags\": []\r\n            }        }\r\n    ]\r\n}<\/pre>\n<p><strong>Sample Response from POST call:<\/strong><\/p>\n<pre>{\r\n  \"total\": 1,\r\n  \"moreAvailable\": false,\r\n  \"messages\"  : [\r\n                {\r\n                  \"_id\": \"ms-xxxxxxxxxxxxxxxxxxxx\",\r\n                  \"type\": \"incoming\",\r\n                  \"status\": \"sent to cs\",\r\n                  \"createdBy\":\"u-xxxxxxxxxxxxxxxxxxx\",\r\n                  \"lmodifiedBy\": u-xxxxxxxxxxxxxxxxxxx\",\r\n                  \"lmodifiedOn\": \"2019-04-10T10:21:45.103Z\",\r\n                  \"channels\": [\r\n                     {\r\n                      \"type\": \"rtm\"\r\n                        }\r\n                     ],\r\n                  \"botId\":\"st-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\r\n                  \"orgId\": \u201co-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\r\n                  \"accountId\": \"5xxxxxxxxxxxxxxxxxxxxxxxx\",\r\n                  \"isBB\": 0,\r\n                  \"ms\": 1,\r\n                  \"channel\": \"rtm\",\r\n                  \"components\": [\r\n                    {\r\n                      \"_id\":\"cp-xxxxxxxxxxx\",\r\n                      \"cT\": \"text\",\r\n                      \"data\": {\r\n                          \"text\": \"23\"\r\n                           },\r\n                      \"thumbnails\": []\r\n                      }\r\n                    ],\r\n                    \"createdOn\": \"2019-04-10T10:21:45.106Z\",\r\n                    \"timestampValue\": 1554891705106,\r\n                    \"__v\": 0,\r\n                    \"sessionId\": \"5cadbefc6a81a71559f6bece\"\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><\/div><\/div><\/div><\/div><\/div><\/section>\n","protected":false},"excerpt":{"rendered":"Fetches the conversational messages between the bot and user in reverse chronological order. This API supports pagination. You can provide offset\/skip and limit to get a certain number of messages at a time. This is a newer version of the old API which will soon be deprecated. This revised API addresses the limitation of the...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-21333","post","type-post","status-publish","format-standard","hentry","category-api-guide"],"_links":{"self":[{"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/posts\/21333","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=21333"}],"version-history":[{"count":24,"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/posts\/21333\/revisions"}],"predecessor-version":[{"id":24608,"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/posts\/21333\/revisions\/24608"}],"wp:attachment":[{"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/media?parent=21333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/categories?post=21333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/tags?post=21333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}