Skip to main content

$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:

  • user requests;
  • events;
  • bot reactions;
  • agent messages.

Message fields:

FieldDescription
questionID

Message identifier.

If the bot responds to a user request or event, the questionID in the bot response will match the questionID in the request or event.

textMessage text. The field is not present if the message has no text.
authorAuthor:
  • CLIENT for user requests and events.
  • BOT for bot reactions.
  • OPERATOR for agent messages.
statusStatus:
  • SENT
  • DELIVERED
  • NOT_DELIVERED
  • READ
  • NOT_SENT
eventDataData passed with the event.
sendDateInUTCSent time in Unix format in the UTC timezone.

How to use

The method is called without arguments.

state: historyJson
q: dialog history in JSON format
a: {{ $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:

  1. 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.

  2. 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");
};