Skip to main content

$rag.getChatHistory

The method returns the history of dialog with the bot in the current session.

The history has a special format for the knowledge base. You can pass this history in the history parameter if you send single requests to the knowledge base:

In this case, the knowledge base can take into account the context of single requests.

Syntax

The method is available only in the ECMAScript 6 runtime and is asynchronous. The method is called without arguments:

 await $rag.getChatHistory();

Return value

The method returns an array with the dialog history:

[
{
"role": "assistant",
"content": "How can I help you?"
},
{
"role": "user",
"content": "How do I cancel an order?"
},
{
"role": "assistant",
"content": "To cancel an order, contact our support. More details: https://example.com/docs"
}
]

Here:

  • role is the role of the dialog participant:

    • user is the user.
    • assistant is the bot.
  • content is the text of the message.

How to use

In this state, the bot sends the user query and the dialog history to the knowledge base:

state: Answer
intent!: /question
scriptEs6:
// The bot gets the dialog history
const history = await $rag.getChatHistory();
// The bot sends the query along with the history
$rag.query.generateAnswer("MyKnowledgeHub", $request.query, history)
.then(answer => {
$conversationApi.sendTextToClient(answer.response);
})
.catch(error => {
$conversationApi.sendTextToClient("An error occured: " + error);
});