GETTING STARTED
Kore.ai XO Platform
Virtual Assistants Overview
Natural Language Processing (NLP)
Concepts and Terminology
Quick Start Guide
Accessing the Platform
Working with the Builder
Building a Virtual Assistant
Using Workspaces
Release Notes
Current Version
Previous Versions
Deprecations

CONCEPTS
Design
Storyboard
Dialog Tasks
Overview
Dialog Builder
Node Types
Intent Node
Dialog Node
Entity Node
Form Node
Confirmation Node
Message Nodes
Logic Node
Bot Action Node
Service Node
Webhook Node
Script Node
Group Node
Agent Transfer
User Prompts
Voice Call Properties
Dialog Task Management
Connections & Transitions
Component Transition
Context Object
Event Handlers
Knowledge Graph
Introduction
Knowledge Extraction
Build Knowledge Graph
Add Knowledge Graph to Bot
Create the Graph
Build Knowledge Graph
Add FAQs
Run a Task
Build FAQs from an Existing Source
Traits, Synonyms, and Stop Words
Manage Variable Namespaces
Update
Move Question and Answers Between Nodes
Edit and Delete Terms
Edit Questions and Responses
Knowledge Graph Training
Knowledge Graph Analysis
Knowledge Graph Import and Export
Importing Knowledge Graph
Exporting Knowledge Graph
Creating a Knowledge Graph
From a CSV File
From a JSON file
Auto-Generate Knowledge Graph
Alert Tasks
Small Talk
Digital Skills
Digital Forms
Views
Introduction
Panels
Widgets
Feedback Survey
Train
Introduction
ML Engine
Introduction
Model Validation
FM Engine
KG Engine
Traits Engine
Ranking and Resolver
NLP Configurations
NLP Guidelines
Intelligence
Introduction
Contextual Memory
Contextual Intents
Interruption Management
Multi-intent Detection
Amending Entities
Default Conversations
Sentinment Management
Tone Analysis
Test & Debug
Talk to Bot
Utterence Testing
Batch Testing
Conversation Testing
Deploy
Channels
Publish
Analyze
Introduction
Conversations Dashboard
Performance Dashboard
Custom Dashboards
Introduction
Meta Tags
Dashboards and Widgets
Conversations History
Conversation Flows
Feedback Analytics
NLP Metrics
Containment Metrics
Usage Metrics
Smart Bots
Universal Bots
Introduction
Universal Bot Definition
Universal Bot Creation
Training a Universal Bot
Universal Bot Customizations
Enabling Languages
Store
Manage Assistant
Plan & Usage
Overview
Usage Plans
Support Plans
Invoices
Authorization
Multilingual Virtual Assistants
Masking PII Details
Variables
IVR Settings
General Settings
Assistant Management
Data Table
Table Views
App Definitions
Sharing Data Tables or Views

HOW TOs
Build a Flight Status Assistant
Design Conversation Skills
Create a Sample Banking Assistant
Create a Transfer Funds Task
Create a Update Balance Task
Create a Knowledge Graph
Set Up a Smart Alert
Design Digital Skills
Configure Digital Forms
Configure Digital Views
Add Data to Data Tables
Update Data in Data Tables
Add Data from Digital Forms
Train the Assistant
Use Traits
Use Patterns for Intents & Entities
Manage Context Switching
Deploy the Assistant
Configure an Agent Transfer
Use Assistant Functions
Use Content Variables
Use Global Variables
Web SDK Tutorial
Widget SDK Tutorial
Analyze the Assistant
Create a Custom Dashboard
Use Custom Meta Tags in Filters

APIs & SDKs
API Reference
API Introduction
API List
API Collection
koreUtil Libraries
SDK Reference
SDK Introduction
SDK Security
SDK Registration
Web Socket Connect and RTM
Using the BotKit SDK
BotKit SDK Tutorial - Blue Prism

ADMINISTRATION
Introduction
Assistant Admin Console
Administration Dashboard
User Management
Add Users
Manage Groups
Manage Roles
Assistant Management
Enrollment
Invite Users
Send Bulk Invites
Import User Data
Synchronize Users from AD
Security & Compliance
Using Single-Sign On
Security Settings
Cloud Connector
Analytics
Billing
  1. Home
  2. Docs
  3. Virtual Assistants
  4. Builder
  5. Dialog Task
  6. Using Session and Context Variables in Tasks6 min read

Using Session and Context Variables in Tasks6 min read

When you define tasks, you can access session variables provided by the Bots Platform, or custom variables that you define, as well as the context that defines the scope of the variable.

For example, some API requests may require you to set session variables before the request is executed, or a dialog task component may need to access a session variable to transition to the next node. In addition, a dialog task can access the context object with additional system variables. For more information, see the Context Object.

You can use session variables where you define JavaScript for tasks and the User Prompt editor on the JavaScript tab.

Session Variables

This section describes the context variables and the scope of the context variables that you can use in your custom JavaScript code for your tasks.

The JavaScript syntax to GET or PUT a key/value pair for each context type is:

   "EnterpriseContext" : {
       "get" : function(key){...},//get the specified key
       "put" : function(key, value, ttl){...} //put the value at the key for the specified ttl, ttl is in minutes
   },
   "BotContext" : {
       "get" : function(key){...},//get the specified key
       "put" : function(key, value, ttl){...} //put the value at the key for the specified ttl, ttl is in minutes
   },
   "UserContext" : {
       "get" : function(key){...},//get the specified key
   },
   "UserSession" : {
       "get" : function(key){...},//get the specified key
       "put" : function(key, value, ttl){...} //put the value at the key for the specified ttl, ttl is in minutes
   },
   "BotUserSession" : {
       "get" : function(key){...},//get the specified key
       "put" : function(key, value, ttl){...} //put the value at the key for the specified ttl, ttl is in minutes
   }

