OVERVIEW
Virtual Assistants
Kore.ai Platform
Key Concepts
Natural Language Processing (NLP)
Accessing Platform
VIRTUAL ASSISTANTS
Virtual Assistant Builder
Virtual Assistant Types
Getting Started
Creating a Simple Bot
SKILLS
Storyboard
Dialog Task
Introduction
Dialog Builder (New)
Dialog Builder (Legacy)
User Intent Node
Dialog Node
Entity Node
Supported Entity Types
Composite Entities
Supported Colors
Supported Company Names
Form Node
Logic Node
Message Nodes
Confirmation Nodes
Bot Action Node
Service Node
Custom Authentication
2-way SSL for Service nodes
Script Node
Agent Transfer Node
WebHook Node
Grouping Nodes
Connections & Transitions
Manage Dialogs
User Prompts
Knowledge Graph
Terminology
Building
Generation
Importing and Exporting
Analysis
Knowledge Extraction
Build
Alert Tasks
Introduction
Ignore Words and Field Memory
How to Schedule a Smart Alert
Small Talk
Digital Views
Overview
Configuring Digital Views
Digital Forms
Overview
How to Configure Digital Forms
NATURAL LANGUAGE
Overview
Machine Learning
Introduction
Model Validation
Fundamental Meaning
Introduction
NLP Guidelines
Knowledge Graph
Traits
Introduction
How to Use Traits
Ranking and Resolver
Advanced NLP Configurations
INTELLIGENCE
Overview
Context Management
Overview
Session and Context Variables
Context Object
How to Manage Context Switching
Manage Interruptions
Dialog Management
Sub-Intents & Follow-up Intents
Amend Entity
Multi-Intent Detection
Sentiment Management
Tone Analysis
Sentiment Management
Event Based Bot Actions
Default Conversations
Default Standard Responses
TEST & DEBUG
Talk to Bot
Utterance Testing
Batch Testing
Record Conversations
CHANNELS
PUBLISH
ANALYZE
Overview
Dashboard
Custom Dashboard
Overview
How to Create Custom Dashboard
Conversation Flows
NLP Metrics
ADVANCED TOPICS
Universal Bots
Overview
Defining
Creating
Training
Customizing
Enabling Languages
Store
Smart Bots
Defining
koreUtil Libraries
SETTINGS
Authorization
Language Management
PII Settings
Variables
Functions
IVR Integration
General Settings
Management
Import & Export
Delete
Versioning
Collaborative Development
Plan Management
API GUIDE
API Overview
API List
API Collection
SDKs
SDK Overview
SDK Security
SDK App Registration
Web SDK Tutorial
Message Formatting and Templates
Mobile SDK Push Notification
Widget SDK Tutorial
Widget SDK – Message Formatting and Templates
Web Socket Connect & RTM
Using the BotKit SDK
Installing
Configuring
Events
Functions
BotKit SDK Tutorial – Agent Transfer
BotKit SDK Tutorial – Flight Search Sample Bot
Using an External NLP Engine
ADMINISTRATION
HOW TOs
Creating a Simple Bot
Creating a Banking Bot
Context Switching
Using Traits
Schedule a Smart Alert
Configure UI Forms
Add Form Data into Data Tables
Configuring Digital Views
Add Data to Data Tables
Update Data in Data Tables
Custom Dashboard
Custom Tags to filter Bot Metrics
Patterns for Intents & Entities
Build Knowledge Graph
Global Variables
Content Variables
Using Bot Functions
Configure Agent Transfer
Update Balance Task
Transfer Funds Task
RELEASE NOTES
  1. Home
  2. Docs
  3. Virtual Assistants
  4. Advanced Topics
  5. koreUtil Libraries

koreUtil Libraries

koreUtil libraries provide pre-written JavaScript functions which makes common or complex tasks easy to implement. These libraries often target specific tasks such as setting up recurring rules for calendar, parsing and manipulation of dates, conversion of dates between timezone, tools to simplify programming with strings, numbers, arrays, functions and objects etc.

How to Use

koreUtil libraries can be used anywhere in the bot where there is a flexibility to write JavaScript code such as script node, message node, confirmation node, entity node, standard responses, answers to FAQs, small talk, event handlers etc.

List of koreUtil libraries

Below is the list of koreUtil libraries provided by the platform:

koreUtil.rrule

koreUtil.rrule is platform offered JS library for creating new recurrence rules, interpreting and reading them in human readable format.

Usage Example:
context.rule = new koreUtil.rrule({
freq: koreUtil.rrule.WEEKLY,
interval: 5,
byweekday: [koreUtil.rrule.MO, koreUtil.rrule.FR],
dtstart: new Date(2012, 1, 1, 10, 30),
until: new Date(2012, 12, 31)
});

context.between=context.rule.between(new Date(2012, 7, 1), new Date(2012, 8, 1));
context.readableFormat=context.rule.toText();

Output:

  • For context.between
    [
    "2012-08-27T10:30:00.000Z",
    "2012-08-31T10:30:00.000Z"
    ]
  • For context.readableFormat
    every 5 weeks on Monday, Friday until January 31, 2013

koreUtil.moment

koreUtil.moment is platform offered JS library for validating, manipulating, and formatting dates.

Usage Example:
context.german=koreUtil.moment().locale('de').format('LLLL');

Output:
For context.german:
Montag, 18. November 2019 01:43

koreUtil.intl

koreUtil.intl is platform offered JS library for language specific string comparison, number formatting, and date and time formatting.

Usage Example:
context.formattedNumberUK = koreUtil.intl.NumberFormat('en-GB').format(123456.789);
var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
context.USdate=koreUtil.intl.DateTimeFormat('en-US').format(date);

