-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathSimpleConversationalBotWithMultipleBotId.js
51 lines (45 loc) · 1.58 KB
/
SimpleConversationalBotWithMultipleBotId.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var botId = ["st-12345","st-67890"];
var botName = "testBot";
var sdk = require("./lib/sdk");
/*
* This is the most basic example of BotKit.
*
* It showcases how the BotKit can intercept the message being sent to the bot or the user.
*
* We can either update the message, or chose to call one of 'sendBotMessage' or 'sendUserMessage'
*/
module.exports = {
botId : botId,
botName : botName,
on_user_message : function(requestId, data, callback) {
if (data.message === "Hi") {
data.message = "Hello";
//Sends back 'Hello' to user.
return sdk.sendUserMessage(data, callback);
} else if(!data.agent_transfer){
//Forward the message to bot
return sdk.sendBotMessage(data, callback);
} else {
data.message = "Agent Message";
return sdk.sendUserMessage(data, callback);
}
},
on_bot_message : function(requestId, data, callback) {
if (data.message === 'hello') {
data.message = 'The Bot says hello!';
}
//Sends back the message to user
return sdk.sendUserMessage(data, callback);
},
on_agent_transfer : function(requestId, data, callback){
return callback(null, data);
},
on_event : function (requestId, data, callback) {
console.log("on_event --> Event : ", data.event);
return callback(null, data);
},
on_alert : function (requestId, data, callback) {
console.log("on_alert --> : ", data, data.message);
return sdk.sendAlertMessage(data, callback);
}
};