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. How Tos
  5. Using Assistant Functions4 min read

Using Assistant Functions4 min read

In this How-To, we will explore a scenario in a Banking Bot, where Bot Functions can be used to reuse a piece of functionality. We will see how the expenditure report can be programmed as a function and can be used for both Savings Account and Credit Card.

For details on what Bot Functions are and how they are implemented in the Kore.ai Bots platform, refer here.

Problem Statement

In our Banking Bot, we have a reporting task:

  1. Monthtly Statement which gives the monthly balance amounts for a given Account number.
  2. Credit Card Statement gives an overview of the expenses for a given Credit Card.
  3. Both the reports are presented as pie chart and the input in both the cases is an array with month, amount values.

In this document, we will see how Bot Function can be used to avoid duplication of coding effort and ensure uniform presentation.

Pre-requisites

  • Bot building knowledge
  • A working bot. We will be using the Banking Bot from here.
  • Following is the Script file with two functions using the message templates to display the data (see here for more on message templates):
    • tableTemplate – takes an two-dimensional array and displays the content in a tabular format
    • pieTemplate – takes an two-dimensional array and displays the content in a pie format

    Copy the following content and save it as a .js file (say, functionEX.js)

    function tableTemplate(data){
     var message = {
       "type": "template",
       "payload": {
       "template_type": "mini_table",
       "layout": "vertical",
       "text":"Monthly Balance Statement",
       "elements": []
      }
     };
     for (i=0; i < data.length; i++) {
       var j=0;
       var element = {
         "primary":[[data[i][j]],[data[i][j+1],"right"]],
         "additional":[[data[i][j+2],data[i][j+3]],[data[i][j+4],data[i][j+5]]]
       };
     message.payload.elements.push(element);
     }
     return JSON.stringify(message);
    };
    
    function pieTemplate(data){
      var message = {
       "type": "template",
       "payload": {
       "template_type": "piechart",
       "pie_type": "regular",
       "text": "Monthly Expense Report",
       "elements": []
       }
      };
     for (i=0; i < data.length; i++) {
      var element = {
       "title": data[i][0],
       "value": data[i][1]
       };
      message.payload.elements.push(element);
     }
     return JSON.stringify(message);
    };

Implementation

  1. Open the Banking Bot
  2. Select the Build tab from the top menu
  3. From Configurations select the Bot Functions section.
  4. Click Import (or Import New) to open the Import Custom Script window
  5. Drag and drop or Browse the script file that you saved from the Pre-requisites section and click Import.
  6. Once the success message is displayed click Done.
  7. Your Script file is ready to use.
  8. Open the Dialog Tasks page and create a New Dialog Task called “Monthly Statement”.
    1. Add entities to capture the Account Number and Account Type.
    2. Ideally, there would be a service call to fetch the monthly balance details. Here we will use static values for demonstration purposes.
    3. Add a Script node using the Bot Action and enter the following – we are declaring an array carrying the balances for the months of January, February and March:
      context.monthlyBal = [["Jan",100],["Feb",200],["Mar", 300]];
    4. Add a Message node to send this data to the Bot Function declared earlier and get the report.
      • From Bot Responses section, click Manage Responses
      • Add Bot Response, select Web/Mobile Client as the Channel, switch to JavaScript tab and enter  the following code to display the values in a tabular format:
        var info = context.monthlyBal;
        print(tableTemplate(info));
    5. Add another Message node to send this data to the Bot Function declared earlier and get the report.
      • From Bot Responses section, click Manage Responses
      • Add Bot Response, select Web/Mobile Client as the Channel, switch to JavaScript tab and enter  the following code to display the values in a pie chart:
        var info = context.monthlyBal;
        print(pieTemplate(info));
  9. Close the dialog task and return to the Dialog Tasks page
  10. Create a New Dialog Task called “Credit Card Statement”.
    1. Add entities to capture the Account Number.
    2. Ideally, there would be a service call to fetch the monthly expenditure values. Here we will use static values for demonstration purposes.
    3. Add a Script node within Bot Action node and enter the following – we are declaring an array carrying the expenditure values for all the months:
      context.monthlyExpenses = [["Jan",100],["Feb",200],["Mar", 300],["Apr",100],["May",400],["June", 500],["Jul",100],["Aug",200],["Sept", 300],["Oct",100],["Nov",100],["Dec", 300]];
    4. Add a Message node to send this data to the Bot Function declared earlier and get the report.
      • From Bot Responses section, click Manage Responses
      • Add Bot Response, select Web/Mobile Client as the Channel, switch to JavaScript tab and enter the following code to display the values in a pie chart. As you can see we are using the same function that was invoked in the previous dialog task.
        var info = context.monthlyExpenses;
        print(pieTemplate(info));
  11. Close the Dialog Task
  12. Talk to Bot and try both the dialogs. Thus we have used the same function to display the reports in multiple places.

Menu