For example:

    BotContext.put("topicSessionVariable","music",2000);
    UserSession.put("firstName","Mary",20000);
    UserContext.get("firstName");

Session Variable Types

The following types of session variables are available on the Bots Platform:

  • EnterpriseContext – A key/value pair available to all bots and all users in an enterprise. For example, with the GitHub bot, a user will need to access one or more enterprise repositories. You can persist the repository data as Gitrepository (Enterprise Context) with the following JavaScript code:
    var userRepository = {
    "title": _labels_[repository],
    "value": repository
    };
    EnterpriseContext.put('Gitrepository', userRepository, 200000);
  • BotContext – A key/value pair available to all users of this specific bot. For example, you may want to set up a default currency for financial transactions for a session based on the location of a user. You can persist the default currency data as currency (Bot Context) with the following JavaScript code:
    var defaultCurrency = { TODO Custom JavaScript for location-based currency }
    BotContext.put('currency', defaultCurrency, 200000);
  • UserContext – A key/value pair available to all bots for a user. These keys are read-only and provided by the system as user data for:
      • UserContext.get(“_id”) – The Kore.ai user ID.
      • UserContext.get(“emailId”) – The email address associated with the user ID.
      • UserContext.get(“lastName”) – The last name of the user.
      • UserContext.get(“firstName”) – The first name of the user.
      • UserContext.get(“profImage”) – The image or avatar filename of the user.
      • UserContext.get(“profColor”) – The account color for the user.
      • UserContext.get(“activationStatus”) – The account status of the user. Can be:
        • 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 login attempts.
      • UserContext.get(“jTitle”) – The title of the user, if defined.
      • UserContext.get(“orgId”) – The organizational ID of the user account, if defined.
      • UserContext.get(“customData”) – Use this to pass user information to web channels, currently only for webSDK, see here for more.
      • UserContext.get(“identities”) – Alternate user IDs, if defined.
        • val – The alternate ID
        • type – The type of alternate ID.

    For example, you can PUT a value into the session using the UserSession variable where the key is defined as fullName based on the GET from the two UserContext variables.

    var name = UserContext.get("firstName")+UserContext.get("lastName");
    UserSession.put("fullName") = name;
  • UserSession – A key/value pair that you can define for this specific user for all bots in an enterprise. For example, you may want to store a user location to make it available to all Bots, such as a user home address for commerce, transportation, and home delivery services. For example, you can persist default location data as HomeLocation (UserSession) with the following JavaScript code:
    var location = {
     "title": labels[location],
     "value": {
     "latitude": location.latitude,
     "longitude": request.location.longitude
     }
    };
    UserSession.put('HomeLocation', location, '20000');
  • BotUserSession – A key/value pair that you can define to a specific bot based on the inputs by a specific user. For example, you may want to persist a user location for more than one task of a Bot. For a travel bot, the user may be able to book a flight and a hotel based on the same home and destination addresses. For example, you can persist the default home and destination data as HomeLocation (BotUserSession) and DestinationLocation (BotUserSession) with the following JavaScript code:
    var homelocation = {
     "title": labels[request.sourceLocation],
     "value": {
     "latitude": request.sourceLocation.latitude,
     "longitude": request.sourceLocation.longitude
     }
    };
    BotUserSession.put('HomeLocation', homelocation, '20000');
    var destlocation = {
     "title": labels[request.destLocation],
     "value": {
     "latitude": request.destLocation.latitude,
     "longitude": request.destLocation.longitude
     }
    };
    BotUserSession.put('DestinationLocation', destlocation, '20000’);

Standard Keys

In addition to session and context keys, there are Kore.ai variable placeholders for reusable data. Select one of:

  • _labels_ – Used to return the friendly label in place of a GUID. For example, when user data is requested from a web service API, the ID of a project or workspace returned is a GUID. You can use the _labels_ key to show the user-friendly name of the GUID to the end-user instead of the GUID. In Kore.ai, a drop-down control stores the response for the _labels_ key as, for example:
    {
        "_labels_": {
            "15379386734832": "roadlabs.com",
            "26377329985341": "Test Project",
            "workspace": "roadlabs.com",
            "project": "Test Project"
        },
        "_fields_": {
            "workspace": "15379386734832",
            "project": "26377329985341"
        }
    }

    To use the _labels_ key in a response:

    print('<a href="https://app.asana.com/0/' + workspace.id + '/' + id + '/f" target="_blank">' + title + '</a> in workspace '+_labels_[workspace.id]);
  • _tenant_ – Used to return the tenant for the enterprise when defined. For example, JIRA requires a tenant for URLs, such as koreteam, in https://koreteam.atlassian.net/browse/BBF-3265. You can use the _tenant_ key to build a link in a task response such as:
    var title = request.fields.issuetype.name + ' <a href ="https://' + _tenant_ + '/browse/' + response.key + '" target = "_blank">' + request.fields.summary + '</a>  has been created.';
  • _fields_ – Used to return an action task field input provided by the end-user that is not part of a payload response. For example, in a JIRA action task, the end-user is prompted to enter a workspace name. You can use the _fields_ key to store the end-user input as:
    _fields_["workspace"]
  • _last_run – Used to return the UTC date timestamp of a web service poll using ISO 8601 format, for example, 2016-03-05T12:44:38+00:00. For example, if a web service request returns all activity in a payload response, you can use the _last_run key to filter results displayed before or after the value for _last_run.
Menu