$jsapi.chatHistoryJson
The $jsapi.chatHistoryJson()
method returns the detailed dialog history of the current session in the JSON format.
In this format, you can send the history to external systems.
A history is a list of various messages:
Message fields:
Field | Description |
---|---|
questionID | Message identifier. If the bot responds to a user request or event, the |
text | Message text. The field is not present if the message has no text. |
author | Author:
|
status | Status:
|
eventData | Data passed with the event. |
sendDateInUTC | Sent time in Unix format in the UTC timezone. |
How to use
The method is called without arguments.
- ECMAScript 5
- ECMAScript 6
state: historyJson
q: dialog history in JSON format
a: {{ $jsapi.chatHistoryJson() }}
In the ECMAScript 6 runtime, the method is asynchronous:
state: historyJson
q: dialog history in JSON format
scriptEs6:
$reactions.answer(await $jsapi.chatHistoryJson());
History example:
[
{
"questionId": "example1-0000-0000-0000-000000000000",
"text": "How do I buy a ticket?",
"author": "CLIENT",
"status": "SENT",
"eventData": {},
"sendDateInUTC": 1713883656
},
{
"questionId": "example1-0000-0000-0000-000000000000",
"text": "You can buy a ticket online: https://example.com/buy",
"author": "BOT",
"status": "SENT",
"eventData": {},
"sendDateInUTC": 1713883656
},
{
"questionId": "example2-0000-0000-0000-000000000000",
"author": "CLIENT",
"status": "SENT",
"eventData": {
"example": "data"
},
"sendDateInUTC": 1713883656
}
]
In phone channel
In this example:
-
The bot sends the history via an HTTP request in a state with the
hangup
event. This event is triggered if the user ended the call. -
If the history was sent successfully, the bot adds a comment to analytics.
state: ClientHangUp
// The event is triggered if the user ends the call
event!: hangup
script:
// The bot sends the history
$temp.response = $http.query("https://httpbin.org/post", {
method: "POST",
body: $jsapi.chatHistoryJson(),
dataType: "json"
});
// The bot adds a comment to analytics
if ($temp.response.isOk) {
$analytics.setComment("History sent");
};