はじめに
対話型AIプラットフォーム
チャットボットの概要
自然言語処理(NLP)
ボットの概念と用語
クイックスタートガイド
プラットフォームへのアクセス
ボットビルダーの操作
リリースノート
最新バージョン(英語)
以前のバージョン(英語)
廃止機能(英語)
コンセプト
設計
ストーリーボード
ダイアログタスク
ダイアログタスクとは
ダイアログビルダー
ノードタイプ
インテントノード
ダイアログノード
エンティティノード
フォームノード
確認ノード
ロジックノード
ボットアクションノード
サービスノード
Webhookノード
スクリプトノード
グループノード
エージェント転送ノード
ユーザープロンプト
音声通話プロパティ
イベント ハンドラー
ナレッジグラフ
ナレッジグラフの抽出
ナレッジグラフの構築
ボットにナレッジグラフを追加
グラフの作成
ナレッジグラフの構築
既存のソースからFAQを構築
通知タスク
スモールトーク
デジタルスキル
デジタルフォーム
デジタルビュー
デジタルビューとは
パネル
ウィジェット
トレーニング
トレーニングとは
機械学習
機械学習とは
モデル検証
ファンダメンタルミーニング
ナレッジグラフ
示唆
ランキングおよび解決
NLPの詳細設定
NLPのガイドライン
インテリジェンス
インテリジェンスとは
コンテキスト
コンテキストインテント
割り込み
複数インテントの検出
エンティティの変更
デフォルトの会話
センチメント管理
トーン分析
テストとデバッグ
ボットと会話
発話テスト
バッチテスト
会話テスト
デプロイ
チャネル
公開
分析
ボットの分析
NLPメトリクス
会話フロー
Usage Metrics
封じ込め測定
カスタムダッシュボード
カスタムダッシュボードとは
メタタグ
カスタムダッシュボードとウィジェット
LLM and Generative AI
Introduction
LLM Integration
Kore.ai XO GPT Module
Prompts & Requests Library
Co-Pilot Features
Dynamic Conversations Features
ユニバーサルボット
ユニバーサルボットとは
ユニバーサルボットの定義
ユニバーサルボットの作成
ユニバーサルボットのトレーニング
ユニバーサルボットのカスタマイズ
他言語の有効化
ストア
プラントと使用
Overview
Usage Plans
Support Plans
Invoices
管理
ボット認証
複数言語対応ボット
個人を特定できる情報の編集
ボット変数の使用
IVRのシステム連携
一般設定
ボット管理
ハウツー
会話スキルの設計
バンキングボットを作成
バンキングボット – 資金の振り替え
バンキングボット – 残高を更新
ナレッジグラフを構築
スマートアラートの予約方法
Integrations
Actions
Actions Overview
Asana
Configure
Templates
Azure OpenAI
Configure
Templates
BambooHR
Configure
Templates
Bitly
Configure
Templates
Confluence
Configure
Templates
DHL
Configure
Templates
Freshdesk
Configure
Templates
Freshservice
Configure
Templates
Google Maps
Configure
Templates
Here
Configure
Templates
HubSpot
Configure
Templates
JIRA
Configure
Templates
Microsoft Graph
Configure
Templates
Open AI
Configure
Templates
Salesforce
Configure
Templates
ServiceNow
Configure
Templates
Stripe
Configure
Templates
Shopify
Configure
Templates
Twilio
Configure
Templates
Zendesk
Configure
Templates
Agents
Agent Transfer Overview
Custom (BotKit)
Drift
Genesys
Intercom
NiceInContact
NiceInContact(User Hub)
Salesforce
ServiceNow
Configure Tokyo and Lower versions
Configure Utah and Higher versions
Unblu
External NLU Adapters
Overview
Dialogflow Engine
Test and Debug
デジタルスキルの設計
デジタルフォームの設定方法
デジタルビューの設定方法
データテーブルのデータの追加方法
データテーブルのデータの更新方法
Add Data from Digital Forms
ボットのトレーニング
示唆の使用方法
インテントとエンティティのパターンの使用方法
コンテキスト切り替えの管理方法
ボットのデプロイ
エージェント転送の設定方法
ボット関数の使用方法
コンテンツ変数の使用方法
グローバル変数の使用方法
ボットの分析
カスタムダッシュボードの作成方法
カスタムタグを使ってフィルタリング
Data
Overview
Data Table
Table Views
App Definitions
Data as Service
Build a Travel Planning Assistant
Travel Assistant Overview
Create a Travel Virtual Assistant
Design Conversation Skills
Create an ‘Update Booking’ Task
Create a Change Flight Task
Build a Knowledge Graph
Schedule a Smart Alert
Design Digital Skills
Configure Digital Forms
Configure Digital Views
Train the Assistant
Use Traits
Use Patterns
Manage Context Switching
Deploy the Assistant
Use Bot Functions
Use Content Variables
Use Global Variables
Use Web SDK
Build a Banking Assistant
Migrate External Bots
Google Dialogflow Bot
APIs & SDKs
API Reference
API Introduction
Rate Limits
API List
koreUtil Libraries
SDK Reference
SDK Introduction
Web SDK
How the Web SDK Works
SDK Security
SDK Registration
Web Socket Connect and RTM
Tutorials
Widget SDK Tutorial
Web SDK Tutorial
BotKit SDK
BotKit SDK Deployment Guide
Installing the BotKit SDK
Using the BotKit SDK
SDK Events
SDK Functions
Tutorials
BotKit - Blue Prism
BotKit - Flight Search Sample VA
BotKit - Agent Transfer
  1. ホーム
  2. Docs
  3. Virtual Assistants
  4. SDKs
  5. Events for the BotKit SDK