Output:

  • For context.formattedNumberUK:
    123,456.789
  • For context.USdate
    12/20/2012

koreUtil.momenttz

koreUtil.momenttz is platform offered JS library for formatting of dates in any timezone and convert dates between timezones.

Usage Example:
var jun = koreUtil.moment("2014-06-01T12:00:00Z");
context.newyork= koreUtil.momenttz(jun,'America/New_York').format('ha z');
context.tokyo = koreUtil.moment().tz('Asia/Tokyo').format('ha z');
context.sydney = koreUtil.moment().tz('Australia/Sydney').format('ha z');

Output:

  • For context.newyork:
    5am PDT
  • For context.tokyo:
    7pm JST
  • For context.sydney:
    9pm AEDT

koreUtil.xml2js

koreUtil.xml2js is platform offered JS library for parsing xml to json and vice versa.

Usage Example:
var obj = {name: "John", Surname: "Doe", age: 23};
var builder = new koreUtil.xml2js.Builder();
context.xml = builder.buildObject(obj);

Output:

  • For context.xml:
    John Doe 23

koreUtil.hash

koreUtil.hash is platform offered JS library that supports SHA on JavaScript.

Usage Example:
context.hashString= koreUtil.hash('sha256').update('42').digest('hex');

Output:

  • For context.hashString:
    73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049

koreUtil._

koreUtil._ is a platform offered JS library which provides utility functions for common programming tasks.

Usage Example:
context.chunkArray = koreUtil._.chunk(['a', 'b', 'c', 'd'], 2);
var users = [
{ 'user': 'barney', 'age': 36, 'active': true },
{ 'user': 'fred', 'age': 40, 'active': false }
];
context.filterActive =koreUtil._.pluck(koreUtil._.filter(users, { 'age': 36, 'active': true }), 'user');

Output:

  • For context.chunkArray:
    [["a","b"],["c","d"]]
  • For context.filterActive:
    [
    "barney"
    ]

koreUtil.getCurrentOptions

koreUtil.getCurrentOptions is a platform offered JS library which provides utility functions to get the current template for language selection standard response options. This can be used to customize the standard response.
Post the release of v8.1, this function has been enhanced to return the authorization URL used in the standard response when end-user authorization is requested.

Following is the return format for each of the situations:

  • For the language selection standard response:
    {"list_of_languages": [
       {"title": "English","value": "English"},
       {"title": "Deutsche","value": "Deutsche"},
       {"title": "Español","value": "Español"}
    ]}
  • For the language ambiguity standard response:
    {"current_language": "Español",
          "list_of_new_languages": [
             {"title": "English","value": "English"},
             {"title": "Deutsche","value": "Deutsche"},
             {"title": "Español","value": "Español"}
      ]}
  • For the language switch standard response:
    {"new_language": "Español","current_language": "English"}
  • For User authorization request standard response:
    {
        "authorizationURL": "https:///r/xxxxxxxxxxxxx"
    }

Following are the usage examples of how the above utility can be used to render the message in a button template, you can use any template as per your requirements.  See here for more on message templates.

Usage Example 1: To get the standard response for “Ask if the user would like to select any of the languages

var info = koreUtil.getCurrentOptions();
var message = {
  "type": "template",
  "payload": {
    "template_type": "button",
    "text": "please select your laguage",
    "subText": "Button Template Description",
    "buttons": []
    }
  };
for (i = 0; i < info.list_of_languages.length; i++) {
  var button = {
    "type": "postback",
    "title": info.list_of_languages[i].title,
    "payload": info.list_of_languages[i].value
    };

  message.payload.buttons.push(button);
 }
print(JSON.stringify(message));

Usage Example 2: To get the standard response for “Ask if the user would like to switch to any of the new languages detected during a conversation

var info = koreUtil.getCurrentOptions();
var message = {
    "type": "template",
    "payload": {
        "template_type": "button",
        "text": "language abiguity response for the current language" + info.current_language,
        "subText": "Button Template Description",
        "buttons": []
    }
};
for (i = 0; i < info.list_of_new_languages.length; i++) {
    var button = {
        "type": "postback",
        "title": info.list_of_new_languages[i].title,
        "payload": info.list_of_new_languages[i].value
    };

    message.payload.buttons.push(button);
}
print(JSON.stringify(message));

Usage Example 3: To get the standard response for “Ask if the user would like to switch to any of the new languages detected during a conversation

var info = koreUtil.getCurrentOptions();
var message = {
    "type": "template",
    "payload": {
        "template_type": "button",
        "text": "would you like to switch to new language detected: current language " + info.current_language + "new language : " + info.new_language,
        "subText": "Button Template Description",
        "buttons": []
    }
};
var options = ["yes", "no"]
for (i = 0; i < options.length; i++) {
    var button = {
        "type": "postback",
        "title": options[i],
        "payload": options[i]
    };
    message.payload.buttons.push(button);
}
print(JSON.stringify(message));

Usage Example 4: To get the standard response for “User needs to authorize or re-authorize

var info = koreUtil.getCurrentOptions();

var message = {
    type: 'template',
    payload: {
        template_type: 'button',
        text: 'Please authorize before we continue...',
        buttons: [
            {
                type: 'url',
                title: 'Click here to authorize',
                url: info.authorizationURL
            }
        ]
    }
};

print(JSON.stringify(message));

koreUtil.getSessionId

koreUtil.getSessionId is a platform offered JS library for obtaining the current conversation session Id.

Usage Example:
var sessionId = koreUtil.getSessionId();

Output:

  • For sessionId:
    5x54321x11xx87654321xx12
Menu