Get conversation history
Use getConversationHistory
to retrieve the history of messages in the current conversation:
-
getConversationHistory()
- Use this to retrieve all types of messages in the current conversation. -
getConversationHistory(String filters)
- Use this to filter the types of messages that are returned. More on this below.
One use case for this function is to retrieve the conversation history, so you can send it to an aiStudio flow when invoking the flow. This allows the flow to use the info during processing. (aiStudio is LivePerson’s authoring environment for building, testing and tuning advanced AI Agents.)
You can only fetch the most recent 300 messages in the conversation.
Function Name | Arguments | Returns |
---|---|---|
getConversationHistory() |
None | JSON array as a String |
getConversationHistory(String filters) |
filters (String) - A comma-separated list of strings identifying the fields to include in the response | JSON array as a String |
Arguments
The “filters” argument specifies the types of messages to receive. Possible filters include:
Filter | Description |
---|---|
{"types":["PLAIN_TEXT","RICH_CONTENT"]} |
Get only messages of type 'PLAIN_TEXT' and 'RICH_CONTENT' |
{"originatorRoles":["CONSUMER"]} |
Get only messages from 'CONSUMER' |
{"messageAudiences":["AGENTS_AND_MANAGERS"]} |
Get only private messages that are visible to agents and agent managers |
You must specify the filters in this prescribed format:
"{\"types\":[\"PLAIN_TEXT\",\"RICH_CONTENT\"],\"originatorRoles\":[\"CONSUMER\",\"ASSIGNED_AGENT\"]}"
Response
This method returns a JSON array as a String, for example:
[
{
"id": "b89ad8c5-95b1-4a59-b749-386f8dde40cb_877",
"createdTs": "2025-05-27T04:21:31.491+00:00",
"dialogId": "b89ad8c5-95b1-4a59-b749-386f8dde40cb",
"sequence": "877",
"content": {
"status": "READ",
"sequenceList": [
0,
8,
12
]
},
"type": "ACKNOWLEDGEMENT",
"originator": {
"role": "ASSIGNED_AGENT",
"id": "61723987.4515268532"
},
"messageAudience": "ALL"
},
{
"id": "b89ad8c5-95b1-4a59-b749-386f8dde40cb_874",
"createdTs": "2025-05-27T04:20:59.396+00:00",
"dialogId": "b89ad8c5-95b1-4a59-b749-386f8dde40cb",
"sequence": "874",
"content": {
"text": "Hi there! Thanks for coming!!!!!!!"
},
"type": "PLAIN_TEXT",
"originator": {
"role": "ASSIGNED_AGENT",
"id": "61723987.4515268532"
},
"metadata": [
{
"type": "CbBotResponseMetaData",
"botMsgId": "7947863a-9056-4b19-8913-d18fc1b082ba",
"botInteractionId": "58b6f04c-9eaa-4da7-a402-4429b7c9b497",
"botInteractionName": "",
"botId": "38764c7d-acb4-45b2-8b13-b7e05e46fdc6",
"botType": "CUSTOMER_FACING_BOT",
"botProvider": "LP CB",
"botProviderType": "1P_LP_CONNECTOR",
"intentId": "",
"intentName": "",
"matchType": "Pattern",
"domainName": "",
"domainType": ""
}
],
"messageAudience": "ALL"
}
]
Example
This example shows how to read the JSON returned by getConversationHistory
. As a basic example, the sequence attribute is read. You can read any attribute in the same way.
var responseForRequestWithFilters =
// This method below retrieves only messages from the consumer, not the agent.
botContext.getConversationHistory("{\"types\":[\"originatorRoles\":[\"CONSUMER\"]}");
//You should use JSON.parse to convert the string to a JSON object.
var jsonResponseWithFilters = JSON.parse(responseForRequestWithFilters);
botContext.setBotVariable("responseForRequestWithFilters", responseForRequestWithFilters, true, false);
//Evaluating the length of the JSON array returned by the response
var length = jsonResponseWithFilters.length;
botContext.printDebugMessage("Response for request with filters length: " + length);
botContext.setBotVariable("length", length, true, false);
// Now we can use the dot notation on the jsonResponse object.
var seq = jsonResponseWithFilters[0].sequence;
botContext.printDebugMessage("Response 1st element sequence: " + seq);