Events for the BotKit SDK

You can use the Kore.ai BotKit SDK to capture and handle events in the Bots Platform for better control and customization of the user’s experience with the Virtual Assistant that you are building. The following events are supported by the BotKit SDK:

onMessage

This event consists of the following two components:

  • onUserMessage: This event is triggered when a user sends a message to the assistant and it is received by the channel adapter. The user message is wrapped in this event and sent to the SDK.
  • onBotMessage: This event is triggered when any messages need to be sent to the user. These messages are sent to the SDK along with context object.

onUserMessage

Syntax:

on_user_message : function(requestId, data, callback)

Parameters:

  • requestId – A unique ID for each message event.
  • payload – A JSON response payload as follows:
    {
       "message":"message sent by the assistant to the user",
       "taskId":"Dialog task Id",
       "nodeId":"current node id in the dialog flow",
       "channel":"channel name",
       "context":"context object"
    }
  • callback – The function to call at event completion used to send the updated message and context back to the XO Platform.

Example: In the following code example for the onUserMessage event, the user message is evaluated for transfer to a live agent and transferred, otherwise, the message is passed on to the BotKit SDK for processing.

/*
 * OnUserMessage event handler
 */
function onUserMessage(requestId, payload, callback){
    debug("user message", payload);
    var visitorId = _.get(payload, 'channel.from');
	visitorId = payload.context.session.UserContext._id;
	var entry = _map[visitorId];
	if (payload.message === "clearagent") // disconnect from LiveChat on user utterance
	{
		sdk.clearAgentSession(payload);
	}
    if(entry){//check for live agent
        //route to live agent
        var formdata = {};
        formdata.secured_session_id = entry.secured_session_id;
        formdata.licence_id = config.liveagentlicense;
        formdata.message = payload.message;
        return api.sendMsg(visitorId, formdata)
            .catch(function(e){
                console.error(e);
                delete userDataMap[visitorId];
                delete _map[visitorId];
                return sdk.sendBotMessage(payload, callback);
            });
    }
    else {
        return sdk.sendBotMessage(payload, callback);
    }
}

onBotMessage

Syntax:

 on_bot_message : function(requestId, data, callback)

Parameters:

  • requestId – A unique ID for each message event.
  • payload – A JSON response payload as follows:
    {
       "message":"message sent to the user",
       "channel":"channel name",
       "context":"context object"
    }
  • callback – The function to call at event completion used to send the updated message and context back to the user.

Example: The following code snippet onBotMessage event evaluates the user message for content and then for message tone. If the message tone is greater than or equal to 2 for the angry tone, then the communication between the user and the assistant is switched to a live agent.

/*
 * onBotMessage event handler
 */
function onBotMessage(requestId, payload, callback){
    debug("Bot Message Data",payload);
	console.log("in bot message");
    var visitorId = _.get(paylod, 'channel.from');
    var entry = _map[visitorId];
    if(data.message.length === 0 || payload.message === '') {
        return;
    }
    var message_tone = _.get(payload, 'context.message_tone');console.log("message tone -----",message_tone);
    if(message_tone && message_tone.length> 0){
        var angry = _.filter(message_tone, {tone_name: 'angry'});
        if(angry.length){
            angry = angry[0];
            if(angry.level >=2){
              return  connectToAgent(requestId, data);
            }
        }
    }
    if(!entry)
    {
        sdk.sendUserMessage(payload, callback);
    }
}

