Skip to content

Context Object

The Context object is the container object that persists data for dialog execution and across all intents i.e. dialog tasks, action, alert & info tasks, and FAQs. Kore.ai’s natural language processing (NLP) engine populates the intent identified, entities extracted, and history into this object. Keys from the Context object are used in the dialog task and intent transition conditions. Also, the context object can be accessed with additional system and session variables.

The syntax when using an Context object key in a URL is to enclose the object name in double brackets as shown next, Learn more.

The Context object can also be referenced in a script node as well as for dynamic values in an entity node and passed in the payload response to the Kore.ai SDK. You can update the Context object key values based on business logic to influence the dialog task execution.

Note

The context object has a size limit of 1024 KB. The platform notifies the bot designers when the size of the context object exceeds the limit.

We recommend you review these notifications and modify the bot definition to keep the context object size under the limit. In the upcoming releases, the platform will discard conversations if the context size exceeds the limit.

The platform also creates and maintains Session Variables which can be referred to from here.

The following table describes the Context object keys. These can be classified into Global and Dialog contexts based on when they are created and populated. Click here for details.

KEY CATEGORY DESCRIPTION USAGE EXAMPLE
intent Dialog The intent recognized by the NLP interpreter. Syntax: context.intent.<< intent name >>
entities Dialog An array of key/value pairs based on user prompts and recognized user input for those prompts. Syntax: context.entities.<< entity name >>In the following code example, the context.entities object is used to access values for the amount and account names as a confirmation for a funds transfer between accounts

var today = new Date();

if(today.getHours() < 21)

{

print("You have requested to transfer " +context.entities.Passenger +

" from " +context.entities.FromFlightNumber +

" to " +context.entities.ToFlightNumber + ". " +

" It will take 24h for your boarding pass to reflect the change. Shall I go ahead? ");

}

else

{

print("You have requested to transfer" +context.entities.Passenger +

" from " +context.entities.FromFlightNumbere +

" to " +context.entities.ToFlightNumber+ ". Shall I go ahead? " +

context.accdata[0].transfers.length);

}

traits Dialog Traits set for the given context
currentLanguage

(introduced in ver7.1)

Global the current conversation language
suggestedLanguages

(introduced in ver7.1)

Global list of all languages detected by the platform from the user’s first utterance, presented in the order of confidence level. This will be reset at the start of each conversation.
history Global An array that contains the nodeId for each component using the NLP interpreter. An array of objects defining the sequential and historical node path executed in the dialog flow.
  • nodeId – The dialog task flow ID for this node using node type and incremental numbering, for example, intent0, service2, and so forth.
  • state – The status of the object for the timestamp indicated. One of:
    • processing – The Bots Platform begins processing of the node
    • processed – The node and node connections are processed, the following node is found but the dialog has not yet moved to that node.
    • waitingForUserInput – The user was prompted for input but has not been received.
    • pause – The current dialog task is paused while another task is started.
    • resume – The current dialog with the status of pause continues at the same point in the flow after the completion of another task that was started.
    • waitingForServerResponse – The server request is pending an asynchronous response.
    • error – An error occurred, for example, the loop limit is reached, a server or script node execution fails.
    • end – The dialog reached the end of the dialog flow.
  • type – The type of dialog task. One of:
    • intent – The dialog task is a user intent or task.
    • faq – The dialog task is a knowledge graph.
  • componentName – The name of the node.
  • timestamp – The JSON date timestamp of the node execution, for example, 1492794646000.
onHoldTasks Dialog an array of all tasks that are kept on hold while a conversation is in progress. This is a read-only list that you can use for evaluation purposes. (introduced in ver 7.1)
service node name Dialog A collection of objects for Service node executions.
  • response – Returns the request status and response body as a JSON payload.
    • statusCode – The HTTP status code of the request, for example, 200 OK.
    • body – The JSON payload response body from the service request.
resultsFound Dialog True, if results are returned
message_tone Global An array of recognized tone emotions and scores for the current node in a dialog task.
  • tone_name – The name of the tone detected. One of:
    • angry
    • disgust
    • fear
    • sad
    • joy
    • positive – A special tone used to evaluate the general positivity of an utterance.
  • count
  • level – The level of the tone emotion ranging from -3 to +3. One of:
    • +3 – The user definitely expressed the tone emotion.
    • +2 – The user expressed the tone emotion.
    • +1 – The user likely expressed the tone emotion.
    • 0 – The user tone emotion is neutral.
    • -1 – The user likely suppressed the tone emotion.
    • -2 – The user suppressed the tone emotion.
    • -3 – The user definitely suppressed the tone emotion.
