Skip to content

Add Data to Data Tables

In this post, we explore how to add account-related data for a customer with the help of a Banking Bot. We see how the required information gathered from the user can be stored in a data table.

For details on what Data Tables are and how it is implemented in the XO platform, click here.

Problem Statement

Consider a Banking Bot, for a given customer, the following data needs to be stored:

  • Id
  • Name
  • Email id
  • Address
  • Type

banking bot configure columns

Prerequisites

  • Bot building knowledge;
  • A Banking Bot.

Configurations

Let us consider each of the following scenarios one by one:

  1. Define Data Table with the above requirements;
  2. Dialog Task to:
    • Gather required information; and
    • Invoke a service to update the customer information.

Data Table Configuration

Create a Data Table to hold the following information:

  • CustId – A unique identifier for a customer;
  • CustName – Name of the customer;
  • CustEmail – Email id of the customer;
  • CustType – Type of customer – Regular, Preferred, etc.
  • Address – Customer Address;

Table Creation

  1. Log in to the Kore.ai Bot Builder platform.
  2. Select the Data tab. select data tab

  3. Click the New Table button.

  4. In the New Table page enter the following:

    • Name, say customertable;
    • Description, say Table containing customer details;
  5. Under the Column section add the following details:

COLUMN NAME TYPE REQUIRED ADDITIONAL SETTINGS
CustId number Yes Encrypted & Max Length of 5
CustName string Yes
Address string No
CustType string No Default Value as Preferred
CustEmail string No

add column details

  1. Under the Indexes section add an index for CustId to be unique.
  2. indexes section
  3. Click Create and your table is ready.
  4. Under the Bot Assignments add the bot which would be using this table, say Banking Bot, and give Read, Write and Delete permissions. Delete permission is optional since we would not be deleting data.
  5. bot assignments

Dialog Task Configuration

We will be creating a dialog task to gather the required information, and use a Service node to update the data table with the values thus gathered.

dialog task configuration

Create Dialog Task

  1. From the left navigation menu, select Bot Tasks -> Dialog Tasks.
  2. Click the + icon against the Dialog Tasks to create a new Task, and follow the steps below:
    • Enter IntentName, say, AddCustomer
    • Create & Proceed to open the dialog builder page.
  3. Retain the Intent Node default settings, and close the Intent Node.
  4. Click the + icon next to the intent node and add four Entities as follows:
ENTITY NAME TYPE USER PROMPTS
CustName String Enter your name
CustEmail Email Enter your email id
CustAddress City Enter your address city
CustType List of items (enumerated) Select your income range
  1. CustType can be Basic, Preferred, or Premium based on the income level of the customer. For this purpose, we have used a static list to populate the CustType value as follows:
  2. basic cust type
  3. For generating the CustID, we need to get the last customer id in the table and add one to it. For this, we will first fetch data from the table and then use a Script node to process the id.

Fetch Data

You can use a Service call to fetch data from the table:

  1. Click the + icon of the last entity node.
  2. Select Service -> New Service Node option.
  3. From the General Settings section configure the following:
    • Name say GetLastCustId
    • Display Name say Get Customer Data
    • Service Type select Data Service
    • Type select Table.
  4. Under Request Definition click Add Request to define a request to fetch data from the table.
  5. In the Data Service Request Definition page, enter the following:

    • Choose Table Name as customertable
    • Actions as Get Data. configure data service request
  6. Test and Save the definition and close the service node.

  7. Add a Script node to process the values fetched from the data service to obtain the value for the next customer id using the following script:
var resultSet = context.GetLastCustId.response.body.queryResult;
var id = 0;
if (!resultSet.length) {
    id=1;
} else {
    for (var i=0; i<resultSet.length; i++) {
        if (id < resultSet[i].CustId) {
            id = resultSet[i].CustId;
         }
        }
    id++;    
    }
context.lastID = id;
  1. Now we have all the required data to add to the table.

Add Data

We will be using a Service call to add data to the table:

  1. Click the + icon against the last Entity node added above.
  2. Select Service -> New Service Node option.
  3. From the General Settings section configure the following:
    • Name say AddCustData.
    • Display Name say Add Customer Data.
    • Service Type select Data Service.
    • Type select Table.
  4. Under Request Definition click Add Request to define a request to add data to the table.
  5. In the Data Service Request Definition page, enter the following:
    • Choose Table Name as customertable defined earlier.
    • Actions as Add Data.
  6. Assign Values from the entities defined as follows:
COLUMN ENTITY CONTEXT
CustName {{context.entities.CustName}}
CustEmail {{context.entities.CustEmail}}
Address {{context.entities.CustAddress}}
CustType {{context.entities.CustType}}
CustId {{context.lastID}}

data service request

  1. Add a Message node to display the values added using the following response format:
Customer account created for: {{context.GetCustData.response.body.queryResult[0].CustName}}, {{context.GetCustData.response.body.queryResult[0].CustEmail}}, {{context.GetCustData.response.body.queryResult[0].CustAddress}}, {{context.GetCustData.response.body.queryResult[0].CustType}}
  1. Using Talk to bot option, enter the values when prompted and see the message being displayed.