onWebHook

This event is triggered when the Kore NL Engine processes the Webhook node in the dialog flow. This event is sent to the SDK with componentId and context. The SDK can execute business logic and send the updated context back to the Platform. Syntax:

on_webhook = function(requestId, componentId, payload, callback)

Parameters:

  • requestId – A unique ID for each webhook event.
  • componentId – The unique ID for the SDKWebhook node.
  • payload – A JSON response payload as follows:
    {
       "message":"message sent by the assistant to the XO Platform",
       "taskId":"Dialog task Id",
       "nodeId":"current node id in the dialog flow",
       "channel":"channel name",
       "context":"context object"
    }
  • callback – The function to call at event completion used to send the updated message and context back to the XO Platform.

Examples In the following example for the on_webhook event, two hotel names are returned as results as a response to user input.

    //on_webhook handler
    on_webhook  : function(requestId, payload, componentId, callback) {
        if (componentId === 'sendResponse') {
          var hotels = {
            "hotels":[
                  "Taj Banjara",
                  "Novotel"
            ]
          };
          payload.context.hotelResults = hotels;
          callback(null,data);
        }
    }

In this example for the on_webhook event, for the Flights Info node in a dialog task, either a list of departure or destination airports based on the requested date is returned based on the flow of the dialog, as a list of results displayed to the end user.

    on_webhook : function(requestId, payload, componentId, callback) {
        var context = payload.context;
	    if (componentName === 'FlightsInfo') {
		  var origin = context.entities.Source;
          var destination = context.entities.Dest;
          var departureDate = context.entities.Date;
          findFlights(origin,destination,departureDate)
			.then(function(flightResults) {
                payload.context.flightResults = flightResults;
				callback(null, data);
			});
	    } else if(componentId === 'GetSourceAirports'){
             var searchTerm = context.entities.SourceName;
             findAirports(searchTerm)
            .then(function(airportResults) {
                payload.context.sourceAirports = airportResults;
                callback(null, data);
            });
        } else if(componentId === 'GetDestAirports'){
           var searchTerm = context.entities.DestName;
             findAirports(searchTerm)
            .then(function(airportResults) {
                payload.context.destAirports = airportResults;
                callback(null, data);
            });
        }

onAgentTransfer

This event is triggered when the Kore NL Engine processes an Agent Transfer node in the dialog flow. This event is sent to the SDK with requestId and context. The SDK can execute a business logic to switch the user seamlessly to a Live Agent. Syntax:

function onAgentTransfer(requestId, data, callback){
connectToAgent(requestId, data, callback);
}

Parameters:

  • requestId – A unique ID for each message event.
  • payload – A JSON response payload as follows:
    {
       OnAgentTransferPayload ","
          requestId ":1501244156289,"
          botId ":"st - b4a22e86 - e95b - 575 c - b888 - e106d083a251 ","
          callbackUrl ":"https: //bots.kore.ai/api/botsdk/stream/st-b4a22e86-e95b-575c-b888-e106d083a251/serviceCallback/1501244156289","context": ...
    }
  • callback – The function to call at event completion used to send the updated message and context back to the XO Platform.

Example: The following code snippet onAgentTransfer event connects the user to a Live Agent and passing the user message, bot message, and historical chat messages of the session.

function connectToAgent(requestId, data, cb){
var formdata = {}; console.log("userlog",JSON.stringify(data.context.session.UserContext._id));
formdata.licence_id = config.liveagentlicense;
formdata.welcome_message = "";
var visitorId = _.get(data, 'channel.channelInfos.from');
if(!visitorId){
visitorId = _.get(data, 'channel.from');
}
visitorId = data.context.session.UserContext._id;
userDataMap[visitorId] = data;
data.message="An Agent will be assigned to you shortly!!!";
var d = new Date();
data.context.session.BotUserSession.startTime = new Date().toLocaleString();
console.log("userlog",JSON.stringify(data.context.session));
sdk.sendUserMessage(data, cb);
formdata.welcome_message = "Link for user Chat history with the assistant : "+ config.app.url +"/history/index.html?visitorId=" + visitorId;
return api.initChat(visitorId, formdata)
.then(function(res){
_map[visitorId] = {
secured_session_id: res.secured_session_id,
visitorId: visitorId,
last_message_id: 0
};
});
}


		

OnEvent

This event is triggered when Dialog Task or FAQ ends in the assistant and sends request ID and context to the SDK. Syntax: on_event : function (requestId, data, callback) Parameters:

  • requestId – A unique ID for each message event.
  • data– A JSON response payload as shown in the example below:
  • callback – The function to call after event completion; it is used to send the updated message and context back to the XO Platform.

Example:

on_event : function (requestId, data, callback)
{
return sdk.sendAlertMessage(data, callback);
}

The event adds the following code in the Data object sent to kit:

"event":
{
"event Type": "endDialog"/ “endFAQ”
}


		

OnAlert

This event is triggered when a user receives an alert. Syntax: on_alert : function (requestId, data, callback) Parameters:

  • requestId – A unique ID for each message event.
  • data– A JSON response payload.
  • callback – The function to call at event completion; it is used to send the updated message and context back to the XO Platform.

Example:

on_alert: function(requestId, data, callback)
{
 return sdk.sendAlertMessage(data, callback);
}

The alert response data is found in the data object sent to the kit.

OnVariableUpdate

The “OnVariableUpdate” event allows you to access VA variables in both the standard and the universal VA. By default, it is not subscribed. You can subscribe to this event to retrieve variables from the VA when publishing. In BotKit, you can use the OnVariableUpdate event to manage VA variables. Learn more.

Event Trigger Scenarios and Behaviors for Universal VA

Universal VA Child VA Behavior
Subscribed Subscribed The platform triggers the “OnVariableUpdate” event in the Universal VA on publish.
If the propagate flag is on for any VA variables, the platform includes the linked VA info for that variable in the “OnVariableUpdate” event.
Not Subscribed Subscribed The platform does not trigger the “OnVariableUpdate” event on the Universal VA publish.
Subscribed Not Subscribed The platform triggers the “OnVariableUpdate” event in the Universal VA on publish.
If the propagate flag is on for any VA variables, the platform includes the linked VA info for that variable in the “OnVariableUpdate” event.

 

This event is triggered on variable_update when the VA is published.
Syntax: variable_update : function (requestId, data, callback)
Parameters:

  • requestId – A unique ID for each message event.
  • data– A JSON response payload.
  • callback – The function to call after event completion; it is used to send the updated message and context back to the XO Platform.
var event = data.eventType;
console.log("event----------->", event);
if (first || event == "variable_update") {
// fetch BotVariables List for published assistants
sdk.fetchBotVariable(data, langArr, function(err, response) {
dataStore.saveAllVariables(response, langArr);
first = false;
});
} else {
var lang = data.language;
//update Existing BotVariables in Storage
updateBotVariableInDataStore(botVariables, data, event, lang);
}
console.log(dataStore);

Example Bot Kit Logs

Standard Bot:

Standard Bot: [{"variables":[{"_id":"vr-ec2ee9f3-ea56-54c5-a629-84821577dfaa","hint":"","key":"test1","variableType":"env","streamId":"st-b605ad17-2977-524a-9d93-ad5b68bd0afb","propagateValue":false,"createdOn":"2024-05-09T16:30:22.300Z","modifiedOn":"2024-05-09T16:30:22.300Z","scope":"prePopulated","value":"test1","audioTag":"","state":"published","group":"","isDeflect":false,"isSmartAssist":false,"isSecured":false,"vNameSpace":["37f26518-3072-5c45-8f7e-79ff7aa60719"],"__v":0,"resourceid":"botvariables"}],"moreAvailable":false,"count":1}]

Universal Bot:

Universal Bot: [{"variables":[{"_id":"vr-5fabdafd-99d7-5ea9-9b37-e3d00a22cd04","hint":"","key":"test1","variableType":"env","streamId":"st-bf3a7982-e13b-5e53-ba7e-c845465d6d37","propagateValue":true,"linkedBotId":"st-d465e6c6-f4a8-5e13-b3d0-feadf286ad4f","createdOn":"2024-05-09T16:38:30.099Z","modifiedOn":"2024-05-09T16:38:30.099Z","scope":"prePopulated","value":"test1","audioTag":"","state":"published","group":"","isDeflect":false,"isSmartAssist":false,"isSecured":false,"vNameSpace":[],"__v":0,"resourceid":"botvariables"}],"moreAvailable":false,"count":1}]

OnClientEvent

This event is triggered on client_event when the assistant receives client events sent by the third party application. Syntax: on_client_event : function (requestId, data, callback) Parameters:

  • requestId – A unique ID for each message event.
  • data– A JSON response payload
  • callback – The function to call after event completion; it is used to send the updated message and context back to the XO Platform.
on_client_event : function (requestId, data, callback) {
    console.log("on_client_event -->  : ", data.preDefinedEvent, data.customEvent);
    return sdk.sendBotEvent(data, callback);
    }

These events are associated with the application subscribing to botkit event type – onMessage and onagenttransfer. These event can be used to track the events like user is typing, user has stopped typing or user has read the message. Examples:

  • User started typing: Request: { “resourceid”: “/bot.clientEvent”, “preDefinedEvent” : { “type”: “TYPING_STARTED” }, “customEvent”: {“test”:”test”}, “botInfo”: {“chatBot”:”<bot-name>”, “taskBotId”:”<bot-id>”} } Response1: {“ok”:true,”type”:”ack”} Response2: {“type”:”events”, “from”:”bot”, “botInfo”: {“chatBot”:”<bot-name>”, “taskBotId”:”<bot-id>”} }, “preDefinedEvent”:{“type”:”TYPING_STARTED”}, “customEvent”:{“test”:”test”},”traceId”:”6b12f4cc73c806dd”}
  • User stopped typing: Request: { “resourceid”: “/bot.clientEvent”, “preDefinedEvent” : { “type”: “TYPING_STOPPED” }, “customEvent”: {“test”:”test”}, “botInfo”: {“chatBot”:”<bot-name>”, “taskBotId”:”<bot-id>”} } Response1: {“ok”:true,”type”:”ack”} Response2: {“type”:”events”, “from”:”bot”, “botInfo”: {“chatBot”:”<bot-name>”, “taskBotId”:”<bot-id>”} }, “preDefinedEvent”:{“type”:”TYPING_STOPPED”}, “customEvent”:{“test”:”test”},”traceId”:”6b12f4cc73c806dd”}
  • User read the message: Request: { “resourceid”: “/bot.clientEvent”, “preDefinedEvent” : { “type”: “MESSAGE_READ”, “id”: “<msg-id>” }, “customEvent”: {“string”}, “botInfo”: {“chatBot”:”<bot-name>”, “taskBotId”:”<bot-id>”} } Response1: {“ok”:true,”type”:”ack”} Response2: {“type”:”events”, “from”:”bot”, “botInfo”: {“chatBot”:”<bot-name>”, “taskBotId”:”<bot-id>”} }, “preDefinedEvent”:{“type”:”MESSAGE_READ”, “id”:”<msg-id>”}, “customEvent”:{“string”},”traceId”:”6b12f4cc73c806dd”}

