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. The Kore.ai’s natural language processing (NLP) engine populates the intent identified, entities extracted, and history into this object. Keys from the Context
object can be used in the dialog task and intent transition conditions. In addition, the context
object can be accessed with additional system and session variables.
The syntax when using a Context
object key in a URL is to enclose the object name in double brackets as shown next:
https://quora.com/{{context.entities.topic}}/rss
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.
The following table describes the Context
object keys.
Key | Description |
---|---|
intent | The intent recognized by the NLP interpreter. Syntax: context.intent.<< intent name >> |
entities | 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.Amount + " USD from " +context.entities.FromAccountName +" to " +context.entities.ToAccountName + " account. " + " Your funds will be shown immediately though transfer will be shown in tomorrow's date in your transaction history. Shall I go ahead? "); } else { print("You have requested to transfer " +context.entities.Amount + " USD from " +context.entities.FromAccountName +" to " +context.entities.ToAccountName + " account. Shall I go ahead? " +context.accdata[0].transactions.length); } |
traits | Traits set for the given context |
currentLanguage (introduced in ver7.1) |
the current conversation language |
suggestedLanguages (introduced in ver7.1) |
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. |
session.EnterpriseContext | A key/value pair defined by the developer. Any Bots developed by that developer can read and modify this key. The data is common for all Bots and all users in an enterprise. Syntax: GET – context.session.EnterpriseContext.<< varName >> PUT – EnterpriseContext.put( << ‘varName’ >>, << value >>, << persistTimeInMinutes >>) DELETE – EnterpriseContext.delete( << ‘varName’ >>) |
session.BotContext | A key/value pair defined by the developer. The data is common for this Bot only and to all users in an enterprise. Syntax: GET – context.session.BotContext.<< varName >> PUT – BotContext.put( << ‘varName’ >>, << value >>, << persistTimeInMinutes >>) DELETE – BotContext.delete( << ‘varName’ >>) |
session.UserContext | A read-only key/value pair from the Bots Platform that provides all users profile data. This key is not available for Bot definitions but is available as a platform variable. Syntax: GET – context.session.UserContext.<< varName >> |
session.UserSession | A key/value pair defined by the developer. The data is common for all Bots but only for the specified user in an enterprise. Syntax: GET – context.session.UserSession.<< varName >> PUT – UserSession.put( << ‘varName’ >>, << value >>, << persistTimeInMinutes >>) DELETE – UserSession.delete( << ‘varName’ >>) |
session.BotUserSession | A key/value pair defined by the developer. The data is common for all users but only for the specified Bot in an enterprise. Syntax: GET – context.session.BotUserSession.<< varName >> PUT – BotUserSession.put( << ‘varName’ >>, << value >>, << persistTimeInMinutes >>) DELETE – BotUserSession.delete( << ‘varName’ >>) |
history | An array that contains the nodeId for each component using the NLP interpreter. |
<< nodename >>.response.body | 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.
|
Developer Defined Key | A key/value pair defined by the developer. Syntax: context.<< varName >> For example, context.customerId |
Sample Context Object
The following is a payload response that contains a context object.
"context":{ "bot":"Kore Banking 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":{ "lastMessage":{ "channel":"rtm", "messagePayload":{ "clientMessageId":1501244152843, "message":{ "body":"1234" }, "resourceid":"/bot.message", "botInfo":{ "chatBot":"Kore Banking Documentation", "taskBotId":"st-b4a22e86-XXXX-XXXX-b888-e106d083a251" }, "client":"botbuilder", "meta":{ "timezone":"America/New_York", "locale":"en-US" }, "id":1501244152843 } } }, "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":"Kore Banking 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" }
Sample Context Objects
This section contains a series of sample Context
objects.
Sample 1
{ "context": { "bot": "ImageTest", "botid": "st-59423292-a088-56f3-8bae-4aca93e979bf", "taskid": "dg-5e03ef27-2660-560f-a51e-afba56ec8d0f", "intent": "PrintHtml", "intentType": "dialog", "entities": { "url": "www.yahoo.com" }, "history": [ "intent0", "entity2", "service3", "message4" ], "session": { "EnterpriseContext": { "Enterprise_J_Doe_Email": "John.Doe@kore.ai", "EnterpriseContext Summary": "Testing", "enterprisecontext": "enterprisecontextvalue", "enterprisepreprocessor": "enterprisepreprocessorvalue", "EnterpriseContext": "EnterpriseContextvalueresponse", "enterprisecustomprocessor": "enterprisecustomprocessorvalue", "enterprisepreprocessorkey": "enterprisepreprocessorvalue", "Entersession123": "Entersession123value", "enterprisesessiondialog": "enterprisesessiondialogvalue" }, "BotContext": {}, "UserContext": { "_id": "u-c93c649c-078b-52bc-93ee-f825e2ce909b", "emailId": "Jane.Doe.com", "lastName": "Jane", "firstName": "Doe", "profImage": "no-avatar", "profColour": "#5AA921", "activationStatus": "active", "jTitle": "", "orgId": "o-b30656ae-9be9-5fa2-9181-065f7de34be9", "identities": [ { "val": "Jane.Doe.com", "type": "email" } ] }, "UserSession": {}, "BotUserSession": {}, "opts": { "userId": "u-c93c649c-078b-52bc-93ee-f825e2ce909b", "streamId": "st-59423292-a088-56f3-8bae-4aca93e979bf" } }, "accountidtouse": null, "report": { "response": { "body": { "imageURLS": { "vlarge": "https://app.collab.ai/api/getMediaStream/media/f-72247859-68b4-51d0-a9db-c78d2f1cb962.png?e=1485330342&n=7470041802&s=ImpsR2VPODZNUzVFaTVyN3lGd2hXUy9KQ1g4dE5KeXhEOGwybElWTWQ1VTA9Ig$$", "small": "https://app.collab.ai/api/getMediaStream/media/f-d16f9842-5f65-5bd0-8442-25b90f919c6f.png?e=1485330342&n=176619407&s=IitsdS9QM2c3Y212Z1o1V0RTTmkrNkppVnVSbnhHaEpDSnN2ZDNtcW5oVkU9Ig$$", "large": "https://app.collab.ai/api/getMediaStream/media/f-57f47443-f3fc-5258-b8ed-b55bfa50e63d.png?e=1485330343&n=1981298329&s=IkswUmZmQmJ1Lzc0d09FNi9XYld1T1IyZzAwa3p0M2tuS0g3U0pOZTVUUzg9Ig$$" } } } }, "message_tone": [], "dialog_tone": [], "mappedIntents": [] } }
Sample 2
{ "context": { "bot": "ImageTest", "botid": "st-59423292-a088-56f3-8bae-4aca93e979bf", "taskid": "dg-5e03ef27-2660-560f-a51e-afba56ec8d0f", "intent": "PrintHtml", "intentType": "dialog", "entities": { "url": "www.yahoo.com" }, "history": [ "intent0", "entity2", "service3", "message4" ], "session": { "EnterpriseContext": { "Enterprise_G_Ravindra_Email": "ravindra.balleda@kore.ai", "EnterpriseContext Summary": "TestingSpread", "enterprisecontext": "enterprisecontextvalue", "enterprisepreprocessor": "enterprisepreprocessorvalue", "EnterpriseContext": "EnterpriseContextvalueresponse", "enterprisecustomprocessor": "enterprisecustomprocessorvalue", "enterprisepreprocessorkey": "enterprisepreprocessorvalue", "Entersession123": "Entersession123value", "enterprisesessiondialog": "enterprisesessiondialogvalue" }, "BotContext": {}, "UserContext": { "_id": "u-c93c649c-078b-52bc-93ee-f825e2ce909b", "emailId": "umesh.kushwaha@kore.ai", "lastName": "Kushwaha", "firstName": "Umesh", "profImage": "no-avatar", "profColour": "#5AA921", "activationStatus": "active", "jTitle": "", "orgId": "o-b30656ae-9be9-5fa2-9181-065f7de34be9", "identities": [ { "val": "umesh.kushwaha@kore.ai", "type": "email" } ] }, "UserSession": {}, "BotUserSession": {}, "opts": { "userId": "u-c93c649c-078b-52bc-93ee-f825e2ce909b", "streamId": "st-59423292-a088-56f3-8bae-4aca93e979bf" } }, "accountidtouse": null, "reportPage": { "response": { "body": { "imageURLS": { "vlarge": "https://bots.kore.ai/api/getMediaStream/media/f-72247859-68b4-51d0-a9db-c78d2f1cb962.png?e=1485330342&n=7470041802&s=ImpsR2VPODZNUzVFaTVyN3lGd2hXUy9KQ1g4dE5KeXhEOGwybElWTWQ1VTA9Ig$$", "small": "https://bots.kore.ai/api/getMediaStream/media/f-d16f9842-5f65-5bd0-8442-25b90f919c6f.png?e=1485330342&n=176619407&s=IitsdS9QM2c3Y212Z1o1V0RTTmkrNkppVnVSbnhHaEpDSnN2ZDNtcW5oVkU9Ig$$", "large": "https://bots.kore.ai/api/getMediaStream/media/f-57f47443-f3fc-5258-b8ed-b55bfa50e63d.png?e=1485330343&n=1981298329&s=IkswUmZmQmJ1Lzc0d09FNi9XYld1T1IyZzAwa3p0M2tuS0g3U0pOZTVUUzg9Ig$$" } } } }, "message_tone": [], "dialog_tone": [], "mappedIntents": [] } }
The following section describes the Context
object parameters.
bot
– The name of the bot.botid
– The system unique GUID for the bot.taskid
– The system unique GUID for the dialog task.intent
– The name of the root intent of the dialog task.intentType
– The dialog task type.entities
– An array o key/value pairs that represent entity nodes processed and their values, for example, “SourceAirport”:“MCO”.history
– 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:
– The Bots Platform begins processing of the nodeprocessing
– The node and node connections are processed, the following node is found but the dialog has not yet moved to that node.processed
– The user was prompted for input but has not been received.waitingForUserInput
– The current dialog task is paused while another task is started.pause
– The current dialog with the status of pause continues at the same point in the flow after completion of another task that was started.resume
– The server request is pending an asynchronous response.waitingForServerResponse
– An error occurred, for example, the loop limit is reached, a server or script node execution fails.error
– The dialog reached the end of the dialog flow.end
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
– 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 >
– 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
– True, if results are returned.session
EnterpriseContext
– Key/value pairs available to all bots and all users in an enterprise.BotContext
– Key/value pairs available to all users of this specific bot.UserContext
– Key/value pairs available to all bots for a user._id
– The Kore.ai user ID.emailId
– The email address associated with the user ID.lastName
– The last name of the user.firstName
– The first name of the user.profImage
– The image or avatar filename of the user.profColour
– The account color for the user.activationStatus
– The account status of the user. One of:active
– The user is active and can interact with other Kore.ai users.inactive
– The user is not active, but user data is retained in the system.suspended
– The user is suspended by an administrator. The user cannot log on to Kore.ai, however, messages can still be sent to the suspended user.locked
– The user exceeded the maximum number of logon attempts.
jTitle
– The title of the user, if defined.orgId
– The organizational ID of the user account, if defined.customData
– Use this to pass user information to web channels, currently only for webSDK, see here for more.identities
– Alternate user IDs, if defined.val
– The alternate IDtype
– The type of alternate ID.
UserSession
– Key/value pairs that you can define for this specific user for all bots in an enterpriseBotUserSession
– Key/value pairs that you can define to a specific bot based on the inputs by a specific user.opts
userId
– the Kore.ai assigned user-idstreamId
– the bot id
message_tone
– 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
– 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.