dialog_tone Global An array of average recognized tone emotions and scores for the entire dialog task session.
  • tone_name – The name of the tone detected. One of:
    • angry
    • disgust
    • fear
    • sad
    • joy
    • positive – A special tone used to evaluate the general positivity of an utterance.
  • count
  • level – The level of the tone emotion ranging from -3 to +3. One of:
    • +3 – The user definitely expressed the tone emotion.
    • +2 – The user expressed the tone emotion.
    • +1 – The user likely expressed the tone emotion.
    • 0 – The user tone emotion is neutral.
    • -1 – The user likely suppressed the tone emotion.
    • -2 – The user suppressed the tone emotion.
    • -3 – The user definitely suppressed the tone emotion.
<< nodename >>.response.body Dialog The HTTP JSON response from the Service node. Syntax: context.<< node name >>.response.body

In the following code example, the response from a Service node is displayed to the end-user in a Message node.

print(JSON.stringify(context.fetchopportunitiesnode.response.body));

Developer Defined Key Dialog A key/value pair defined by the developer. Syntax: context.<< varName >>

For example, context.customerId

UserQuery Dialog Repharse user query. Syntax: context.UserQuery : { originalUserQuery : < original user input >, rephrasedUserQuery : < rephrase user query > }

For example, context.UserQuery{ "originalUserQuery": "How about Orlando?", "rephrasedUserQuery": "How about the weather in Orlando?" }

Sample Context Object

The following is a payload response that contains a context object:

"context":{
   "bot":"Travel Planning Assistant Documentation",
   "botid":"st-b4a22e86-XXXX-575c-b888-e106d083a251",
   "taskid":"dg-df510618-XXXX-5a0b-8370-ee042b3e5b47",
   "intent":"Agent",
   "intentType":"dialog",
   "entities":{
      "Name":12345,
      "number":1234
   },
   "userInputs":{
      "originalInput":{
         "sentence":" agent",
         "timestamp":1501244143000
      }
   },
   "history":[
      {
         "originalSentence":"agent",
         "timestamp":1501244143000
      },
      {
         "dialogState":"started",
         "timestamp":1501244143000
      },
      {
         "nodeId":"intent0",
         "state":"processed",
         "type":"intent",
         "componentName":"Agent",
         "timestamp":1501244143000
      },
      {
         "nodeId":"entity1",
         "state":"processing",
         "type":"entity",
         "componentName":"Name",
         "timestamp":1501244143000
      },
      {
         "nodeId":"entity1",
         "state":"waitingForUserInput",
         "type":"entity",
         "componentName":"Name",
         "timestamp":1501244143000
      },
      {
         "nodeId":"entity1",
         "state":"processed",
         "type":"entity",
         "componentName":"Name",
         "timestamp":1501244149000
      },
      {
         "nodeId":"entity4",
         "state":"processing",
         "type":"entity",
         "componentName":"number",
         "timestamp":1501244149000
      },
      {
         "nodeId":"entity4",
         "state":"waitingForUserInput",
         "type":"entity",
         "componentName":"number",
         "timestamp":1501244149000
      },
      {
         "nodeId":"entity4",
         "state":"processed",
         "type":"entity",
         "componentName":"number",
         "timestamp":1501244156000
      },
      {
         "nodeId":"agentTransfer3",
         "state":"processing",
         "type":"agentTransfer",
         "componentName":"agenttransfer",
         "timestamp":1501244156000
      },
      {
         "dialogState":"transferredToAgent",
         "timestamp":1501244156000
      }
   ],
   "dialog_tone":[
      {
         "tone_name":"positive",
         "level":1
      }
   ],
   "message_tone":[
      {
         "tone_name":"positive",
         "level":1
      }
   ],
  "currentTags": {
    "tags": [
      "name"
    ]
  },
  "historicTags": [
    {
      "tags": [
        "name"
      ]
    }
  ],
   "session":{
      "EnterpriseContext":{
         "5":"500",
         "TestData-Ent":"1000234",
         "ec1":"Enterprise Context session variable from processor",
         "Enterprise_G_Smith_Email":"george.smith@kore.com",
         "enterprisesessiondialog":"enterprisesessiondialogvalue",
         "enterprisecustomprocessor":"enterprisecustomprocessorvalue",
         "enterprisepreprocessor":"enterprisepreprocessorvalue",
         "EnterpriseContext":"EnterpriseContextvalueresponse",
         "Entersession123":"Entersession123value",
         "EnterpriseContext Summary":"TestingSpread",
         "enterprisecontext":"enterprisecontextvalue",
         "ec2":"Enterprise Context session variable from channel response",
         "EC":"ec session variable from intializer",
         "enterprisepreprocessorkey":"enterprisepreprocessorvalue"
      },
      "BotContext":{
      },
      "UserContext":{
         "profColour":"#3651fc",
         "workinghours":{
            "workdays":"Mon, Tue, Wed, Thu, Fri, Sat, Sun",
            "workstart":"12:00 AM",
            "workend":"12:00 PM"
         },
         "dept":"Product Development",
         "jTitle":"Documentation Manager",
         "profImage":"profile.png",
         "activationStatus":"active",
         "emailId":"help.docs@kore.com",
         "firstName":"Help",
         "lastName":"Docs",
         "orgId":"o-b30656ae-XXXX-XXXX-9181-065f7de34be9",
         "_id":"u-4b9f02a3-XXXX-XXXX-b5cc-6df81c0af603",
         "customData":null,
         "identities":[
            {
               "val":"help.docs@kore.com",
               "type":"email"
            },
            {
               "val":"kore/u-4b9f02a3-XXXX-XXXX-b5cc-6df81c0af603",
               "type":"mapped"
            }
         ]
      },
      "UserSession":{
      },
      "BotUserSession":{
         "isReturningUser": true,
         "lastMessage":{
            "channel":"rtm",
            "messagePayload":{
               "clientMessageId":1501244152843,
               "message":{
                  "body":"1234"
               },
               "resourceid":"/bot.message",
               "botInfo":{
                  "chatBot":"Travel Planning Assistant Documentation",
                  "taskBotId":"st-b4a22e86-XXXX-XXXX-b888-e106d083a251"
               },
               "client":"botbuilder",
               "meta":{
                  "timezone":"America/New_York",
                  "locale":"en-US"
               },
               "id":1501244152843
            }
         },
     "lastUserMessageTime": "2021-07-12T07:07:17.278Z"
      },
      "opts":{
         "userId":"u-4b9f02a3-XXXX-XXXX-b5cc-6df81c0af603",
         "streamId":"st-b4a22e86-XXXX-XXXX-b888-e106d083a251"
      }
   }
},
"channel":{
   "_id":"dc-5b4a742a-XXXX-XXXX-938f-520912935456",
   "channelInfos":{
      "requestId":"ms-26aae382-XXXX-XXXX-8bf1-a9e076770956",
      "message":"The bot is not accessible via Web / Mobile Client.",
      "body":"1234",
      "client":"botbuilder",
      "handle":{
         "spanId":"8cab2ce2f6aabc47",
         "traceId":"8cab2ce2f6aabc47",
         "taskBotId":"st-b4a22e86-XXXX-XXXX-b888-e106d083a251",
         "clientId":"5a37bf24-XXXX-XXXX-a816-f9602db08149",
         "userId":"u-4b9f02a3-XXXX-XXXX-b5cc-6df81c0af603",
         "handleId":"54e95c2b-XXXX-XXXX-ba6b-384d4166f1b2"
      },
      "botInfo":{
         "taskBotId":"st-b4a22e86-XXXX-XXXX-b888-e106d083a251",
         "chatBot":"Travel Planning Assistant Documentation"
      },
      "from":"u-4b9f02a3-3f6f-XXXX-XXXX-6df81c0af603",
      "type":"rtm"
   },
   "__v":0
},
"baseUrl":"https://bots.kore.ai/api/botsdk/stream/st-b4a22e86-XXXX-XXXX-b888-e106d083a251",
"sendUserMessageUrl":"https://bots.kore.ai/api/botsdk/stream/st-b4a22e86-e95b-XXXX-XXXX-e106d083a251/sendUserMessage/1501244156289",
"sendBotMessageUrl":"https://bots.kore.ai/api/botsdk/stream/st-b4a22e86-e95b-XXXX-XXXX-e106d083a251/sendBotMessage/1501244156289"
}
lastUserMessageTime: 2021-07-12T07:07:17.278Z