Events for the BotKit SDK

You can use the Kore.ai BotKit SDK to capture and handle events in the Bots Platform for better control and customization of the user’s experience with the Virtual Assistant that you are building. The following events are supported by the BotKit SDK:

onMessage

This event consists of the following two components:

  • onUserMessage: This event is triggered when a user sends a message to the assistant and it is received by the channel adapter. The user message is wrapped in this event and sent to the SDK.
  • onBotMessage: This event is triggered when any messages need to be sent to the user. These messages are sent to the SDK along with context object.

onUserMessage

Syntax:

on_user_message : function(requestId, data, callback)

Parameters:

  • requestId – A unique ID for each message event.
  • payload – A JSON response payload as follows:
    {
       "message":"message sent by the assistant to the user",
       "taskId":"Dialog task Id",
       "nodeId":"current node id in the dialog flow",
       "channel":"channel name",
       "context":"context object"
    }
  • callback – The function to call at event completion used to send the updated message and context back to the XO Platform.

Example: In the following code example for the onUserMessage event, the user message is evaluated for transfer to a live agent and transferred, otherwise, the message is passed on to the BotKit SDK for processing.

/*
 * OnUserMessage event handler
 */
function onUserMessage(requestId, payload, callback){
    debug("user message", payload);
    var visitorId = _.get(payload, 'channel.from');
	visitorId = payload.context.session.UserContext._id;
	var entry = _map[visitorId];
	if (payload.message === "clearagent") // disconnect from LiveChat on user utterance
	{
		sdk.clearAgentSession(payload);
	}
    if(entry){//check for live agent
        //route to live agent
        var formdata = {};
        formdata.secured_session_id = entry.secured_session_id;
        formdata.licence_id = config.liveagentlicense;
        formdata.message = payload.message;
        return api.sendMsg(visitorId, formdata)
            .catch(function(e){
                console.error(e);
                delete userDataMap[visitorId];
                delete _map[visitorId];
                return sdk.sendBotMessage(payload, callback);
            });
    }
    else {
        return sdk.sendBotMessage(payload, callback);
    }
}

onBotMessage

Syntax:

 on_bot_message : function(requestId, data, callback)

Parameters:

  • requestId – A unique ID for each message event.
  • payload – A JSON response payload as follows:
    {
       "message":"message sent to the user",
       "channel":"channel name",
       "context":"context object"
    }
  • callback – The function to call at event completion used to send the updated message and context back to the user.

Example: The following code snippet onBotMessage event evaluates the user message for content and then for message tone. If the message tone is greater than or equal to 2 for the angry tone, then the communication between the user and the assistant is switched to a live agent.

/*
 * onBotMessage event handler
 */
function onBotMessage(requestId, payload, callback){
    debug("Bot Message Data",payload);
	console.log("in bot message");
    var visitorId = _.get(paylod, 'channel.from');
    var entry = _map[visitorId];
    if(data.message.length === 0 || payload.message === '') {
        return;
    }
    var message_tone = _.get(payload, 'context.message_tone');console.log("message tone -----",message_tone);
    if(message_tone && message_tone.length> 0){
        var angry = _.filter(message_tone, {tone_name: 'angry'});
        if(angry.length){
            angry = angry[0];
            if(angry.level >=2){
              return  connectToAgent(requestId, data);
            }
        }
    }
    if(!entry)
    {
        sdk.sendUserMessage(payload, callback);
    }
}

onWebHook

This event is triggered when the Kore NL Engine processes the Webhook node in the dialog flow. This event is sent to the SDK with componentId and context. The SDK can execute business logic and send the updated context back to the Platform. Syntax:

on_webhook = function(requestId, componentId, payload, callback)

Parameters:

  • requestId – A unique ID for each webhook event.
  • componentId – The unique ID for the SDKWebhook node.
  • payload – A JSON response payload as follows:
    {
       "message":"message sent by the assistant to the XO Platform",
       "taskId":"Dialog task Id",
       "nodeId":"current node id in the dialog flow",
       "channel":"channel name",
       "context":"context object"
    }
  • callback – The function to call at event completion used to send the updated message and context back to the XO Platform.

Examples In the following example for the on_webhook event, two hotel names are returned as results as a response to user input.

    //on_webhook handler
    on_webhook  : function(requestId, payload, componentId, callback) {
        if (componentId === 'sendResponse') {
          var hotels = {
            "hotels":[
                  "Taj Banjara",
                  "Novotel"
            ]
          };
          payload.context.hotelResults = hotels;
          callback(null,data);
        }
    }

In this example for the on_webhook event, for the Flights Info node in a dialog task, either a list of departure or destination airports based on the requested date is returned based on the flow of the dialog, as a list of results displayed to the end user.

    on_webhook : function(requestId, payload, componentId, callback) {
        var context = payload.context;
	    if (componentName === 'FlightsInfo') {
		  var origin = context.entities.Source;
          var destination = context.entities.Dest;
          var departureDate = context.entities.Date;
          findFlights(origin,destination,departureDate)
			.then(function(flightResults) {
                payload.context.flightResults = flightResults;
				callback(null, data);
			});
	    } else if(componentId === 'GetSourceAirports'){
             var searchTerm = context.entities.SourceName;
             findAirports(searchTerm)
            .then(function(airportResults) {
                payload.context.sourceAirports = airportResults;
                callback(null, data);
            });
        } else if(componentId === 'GetDestAirports'){
           var searchTerm = context.entities.DestName;
             findAirports(searchTerm)
            .then(function(airportResults) {
                payload.context.destAirports = airportResults;
                callback(null, data);
            });
        }

onAgentTransfer

This event is triggered when the Kore NL Engine processes an Agent Transfer node in the dialog flow. This event is sent to the SDK with requestId and context. The SDK can execute a business logic to switch the user seamlessly to a Live Agent. Syntax:

function onAgentTransfer(requestId, data, callback){
connectToAgent(requestId, data, callback);
}

Parameters:

  • requestId – A unique ID for each message event.
  • payload – A JSON response payload as follows:
    {
       OnAgentTransferPayload ","
          requestId ":1501244156289,"
          botId ":"st - b4a22e86 - e95b - 575 c - b888 - e106d083a251 ","
          callbackUrl ":"https: //bots.kore.ai/api/botsdk/stream/st-b4a22e86-e95b-575c-b888-e106d083a251/serviceCallback/1501244156289","context": ...
    }
  • callback – The function to call at event completion used to send the updated message and context back to the XO Platform.

Example: The following code snippet onAgentTransfer event connects the user to a Live Agent and passing the user message, bot message, and historical chat messages of the session.

function connectToAgent(requestId, data, cb){
var formdata = {}; console.log("userlog",JSON.stringify(data.context.session.UserContext._id));
formdata.licence_id = config.liveagentlicense;
formdata.welcome_message = "";
var visitorId = _.get(data, 'channel.channelInfos.from');
if(!visitorId){
visitorId = _.get(data, 'channel.from');
}
visitorId = data.context.session.UserContext._id;
userDataMap[visitorId] = data;
data.message="An Agent will be assigned to you shortly!!!";
var d = new Date();
data.context.session.BotUserSession.startTime = new Date().toLocaleString();
console.log("userlog",JSON.stringify(data.context.session));
sdk.sendUserMessage(data, cb);
formdata.welcome_message = "Link for user Chat history with the assistant : "+ config.app.url +"/history/index.html?visitorId=" + visitorId;
return api.initChat(visitorId, formdata)
.then(function(res){
_map[visitorId] = {
secured_session_id: res.secured_session_id,
visitorId: visitorId,
last_message_id: 0
};
});
}


		

OnEvent

This event is triggered when Dialog Task or FAQ ends in the assistant and sends request ID and context to the SDK. Syntax: on_event : function (requestId, data, callback) Parameters:

  • requestId – A unique ID for each message event.
  • data– A JSON response payload as shown in the example below:
  • callback – The function to call after event completion; it is used to send the updated message and context back to the XO Platform.

Example:

on_event : function (requestId, data, callback)
{
return sdk.sendAlertMessage(data, callback);
}

The event adds the following code in the Data object sent to kit:

"event":
{
"event Type": "endDialog"/ “endFAQ”
}


		

OnAlert

This event is triggered when a user receives an alert. Syntax: on_alert : function (requestId, data, callback) Parameters:

  • requestId – A unique ID for each message event.
  • data– A JSON response payload.
  • callback – The function to call at event completion; it is used to send the updated message and context back to the XO Platform.

Example:

on_alert: function(requestId, data, callback)
{
 return sdk.sendAlertMessage(data, callback);
}

The alert response data is found in the data object sent to the kit.

OnVariableUpdate

The “OnVariableUpdate” event allows you to access VA variables in both the standard and the universal VA. By default, it is not subscribed. You can subscribe to this event to retrieve variables from the VA when publishing. In BotKit, you can use the OnVariableUpdate event to manage VA variables. Learn more.

Event Trigger Scenarios and Behaviors for Universal VA

Universal VA Child VA Behavior
Subscribed Subscribed The platform triggers the “OnVariableUpdate” event in the Universal VA on publish.
If the propagate flag is on for any VA variables, the platform includes the linked VA info for that variable in the “OnVariableUpdate” event.
Not Subscribed Subscribed The platform does not trigger the “OnVariableUpdate” event on the Universal VA publish.
Subscribed Not Subscribed The platform triggers the “OnVariableUpdate” event in the Universal VA on publish.
If the propagate flag is on for any VA variables, the platform includes the linked VA info for that variable in the “OnVariableUpdate” event.

 

This event is triggered on variable_update when the VA is published.
Syntax: variable_update : function (requestId, data, callback)
Parameters:

  • requestId – A unique ID for each message event.
  • data– A JSON response payload.
  • callback – The function to call after event completion; it is used to send the updated message and context back to the XO Platform.
var event = data.eventType;
console.log("event----------->", event);
if (first || event == "variable_update") {
// fetch BotVariables List for published assistants
sdk.fetchBotVariable(data, langArr, function(err, response) {
dataStore.saveAllVariables(response, langArr);
first = false;
});
} else {
var lang = data.language;
//update Existing BotVariables in Storage
updateBotVariableInDataStore(botVariables, data, event, lang);
}
console.log(dataStore);

Example Bot Kit Logs

Standard Bot:

Standard Bot: [{"variables":[{"_id":"vr-ec2ee9f3-ea56-54c5-a629-84821577dfaa","hint":"","key":"test1","variableType":"env","streamId":"st-b605ad17-2977-524a-9d93-ad5b68bd0afb","propagateValue":false,"createdOn":"2024-05-09T16:30:22.300Z","modifiedOn":"2024-05-09T16:30:22.300Z","scope":"prePopulated","value":"test1","audioTag":"","state":"published","group":"","isDeflect":false,"isSmartAssist":false,"isSecured":false,"vNameSpace":["37f26518-3072-5c45-8f7e-79ff7aa60719"],"__v":0,"resourceid":"botvariables"}],"moreAvailable":false,"count":1}]

Universal Bot:

Universal Bot: [{"variables":[{"_id":"vr-5fabdafd-99d7-5ea9-9b37-e3d00a22cd04","hint":"","key":"test1","variableType":"env","streamId":"st-bf3a7982-e13b-5e53-ba7e-c845465d6d37","propagateValue":true,"linkedBotId":"st-d465e6c6-f4a8-5e13-b3d0-feadf286ad4f","createdOn":"2024-05-09T16:38:30.099Z","modifiedOn":"2024-05-09T16:38:30.099Z","scope":"prePopulated","value":"test1","audioTag":"","state":"published","group":"","isDeflect":false,"isSmartAssist":false,"isSecured":false,"vNameSpace":[],"__v":0,"resourceid":"botvariables"}],"moreAvailable":false,"count":1}]

OnClientEvent

This event is triggered on client_event when the assistant receives client events sent by the third party application. Syntax: on_client_event : function (requestId, data, callback) Parameters:

  • requestId – A unique ID for each message event.
  • data– A JSON response payload
  • callback – The function to call after event completion; it is used to send the updated message and context back to the XO Platform.
on_client_event : function (requestId, data, callback) {
    console.log("on_client_event -->  : ", data.preDefinedEvent, data.customEvent);
    return sdk.sendBotEvent(data, callback);
    }

These events are associated with the application subscribing to botkit event type – onMessage and onagenttransfer. These event can be used to track the events like user is typing, user has stopped typing or user has read the message. Examples:

  • User started typing: Request: { “resourceid”: “/bot.clientEvent”, “preDefinedEvent” : { “type”: “TYPING_STARTED” }, “customEvent”: {“test”:”test”}, “botInfo”: {“chatBot”:”<bot-name>”, “taskBotId”:”<bot-id>”} } Response1: {“ok”:true,”type”:”ack”} Response2: {“type”:”events”, “from”:”bot”, “botInfo”: {“chatBot”:”<bot-name>”, “taskBotId”:”<bot-id>”} }, “preDefinedEvent”:{“type”:”TYPING_STARTED”}, “customEvent”:{“test”:”test”},”traceId”:”6b12f4cc73c806dd”}
  • User stopped typing: Request: { “resourceid”: “/bot.clientEvent”, “preDefinedEvent” : { “type”: “TYPING_STOPPED” }, “customEvent”: {“test”:”test”}, “botInfo”: {“chatBot”:”<bot-name>”, “taskBotId”:”<bot-id>”} } Response1: {“ok”:true,”type”:”ack”} Response2: {“type”:”events”, “from”:”bot”, “botInfo”: {“chatBot”:”<bot-name>”, “taskBotId”:”<bot-id>”} }, “preDefinedEvent”:{“type”:”TYPING_STOPPED”}, “customEvent”:{“test”:”test”},”traceId”:”6b12f4cc73c806dd”}
  • User read the message: Request: { “resourceid”: “/bot.clientEvent”, “preDefinedEvent” : { “type”: “MESSAGE_READ”, “id”: “<msg-id>” }, “customEvent”: {“string”}, “botInfo”: {“chatBot”:”<bot-name>”, “taskBotId”:”<bot-id>”} } Response1: {“ok”:true,”type”:”ack”} Response2: {“type”:”events”, “from”:”bot”, “botInfo”: {“chatBot”:”<bot-name>”, “taskBotId”:”<bot-id>”} }, “preDefinedEvent”:{“type”:”MESSAGE_READ”, “id”:”<msg-id>”}, “customEvent”:{“string”},”traceId”:”6b12f4cc73c806dd”}
メニュー