@tiledesk/tiledesk-tybot-connector 0.1.62 → 0.1.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/index.js +5 -1
- package/models/MockBotsDataSource.js +10 -1
- package/models/TiledeskChatbot.js +2 -2
- package/models/TiledeskChatbotUtil.js +3 -0
- package/package.json +1 -1
- package/test/conversation-form-test.js +45 -45
- package/test/json_condition-actions_bot.js +7 -12
- package/test/json_condition-conversation_test.js +1 -1
- package/test/json_condition-with-intent-params-conversation_test.js +282 -0
- package/test/json_condition-with-intent-params_bot.js +159 -0
- package/test/web_request-conversation_test.js +1 -1
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +113 -98
- package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +1 -1
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +7 -7
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +10 -18
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +4 -2
- package/tiledeskChatbotPlugs/directives/DirIntent.js +23 -1
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +8 -6
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +37 -22
- /package/test/{disable_input_text_directive_test.js → DEPRECATED-disable_input_text_directive_test.js_} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,20 @@
|
|
|
5
5
|
available on:
|
|
6
6
|
▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
|
|
7
7
|
|
|
8
|
+
### 0.1.63
|
|
9
|
+
- Added stopOnConditionMet to DirIfOnlineAgents
|
|
10
|
+
- Removed deprecated Directive Directives.WHEN_OFFLINE_HOURS
|
|
11
|
+
- Removed deprecated Directive Directives.DISABLE_INPUT_TEXT
|
|
12
|
+
- Removed deprecated Directive Directives.WHEN_OPEN
|
|
13
|
+
- Removed deprecated Directive Directives.WHEN_CLOSED
|
|
14
|
+
- Removed deprecated Directive Directives.IF_AGENTS
|
|
15
|
+
- Removed deprecated Directive Directives.IF_NO_AGENTS
|
|
16
|
+
- Added support for intent parameters in DirJSONCondition DirIfOnlineAgents DirIfOpeningHours
|
|
17
|
+
- Added JSONCondition with intent parameters test
|
|
18
|
+
|
|
19
|
+
### 0.1.63 - online
|
|
20
|
+
- Added support for depId-from-supportRequest in DirMoveToAgent. This fixes no-handoff in test-it-out and from Dialogflow connector
|
|
21
|
+
|
|
8
22
|
### 0.1.62
|
|
9
23
|
- Added TiledeskChatbotUtil.fillCommandAttachments() replacing vars in commands.button.link
|
|
10
24
|
|
package/index.js
CHANGED
|
@@ -390,7 +390,11 @@ router.post('/ext/:projectId/requests/:requestId/messages', async (req, res) =>
|
|
|
390
390
|
id_project: projectId
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
|
-
|
|
393
|
+
if (log) {
|
|
394
|
+
console.log("/ext request....", JSON.stringify(request));
|
|
395
|
+
console.log("/ext APIURL....", APIURL);
|
|
396
|
+
console.log("/ext process.env.TYBOT_ENDPOINT....", process.env.TYBOT_ENDPOINT);
|
|
397
|
+
}
|
|
394
398
|
let directivesPlug = new DirectivesChatbotPlug({supportRequest: request, TILEDESK_API_ENDPOINT: APIURL, TILEBOT_ENDPOINT:process.env.TYBOT_ENDPOINT, token: token, log: log, HELP_CENTER_API_ENDPOINT: process.env.HELP_CENTER_API_ENDPOINT, cache: tdcache});
|
|
395
399
|
// PIPELINE-EXT
|
|
396
400
|
// if (log) {console.log("answer to process:", JSON.stringify(answer));}
|
|
@@ -64,7 +64,16 @@ class MockBotsDataSource {
|
|
|
64
64
|
faq = await this.getByIntentDisplayName(botId, key);
|
|
65
65
|
// console.log("faq found in datasource..:", JSON.stringify(faq));
|
|
66
66
|
}
|
|
67
|
-
|
|
67
|
+
// clones the faq to avoid modifying original object
|
|
68
|
+
// console.log("faq is:", faq)
|
|
69
|
+
let json_faq;
|
|
70
|
+
if (faq !== null && faq !== undefined) {
|
|
71
|
+
let string_faq = JSON.stringify(faq)
|
|
72
|
+
// console.log("string faq is:", string_faq)
|
|
73
|
+
json_faq = JSON.parse(string_faq);
|
|
74
|
+
// console.log("json faq is:", json_faq)
|
|
75
|
+
}
|
|
76
|
+
return json_faq;
|
|
68
77
|
}
|
|
69
78
|
|
|
70
79
|
/**
|
|
@@ -580,7 +580,7 @@ class TiledeskChatbot {
|
|
|
580
580
|
if (static_bot_answer.attributes && static_bot_answer.attributes.webhook && static_bot_answer.attributes.webhook === true) {
|
|
581
581
|
const variables = await this.allParameters();
|
|
582
582
|
context.variables = variables;
|
|
583
|
-
if (this.log) {console.log("adding variables to webhook context:", context.variables);}
|
|
583
|
+
if (this.log) {console.log("adding variables to webhook context:", JSON.stringify(context.variables));}
|
|
584
584
|
}
|
|
585
585
|
const messagePipeline = new MessagePipeline(static_bot_answer, context);
|
|
586
586
|
const webhookurl = bot.webhook_url;
|
|
@@ -625,7 +625,7 @@ class TiledeskChatbot {
|
|
|
625
625
|
});
|
|
626
626
|
// const parameters_key = "tilebot:requests:" + requestId + ":parameters";
|
|
627
627
|
const all_parameters = await this.allParameters();//this.tdcache.hgetall(parameters_key);
|
|
628
|
-
if (this.log) {console.log("(populatePrechatFormAndLead) parameters_key:", all_parameters);}
|
|
628
|
+
if (this.log) {console.log("(populatePrechatFormAndLead) parameters_key:", JSON.stringify(all_parameters));}
|
|
629
629
|
if (all_parameters) {
|
|
630
630
|
if (this.log) {console.log("(populatePrechatFormAndLead) userEmail:", all_parameters['userEmail']);}
|
|
631
631
|
if (this.log) {console.log("(populatePrechatFormAndLead) userFullname:", all_parameters['userFullname']);}
|
package/package.json
CHANGED
|
@@ -138,55 +138,55 @@ describe('Conversation1 - Form filling', async () => {
|
|
|
138
138
|
});
|
|
139
139
|
});
|
|
140
140
|
|
|
141
|
-
it('/disable_input', (done) => {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
141
|
+
// it('/disable_input', (done) => {
|
|
142
|
+
// // console.log("/disable_input...");
|
|
143
|
+
// let listener;
|
|
144
|
+
// let endpointServer = express();
|
|
145
|
+
// endpointServer.use(bodyParser.json());
|
|
146
|
+
// endpointServer.post('/:projectId/requests/:requestId/messages', function (req, res) {
|
|
147
|
+
// // console.log("req.body....:", JSON.stringify(req.body));
|
|
148
|
+
// res.send({ success: true });
|
|
149
|
+
// const message = req.body;
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
// assert(message["text"] !== "");
|
|
152
|
+
// assert(message["attributes"] !== "");
|
|
153
|
+
// assert(message["attributes"]["disableInputMessage"] === true);
|
|
154
154
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
// listener.close(() => {
|
|
156
|
+
// // console.log('closed.');
|
|
157
|
+
// done();
|
|
158
|
+
// });
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
// });
|
|
161
161
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
});
|
|
162
|
+
// listener = endpointServer.listen(10002, '0.0.0.0', function () {
|
|
163
|
+
// // console.log('endpointServer started', listener.address());
|
|
164
|
+
// // const botId = process.env.TEST_BOT_ID;
|
|
165
|
+
// // const PROJECT_ID = process.env.TEST_PROJECT_ID;
|
|
166
|
+
// // console.log("botId:", botId);
|
|
167
|
+
// // console.log("REQUEST_ID:", REQUEST_ID);
|
|
168
|
+
// let request = {
|
|
169
|
+
// "payload": {
|
|
170
|
+
// "_id": uuidv4(),
|
|
171
|
+
// "senderFullname": "guest#367e",
|
|
172
|
+
// "type": "text",
|
|
173
|
+
// "sender": "A-SENDER",
|
|
174
|
+
// "recipient": REQUEST_ID,
|
|
175
|
+
// "text": "/disable_input",
|
|
176
|
+
// "id_project": PROJECT_ID,
|
|
177
|
+
// "metadata": "",
|
|
178
|
+
// "request": {
|
|
179
|
+
// "request_id": REQUEST_ID,
|
|
180
|
+
// "id_project": PROJECT_ID
|
|
181
|
+
// }
|
|
182
|
+
// },
|
|
183
|
+
// "token": CHATBOT_TOKEN
|
|
184
|
+
// }
|
|
185
|
+
// sendMessageToBot(request, BOT_ID, CHATBOT_TOKEN, () => {
|
|
186
|
+
// // console.log("Message sent.");
|
|
187
|
+
// });
|
|
188
|
+
// });
|
|
189
|
+
// });
|
|
190
190
|
|
|
191
191
|
it('/good_form', (done) => {
|
|
192
192
|
// console.log("/good_form...");
|
|
@@ -213,8 +213,7 @@ const bot = {
|
|
|
213
213
|
"actions": [{
|
|
214
214
|
"_tdActionTitle": null,
|
|
215
215
|
"_tdActionType": "jsoncondition",
|
|
216
|
-
"
|
|
217
|
-
"groups": [{
|
|
216
|
+
"groups": [{
|
|
218
217
|
"type": "expression",
|
|
219
218
|
"conditions": [{
|
|
220
219
|
"type": "condition",
|
|
@@ -226,15 +225,13 @@ const bot = {
|
|
|
226
225
|
"name": ""
|
|
227
226
|
}
|
|
228
227
|
}]
|
|
229
|
-
|
|
230
|
-
},
|
|
228
|
+
}],
|
|
231
229
|
"stopOnConditionMet": true,
|
|
232
230
|
"trueIntent": "#d19b1b7a-7146-481d-a7d5-6b9cce8fcb50"
|
|
233
231
|
}, {
|
|
234
232
|
"_tdActionTitle": null,
|
|
235
233
|
"_tdActionType": "jsoncondition",
|
|
236
|
-
"
|
|
237
|
-
"groups": [{
|
|
234
|
+
"groups": [{
|
|
238
235
|
"type": "expression",
|
|
239
236
|
"conditions": [{
|
|
240
237
|
"type": "condition",
|
|
@@ -246,15 +243,13 @@ const bot = {
|
|
|
246
243
|
"name": ""
|
|
247
244
|
}
|
|
248
245
|
}]
|
|
249
|
-
|
|
250
|
-
},
|
|
246
|
+
}],
|
|
251
247
|
"stopOnConditionMet": true,
|
|
252
248
|
"trueIntent": "#16240c0b-9618-40cd-87e7-6319e5c3e392"
|
|
253
249
|
}, {
|
|
254
250
|
"_tdActionTitle": null,
|
|
255
251
|
"_tdActionType": "jsoncondition",
|
|
256
|
-
"
|
|
257
|
-
"groups": [{
|
|
252
|
+
"groups": [{
|
|
258
253
|
"type": "expression",
|
|
259
254
|
"conditions": [{
|
|
260
255
|
"type": "condition",
|
|
@@ -278,8 +273,8 @@ const bot = {
|
|
|
278
273
|
"name": ""
|
|
279
274
|
}
|
|
280
275
|
}]
|
|
281
|
-
|
|
282
|
-
|
|
276
|
+
}],
|
|
277
|
+
|
|
283
278
|
"stopOnConditionMet": false,
|
|
284
279
|
"trueIntent": "#98dd1994-83ef-4863-8179-07c48d2194b9"
|
|
285
280
|
}],
|
|
@@ -59,7 +59,7 @@ describe('Conversation for JSONCondition test', async () => {
|
|
|
59
59
|
let endpointServer = express();
|
|
60
60
|
endpointServer.use(bodyParser.json());
|
|
61
61
|
endpointServer.post('/:projectId/requests/:requestId/messages', function (req, res) {
|
|
62
|
-
|
|
62
|
+
console.log("...req.body:", JSON.stringify(req.body));
|
|
63
63
|
res.send({ success: true });
|
|
64
64
|
const message = req.body;
|
|
65
65
|
assert(message.attributes.commands !== null);
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
let axios = require('axios');
|
|
3
|
+
const tybot = require("../");
|
|
4
|
+
const tybotRoute = tybot.router;
|
|
5
|
+
var express = require('express');
|
|
6
|
+
var app = express();
|
|
7
|
+
app.use("/", tybotRoute);
|
|
8
|
+
app.use((err, req, res, next) => {
|
|
9
|
+
console.error("General error", err);
|
|
10
|
+
});
|
|
11
|
+
require('dotenv').config();
|
|
12
|
+
const bodyParser = require('body-parser');
|
|
13
|
+
const { v4: uuidv4 } = require('uuid');
|
|
14
|
+
const bots_data = require('./json_condition-with-intent-params_bot.js').bots_data;
|
|
15
|
+
|
|
16
|
+
const PROJECT_ID = "projectID"; //process.env.TEST_ACTIONS_PROJECT_ID;
|
|
17
|
+
const REQUEST_ID = "support-group-" + PROJECT_ID + "-" + uuidv4().replace(/-/g, "");
|
|
18
|
+
const BOT_ID = "botID"; //process.env.TEST_ACTIONS_BOT_ID;
|
|
19
|
+
const CHATBOT_TOKEN = "XXX"; //process.env.ACTIONS_CHATBOT_TOKEN;
|
|
20
|
+
|
|
21
|
+
describe('Conversation for JSONCondition with intent params test', async () => {
|
|
22
|
+
|
|
23
|
+
let app_listener;
|
|
24
|
+
|
|
25
|
+
before(() => {
|
|
26
|
+
return new Promise(async (resolve, reject) => {
|
|
27
|
+
console.log("Starting tilebot server...");
|
|
28
|
+
tybot.startApp(
|
|
29
|
+
{
|
|
30
|
+
// MONGODB_URI: process.env.mongoUrl,
|
|
31
|
+
bots: bots_data,
|
|
32
|
+
API_ENDPOINT: process.env.API_ENDPOINT,
|
|
33
|
+
REDIS_HOST: process.env.REDIS_HOST,
|
|
34
|
+
REDIS_PORT: process.env.REDIS_PORT,
|
|
35
|
+
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
|
|
36
|
+
log: process.env.API_LOG
|
|
37
|
+
}, () => {
|
|
38
|
+
console.log("Tilebot route successfully started.");
|
|
39
|
+
var port = process.env.PORT || 10001;
|
|
40
|
+
app_listener = app.listen(port, () => {
|
|
41
|
+
console.log('Tilebot connector listening on port ', port);
|
|
42
|
+
resolve();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
after(function (done) {
|
|
49
|
+
app_listener.close(() => {
|
|
50
|
+
// console.log('ACTIONS app_listener closed.');
|
|
51
|
+
done();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('/condition with params{"star_type":"supernova"}', (done) => {
|
|
56
|
+
console.log('/condition with params{"star_type":"supernova"}');
|
|
57
|
+
// let message_id = uuidv4();
|
|
58
|
+
let listener;
|
|
59
|
+
let endpointServer = express();
|
|
60
|
+
endpointServer.use(bodyParser.json());
|
|
61
|
+
endpointServer.post('/:projectId/requests/:requestId/messages', function (req, res) {
|
|
62
|
+
console.log("...req.body:", JSON.stringify(req.body));
|
|
63
|
+
res.send({ success: true });
|
|
64
|
+
const message = req.body;
|
|
65
|
+
assert(message.attributes.commands !== null);
|
|
66
|
+
assert(message.attributes.commands.length === 2);
|
|
67
|
+
const command2 = message.attributes.commands[1];
|
|
68
|
+
|
|
69
|
+
assert(command2.type === "message");
|
|
70
|
+
assert(command2.message.text === "My name is supernova and I'm 2B km large");
|
|
71
|
+
getChatbotParameters(REQUEST_ID, (err, params) => {
|
|
72
|
+
if (err) {
|
|
73
|
+
assert.ok(false);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
assert(params);
|
|
77
|
+
// assert(params["last_message_id"] === message_id);
|
|
78
|
+
assert(params["project_id"] === PROJECT_ID);
|
|
79
|
+
assert(params["star_type"] === "supernova");
|
|
80
|
+
assert(params["my_name"] === "supernova");
|
|
81
|
+
assert(params["size"] === "2B");
|
|
82
|
+
listener.close(() => {
|
|
83
|
+
done();
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
listener = endpointServer.listen(10002, '0.0.0.0', () => {
|
|
91
|
+
// console.log('endpointServer started', listener.address());
|
|
92
|
+
let request = {
|
|
93
|
+
"payload": {
|
|
94
|
+
// "_id": message_id,
|
|
95
|
+
"senderFullname": "guest#367e",
|
|
96
|
+
"type": "text",
|
|
97
|
+
"sender": "A-SENDER",
|
|
98
|
+
"recipient": REQUEST_ID,
|
|
99
|
+
"text": '/condition with params{"star_type":"supernova"}',
|
|
100
|
+
"id_project": PROJECT_ID,
|
|
101
|
+
"metadata": "",
|
|
102
|
+
"request": {
|
|
103
|
+
"request_id": REQUEST_ID
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
"token": CHATBOT_TOKEN
|
|
107
|
+
}
|
|
108
|
+
sendMessageToBot(request, BOT_ID, () => {
|
|
109
|
+
// console.log("Message sent:\n", request);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('/condition with params{"star_type":"nebula"}', (done) => {
|
|
115
|
+
console.log('/condition with params{"star_type":"nebula"}');
|
|
116
|
+
// let message_id = uuidv4();
|
|
117
|
+
let listener;
|
|
118
|
+
let endpointServer = express();
|
|
119
|
+
endpointServer.use(bodyParser.json());
|
|
120
|
+
endpointServer.post('/:projectId/requests/:requestId/messages', function (req, res) {
|
|
121
|
+
console.log("...req.body:", JSON.stringify(req.body));
|
|
122
|
+
res.send({ success: true });
|
|
123
|
+
const message = req.body;
|
|
124
|
+
assert(message.attributes.commands !== null);
|
|
125
|
+
assert(message.attributes.commands.length === 2);
|
|
126
|
+
const command2 = message.attributes.commands[1];
|
|
127
|
+
|
|
128
|
+
assert(command2.type === "message");
|
|
129
|
+
assert(command2.message.text === "My name is nebula and I'm 500k km large");
|
|
130
|
+
getChatbotParameters(REQUEST_ID, (err, params) => {
|
|
131
|
+
if (err) {
|
|
132
|
+
assert.ok(false);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
console.log("params:", params)
|
|
136
|
+
assert(params);
|
|
137
|
+
// assert(params["last_message_id"] === message_id);
|
|
138
|
+
assert(params["project_id"] === PROJECT_ID);
|
|
139
|
+
assert(params["star_type"] === "nebula");
|
|
140
|
+
assert(params["my_name"] === "nebula");
|
|
141
|
+
assert(params["size"] === "500k");
|
|
142
|
+
listener.close(() => {
|
|
143
|
+
done();
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
listener = endpointServer.listen(10002, '0.0.0.0', () => {
|
|
151
|
+
// console.log('endpointServer started', listener.address());
|
|
152
|
+
let request = {
|
|
153
|
+
"payload": {
|
|
154
|
+
// "_id": message_id,
|
|
155
|
+
"senderFullname": "guest#367e",
|
|
156
|
+
"type": "text",
|
|
157
|
+
"sender": "A-SENDER",
|
|
158
|
+
"recipient": REQUEST_ID,
|
|
159
|
+
"text": '/condition with params{"star_type":"nebula"}',
|
|
160
|
+
"id_project": PROJECT_ID,
|
|
161
|
+
"metadata": "",
|
|
162
|
+
"request": {
|
|
163
|
+
"request_id": REQUEST_ID
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
"token": CHATBOT_TOKEN
|
|
167
|
+
}
|
|
168
|
+
sendMessageToBot(request, BOT_ID, () => {
|
|
169
|
+
// console.log("Message sent:\n", request);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* A stub to send message to the "ext/botId" endpoint, hosted by tilebot on:
|
|
178
|
+
* /${TILEBOT_ROUTE}/ext/${botId}
|
|
179
|
+
*
|
|
180
|
+
* @param {Object} message. The message to send
|
|
181
|
+
* @param {string} botId. Tiledesk botId
|
|
182
|
+
* @param {string} token. User token
|
|
183
|
+
*/
|
|
184
|
+
function sendMessageToBot(message, botId, callback) {
|
|
185
|
+
// const jwt_token = this.fixToken(token);
|
|
186
|
+
const url = `${process.env.TYBOT_ENDPOINT}/ext/${botId}`;
|
|
187
|
+
// console.log("sendMessageToBot URL", url);
|
|
188
|
+
const HTTPREQUEST = {
|
|
189
|
+
url: url,
|
|
190
|
+
headers: {
|
|
191
|
+
'Content-Type': 'application/json'
|
|
192
|
+
},
|
|
193
|
+
json: message,
|
|
194
|
+
method: 'POST'
|
|
195
|
+
};
|
|
196
|
+
myrequest(
|
|
197
|
+
HTTPREQUEST,
|
|
198
|
+
function (err, resbody) {
|
|
199
|
+
if (err) {
|
|
200
|
+
if (callback) {
|
|
201
|
+
callback(err);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
if (callback) {
|
|
206
|
+
callback(null, resbody);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}, false
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* A stub to get the request parameters, hosted by tilebot on:
|
|
215
|
+
* /${TILEBOT_ROUTE}/ext/parameters/requests/${requestId}?all
|
|
216
|
+
*
|
|
217
|
+
* @param {string} requestId. Tiledesk chatbot/requestId parameters
|
|
218
|
+
*/
|
|
219
|
+
function getChatbotParameters(requestId, callback) {
|
|
220
|
+
// const jwt_token = this.fixToken(token);
|
|
221
|
+
const url = `${process.env.TYBOT_ENDPOINT}/ext/parameters/requests/${requestId}?all`;
|
|
222
|
+
const HTTPREQUEST = {
|
|
223
|
+
url: url,
|
|
224
|
+
headers: {
|
|
225
|
+
'Content-Type': 'application/json'
|
|
226
|
+
},
|
|
227
|
+
method: 'get'
|
|
228
|
+
};
|
|
229
|
+
myrequest(
|
|
230
|
+
HTTPREQUEST,
|
|
231
|
+
function (err, resbody) {
|
|
232
|
+
if (err) {
|
|
233
|
+
if (callback) {
|
|
234
|
+
callback(err);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
if (callback) {
|
|
239
|
+
callback(null, resbody);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}, false
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function myrequest(options, callback, log) {
|
|
247
|
+
if (log) {
|
|
248
|
+
console.log("API URL:", options.url);
|
|
249
|
+
console.log("** Options:", JSON.stringify(options));
|
|
250
|
+
}
|
|
251
|
+
axios(
|
|
252
|
+
{
|
|
253
|
+
url: options.url,
|
|
254
|
+
method: options.method,
|
|
255
|
+
data: options.json,
|
|
256
|
+
params: options.params,
|
|
257
|
+
headers: options.headers
|
|
258
|
+
})
|
|
259
|
+
.then((res) => {
|
|
260
|
+
if (log) {
|
|
261
|
+
console.log("Response for url:", options.url);
|
|
262
|
+
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
263
|
+
//console.log("******** Response for url:", res);
|
|
264
|
+
}
|
|
265
|
+
if (res && res.status == 200 && res.data) {
|
|
266
|
+
if (callback) {
|
|
267
|
+
callback(null, res.data);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
if (callback) {
|
|
272
|
+
callback(TiledeskClient.getErr({ message: "Response status not 200" }, options, res), null, null);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
})
|
|
276
|
+
.catch((error) => {
|
|
277
|
+
console.error("An error occurred:", error);
|
|
278
|
+
if (callback) {
|
|
279
|
+
callback(error, null, null);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
const bot = {
|
|
2
|
+
"webhook_enabled": false,
|
|
3
|
+
"language": "en",
|
|
4
|
+
"name": "Link Button",
|
|
5
|
+
"type": "tilebot",
|
|
6
|
+
"intents": [{
|
|
7
|
+
"webhook_enabled": false,
|
|
8
|
+
"enabled": true,
|
|
9
|
+
"actions": [{
|
|
10
|
+
"_tdActionType": "reply",
|
|
11
|
+
"text": "Start\r\n",
|
|
12
|
+
"attributes": {
|
|
13
|
+
"commands": [{
|
|
14
|
+
"type": "wait",
|
|
15
|
+
"time": 500
|
|
16
|
+
}, {
|
|
17
|
+
"type": "message",
|
|
18
|
+
"message": {
|
|
19
|
+
"type": "text",
|
|
20
|
+
"text": "Start",
|
|
21
|
+
"attributes": {
|
|
22
|
+
"attachment": {
|
|
23
|
+
"type": "template",
|
|
24
|
+
"buttons": [{
|
|
25
|
+
"value": "/condition with params{\"star_type\":\"supernova\"}",
|
|
26
|
+
"type": "text",
|
|
27
|
+
"target": "blank",
|
|
28
|
+
"link": "",
|
|
29
|
+
"action": "",
|
|
30
|
+
"show_echo": true
|
|
31
|
+
}, {
|
|
32
|
+
"value": "/condition with params{\"star_type\":\"nebula\"}",
|
|
33
|
+
"type": "text",
|
|
34
|
+
"target": "blank",
|
|
35
|
+
"link": "",
|
|
36
|
+
"action": "",
|
|
37
|
+
"show_echo": true
|
|
38
|
+
}]
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}]
|
|
43
|
+
},
|
|
44
|
+
"_tdActionTitle": null
|
|
45
|
+
}],
|
|
46
|
+
"question": "\\start",
|
|
47
|
+
"intent_display_name": "start",
|
|
48
|
+
"language": "en",
|
|
49
|
+
"intent_id": "550a5f10-f161-43d1-a308-97576797d54d"
|
|
50
|
+
}, {
|
|
51
|
+
"webhook_enabled": false,
|
|
52
|
+
"enabled": true,
|
|
53
|
+
"actions": [{
|
|
54
|
+
"_tdActionType": "reply",
|
|
55
|
+
"text": "I didn't understand. Can you rephrase your question?",
|
|
56
|
+
"attributes": {
|
|
57
|
+
"commands": [{
|
|
58
|
+
"type": "message",
|
|
59
|
+
"message": {
|
|
60
|
+
"type": "text",
|
|
61
|
+
"text": "I didn't understand. Can you rephrase your question?"
|
|
62
|
+
}
|
|
63
|
+
}]
|
|
64
|
+
}
|
|
65
|
+
}],
|
|
66
|
+
"question": "defaultFallback",
|
|
67
|
+
"intent_display_name": "defaultFallback",
|
|
68
|
+
"language": "en",
|
|
69
|
+
"intent_id": "543f9b38-376a-447b-ba9c-dda4cae91cd9"
|
|
70
|
+
}, {
|
|
71
|
+
"webhook_enabled": false,
|
|
72
|
+
"enabled": true,
|
|
73
|
+
"actions": [{
|
|
74
|
+
"_tdActionTitle": "star_type === supernova",
|
|
75
|
+
"_tdActionType": "jsoncondition",
|
|
76
|
+
"groups": [{
|
|
77
|
+
"type": "expression",
|
|
78
|
+
"conditions": [{
|
|
79
|
+
"type": "condition",
|
|
80
|
+
"operand1": "star_type",
|
|
81
|
+
"operator": "equalAsStrings",
|
|
82
|
+
"operand2": {
|
|
83
|
+
"type": "const",
|
|
84
|
+
"value": "supernova",
|
|
85
|
+
"name": ""
|
|
86
|
+
}
|
|
87
|
+
}]
|
|
88
|
+
}],
|
|
89
|
+
"stopOnConditionMet": false,
|
|
90
|
+
"trueIntent": "#1ccbf281-ea62-4567-a481-c1cc48266168",
|
|
91
|
+
"falseIntent": "#1ccbf281-ea62-4567-a481-c1cc48266168",
|
|
92
|
+
"trueIntentAttributes": {
|
|
93
|
+
"my_name": "supernova",
|
|
94
|
+
"size": "2B"
|
|
95
|
+
},
|
|
96
|
+
"falseIntentAttributes": {
|
|
97
|
+
"my_name": "nebula",
|
|
98
|
+
"size": "500k"
|
|
99
|
+
}
|
|
100
|
+
}],
|
|
101
|
+
"language": "en",
|
|
102
|
+
"intent_display_name": "condition with params",
|
|
103
|
+
"intent_id": "e538b93d-47e7-4888-8f23-e10f878ac901"
|
|
104
|
+
}, {
|
|
105
|
+
"webhook_enabled": false,
|
|
106
|
+
"enabled": true,
|
|
107
|
+
"actions": [{
|
|
108
|
+
"_tdActionTitle": null,
|
|
109
|
+
"_tdActionType": "setattribute",
|
|
110
|
+
"expression": "?",
|
|
111
|
+
"assignTo": "star_type"
|
|
112
|
+
}],
|
|
113
|
+
"language": "en",
|
|
114
|
+
"intent_display_name": "variables declaration",
|
|
115
|
+
"intent_id": "f629c3ab-b317-486d-802f-e7e458a4c839"
|
|
116
|
+
}, {
|
|
117
|
+
"webhook_enabled": false,
|
|
118
|
+
"enabled": true,
|
|
119
|
+
"actions": [{
|
|
120
|
+
"_tdActionTitle": null,
|
|
121
|
+
"_tdActionType": "reply",
|
|
122
|
+
"attributes": {
|
|
123
|
+
"disableInputMessage": false,
|
|
124
|
+
"commands": [{
|
|
125
|
+
"type": "wait",
|
|
126
|
+
"time": 500
|
|
127
|
+
}, {
|
|
128
|
+
"type": "message",
|
|
129
|
+
"message": {
|
|
130
|
+
"type": "text",
|
|
131
|
+
"text": "My name is ${my_name} and I'm ${size} km large"
|
|
132
|
+
}
|
|
133
|
+
}]
|
|
134
|
+
},
|
|
135
|
+
"text": "My name is ${my_name} and I'm ${size} km large\r\n"
|
|
136
|
+
}],
|
|
137
|
+
"language": "en",
|
|
138
|
+
"intent_display_name": "result",
|
|
139
|
+
"intent_id": "1ccbf281-ea62-4567-a481-c1cc48266168"
|
|
140
|
+
}]
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// normalize the bot structure for the static intent search
|
|
144
|
+
let intents = bot.intents;
|
|
145
|
+
delete bot.intents;
|
|
146
|
+
// console.log ("bot still is", JSON.stringify(bot));
|
|
147
|
+
// console.log ("bintents still are", intents[0]);
|
|
148
|
+
intent_dict = {};
|
|
149
|
+
for (let i = 0; i < intents.length; i++) {
|
|
150
|
+
intent_dict[intents[i].intent_display_name] = intents[i];
|
|
151
|
+
intent_dict["#" + intents[i].intent_id] = intents[i];
|
|
152
|
+
}
|
|
153
|
+
bot.intents = intent_dict;
|
|
154
|
+
const bots_data = {
|
|
155
|
+
"bots": {}
|
|
156
|
+
}
|
|
157
|
+
bots_data.bots["botID"] = bot;
|
|
158
|
+
|
|
159
|
+
module.exports = { bots_data: bots_data };
|
|
@@ -83,7 +83,7 @@ describe('Conversation for JSONCondition test', async () => {
|
|
|
83
83
|
assert(command1.type === "message");
|
|
84
84
|
assert(command1.message.text === "var1: Application var");
|
|
85
85
|
assert(command3.type === "message");
|
|
86
|
-
console.log("command3.message.text", command3.message.text)
|
|
86
|
+
// console.log("command3.message.text", command3.message.text)
|
|
87
87
|
assert(command3.message.text === "service_reply: Your name is Andrea");
|
|
88
88
|
getChatbotParameters(REQUEST_ID, (err, params) => {
|
|
89
89
|
if (err) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { TiledeskChatbotUtil } = require('@tiledesk/tiledesk-chatbot-util');
|
|
2
2
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
3
3
|
const { DirDeflectToHelpCenter } = require('./directives/DirDeflectToHelpCenter');
|
|
4
|
-
const { DirOfflineHours } = require('./directives/DirOfflineHours'); // DEPRECATED
|
|
4
|
+
// const { DirOfflineHours } = require('./directives/DirOfflineHours'); // DEPRECATED
|
|
5
5
|
const { DirMoveToAgent } = require('./directives/DirMoveToAgent');
|
|
6
6
|
const { DirMessage } = require('./directives/DirMessage');
|
|
7
7
|
const { DirWait } = require('./directives/DirWait');
|
|
@@ -11,10 +11,10 @@ const { DirLockIntent } = require('./directives/DirLockIntent');
|
|
|
11
11
|
const { DirUnlockIntent } = require('./directives/DirUnlockIntent');
|
|
12
12
|
const { DirDepartment } = require('./directives/DirDepartment');
|
|
13
13
|
const { DirIntent } = require('./directives/DirIntent');
|
|
14
|
-
const { DirWhenOpen } = require('./directives/DirWhenOpen'); // DEPRECATED
|
|
14
|
+
// const { DirWhenOpen } = require('./directives/DirWhenOpen'); // DEPRECATED
|
|
15
15
|
const { DirDisableInputText } = require('./directives/DirDisableInputText');
|
|
16
16
|
const { DirClose } = require('./directives/DirClose');
|
|
17
|
-
const { DirIfAvailableAgents } = require('./directives/DirIfAvailableAgents'); // DEPRECATED
|
|
17
|
+
// const { DirIfAvailableAgents } = require('./directives/DirIfAvailableAgents'); // DEPRECATED
|
|
18
18
|
const { DirFireTiledeskEvent } = require('./directives/DirFireTiledeskEvent');
|
|
19
19
|
const { DirSendEmail } = require('./directives/DirSendEmail');
|
|
20
20
|
const { Directives } = require('./directives/Directives');
|
|
@@ -49,6 +49,7 @@ class DirectivesChatbotPlug {
|
|
|
49
49
|
this.HELP_CENTER_API_ENDPOINT = config.HELP_CENTER_API_ENDPOINT;
|
|
50
50
|
this.tdcache = config.cache;
|
|
51
51
|
this.directives = config.directives;
|
|
52
|
+
console.log("We have the support request:", JSON.stringify(this.supportRequest))
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
exec(pipeline) {
|
|
@@ -96,6 +97,8 @@ class DirectivesChatbotPlug {
|
|
|
96
97
|
return;
|
|
97
98
|
}
|
|
98
99
|
const supportRequest = this.supportRequest;
|
|
100
|
+
console.log("supportRequest is:", JSON.stringify(supportRequest))
|
|
101
|
+
|
|
99
102
|
const token = this.token;
|
|
100
103
|
const API_URL = this.API_URL;
|
|
101
104
|
const TILEBOT_ENDPOINT = this.TILEBOT_ENDPOINT;
|
|
@@ -103,7 +106,9 @@ class DirectivesChatbotPlug {
|
|
|
103
106
|
// const requestId = supportRequest.request_id
|
|
104
107
|
let depId;
|
|
105
108
|
if (supportRequest.department && supportRequest.department._id) {
|
|
109
|
+
if (this.log) {console.log("setting depId:", supportRequest.department._id);}
|
|
106
110
|
depId = supportRequest.department._id;
|
|
111
|
+
if (this.log) {console.log("depId is:", depId);}
|
|
107
112
|
}
|
|
108
113
|
const projectId = supportRequest.id_project;
|
|
109
114
|
const tdcache = this.tdcache;
|
|
@@ -127,6 +132,7 @@ class DirectivesChatbotPlug {
|
|
|
127
132
|
tdclient: tdclient,
|
|
128
133
|
log: this.log
|
|
129
134
|
}
|
|
135
|
+
if (this.log) {console.log("this.context.departmentId is:", this.context.departmentId);}
|
|
130
136
|
|
|
131
137
|
this.curr_directive_index = -1;
|
|
132
138
|
if (this.log) { console.log("processing directives...");}
|
|
@@ -257,9 +263,18 @@ class DirectivesChatbotPlug {
|
|
|
257
263
|
});
|
|
258
264
|
}
|
|
259
265
|
else if (directive_name === Directives.IF_ONLINE_AGENTS) {
|
|
266
|
+
// console.log("...DirIfOnlineAgents")
|
|
260
267
|
new DirIfOnlineAgents(context).execute(directive, async () => {
|
|
261
|
-
|
|
262
|
-
|
|
268
|
+
if (stop) {
|
|
269
|
+
if (context.log) { console.log("Stopping Actions on:", directive);}
|
|
270
|
+
this.theend();
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
274
|
+
this.process(next_dir);
|
|
275
|
+
}
|
|
276
|
+
// let next_dir = await this.nextDirective(this.directives);
|
|
277
|
+
// this.process(next_dir);
|
|
263
278
|
});
|
|
264
279
|
}
|
|
265
280
|
else if (directive_name === Directives.FUNCTION_VALUE) {
|
|
@@ -311,57 +326,57 @@ class DirectivesChatbotPlug {
|
|
|
311
326
|
this.process(next_dir);
|
|
312
327
|
});
|
|
313
328
|
}
|
|
314
|
-
else if (directive_name === Directives.WHEN_OPEN) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
else if (directive_name === Directives.WHEN_CLOSED) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
else if (directive_name === Directives.IF_AGENTS) {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
else if (directive_name === Directives.IF_NO_AGENTS) {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
}
|
|
329
|
+
// else if (directive_name === Directives.WHEN_OPEN) {
|
|
330
|
+
// // DEPRECATED
|
|
331
|
+
// const whenOpenDir = new DirWhenOpen(
|
|
332
|
+
// {
|
|
333
|
+
// tdclient: this.context.tdclient, // matches open hours
|
|
334
|
+
// log: false
|
|
335
|
+
// });
|
|
336
|
+
// whenOpenDir.execute(directive, directives, curr_directive_index, async () => {
|
|
337
|
+
// let next_dir = await this.nextDirective(this.directives);
|
|
338
|
+
// this.process(next_dir);
|
|
339
|
+
// });
|
|
340
|
+
// }
|
|
341
|
+
// else if (directive_name === Directives.WHEN_CLOSED) {
|
|
342
|
+
// // DEPRECATED
|
|
343
|
+
// const whenOpenDir = new DirWhenOpen(
|
|
344
|
+
// {
|
|
345
|
+
// tdclient: this.context.tdclient,
|
|
346
|
+
// checkOpen: false, // matches closed hours
|
|
347
|
+
// log: false
|
|
348
|
+
// });
|
|
349
|
+
// whenOpenDir.execute(directive, directives, curr_directive_index, async () => {
|
|
350
|
+
// let next_dir = await this.nextDirective(this.directives);
|
|
351
|
+
// this.process(next_dir);
|
|
352
|
+
// });
|
|
353
|
+
// }
|
|
354
|
+
// else if (directive_name === Directives.IF_AGENTS) {
|
|
355
|
+
// // DEPRECATED
|
|
356
|
+
// const ifNoAgentsDir = new DirIfAvailableAgents(
|
|
357
|
+
// {
|
|
358
|
+
// tdclient: this.context.tdclient,
|
|
359
|
+
// checkAgents: true, // check available agents > 0
|
|
360
|
+
// log: false
|
|
361
|
+
// });
|
|
362
|
+
// ifNoAgentsDir.execute(directive, directives, curr_directive_index, async () => {
|
|
363
|
+
// let next_dir = await this.nextDirective(this.directives);
|
|
364
|
+
// this.process(next_dir);
|
|
365
|
+
// });
|
|
366
|
+
// }
|
|
367
|
+
// else if (directive_name === Directives.IF_NO_AGENTS) {
|
|
368
|
+
// // DEPRECATED
|
|
369
|
+
// const ifNoAgentsDir = new DirIfAvailableAgents(
|
|
370
|
+
// {
|
|
371
|
+
// tdclient: this.context.tdclient,
|
|
372
|
+
// checkAgents: false, // check no available agents
|
|
373
|
+
// log: false
|
|
374
|
+
// });
|
|
375
|
+
// ifNoAgentsDir.execute(directive, directives, curr_directive_index, async () => {
|
|
376
|
+
// let next_dir = await this.nextDirective(this.directives);
|
|
377
|
+
// this.process(next_dir);
|
|
378
|
+
// });
|
|
379
|
+
// }
|
|
365
380
|
else if (directive_name === Directives.AGENT) {
|
|
366
381
|
console.log("...DirMoveToAgent");
|
|
367
382
|
new DirMoveToAgent(context).execute(directive, async () => {
|
|
@@ -369,35 +384,35 @@ class DirectivesChatbotPlug {
|
|
|
369
384
|
this.process(next_dir);
|
|
370
385
|
});
|
|
371
386
|
}
|
|
372
|
-
else if (directive_name === Directives.WHEN_ONLINE_MOVE_TO_AGENT) { // DEPRECATED?
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
}
|
|
387
|
+
// else if (directive_name === Directives.WHEN_ONLINE_MOVE_TO_AGENT) { // DEPRECATED?
|
|
388
|
+
// // let depId;
|
|
389
|
+
// // if (context.supportRequest && context.supportRequest.department && context.supportRequest.department._id) {
|
|
390
|
+
// // depId = context.supportRequest.department._id;
|
|
391
|
+
// // console.log("context.supportRequest", JSON.stringify(context.supportRequest));
|
|
392
|
+
// // const agentDir = new DirMoveToAgent(
|
|
393
|
+
// // {
|
|
394
|
+
// // tdclient: context.tdclient,
|
|
395
|
+
// // requestId: context.requestId,
|
|
396
|
+
// // depId: depId
|
|
397
|
+
// // }
|
|
398
|
+
// // );
|
|
399
|
+
// // if (!directive.action) {
|
|
400
|
+
// // directive.action = {}
|
|
401
|
+
// // directive.action = {
|
|
402
|
+
// // whenOnlineOnly: true
|
|
403
|
+
// // }
|
|
404
|
+
// // }
|
|
405
|
+
// new DirMoveToAgent(context).execute(directive, async () => {
|
|
406
|
+
// let next_dir = await this.nextDirective(this.directives);
|
|
407
|
+
// this.process(next_dir);
|
|
408
|
+
// });
|
|
409
|
+
// // }
|
|
410
|
+
// // else {
|
|
411
|
+
// // console.log("Warning. DepId null while calling 'WHEN_ONLINE_MOVE_TO_AGENT' directive")
|
|
412
|
+
// // let next_dir = await this.nextDirective(this.directives);
|
|
413
|
+
// // this.process(next_dir);
|
|
414
|
+
// // }
|
|
415
|
+
// }
|
|
401
416
|
else if (directive_name === Directives.CLOSE) {
|
|
402
417
|
// console.log("Exec close()")
|
|
403
418
|
new DirClose(context).execute(directive, async () => {
|
|
@@ -450,7 +465,7 @@ class DirectivesChatbotPlug {
|
|
|
450
465
|
});
|
|
451
466
|
}
|
|
452
467
|
else if (directive_name === Directives.WEB_REQUEST) {
|
|
453
|
-
console.log("...DirWebRequest");
|
|
468
|
+
// console.log("...DirWebRequest");
|
|
454
469
|
new DirWebRequest(context).execute(directive, async () => {
|
|
455
470
|
let next_dir = await this.nextDirective(this.directives);
|
|
456
471
|
this.process(next_dir);
|
|
@@ -505,18 +520,18 @@ class DirectivesChatbotPlug {
|
|
|
505
520
|
if (directive == null) {
|
|
506
521
|
theend();
|
|
507
522
|
}
|
|
508
|
-
else if (directive_name === Directives.WHEN_OFFLINE_HOURS) { // DEPRECATED
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
}
|
|
514
|
-
else if (directive_name === Directives.DISABLE_INPUT_TEXT) { // DEPRECATED => will change in a "message-option" --disableInput
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
}
|
|
523
|
+
// else if (directive_name === Directives.WHEN_OFFLINE_HOURS) { // DEPRECATED
|
|
524
|
+
// const offlineHoursDir = new DirOfflineHours(tdclient);
|
|
525
|
+
// offlineHoursDir.execute(directive, pipeline, () => {
|
|
526
|
+
// process(nextDirective());
|
|
527
|
+
// });
|
|
528
|
+
// }
|
|
529
|
+
// else if (directive_name === Directives.DISABLE_INPUT_TEXT) { // DEPRECATED => will change in a "message-option" --disableInput
|
|
530
|
+
// const disableInputTextDir = new DirDisableInputText();
|
|
531
|
+
// disableInputTextDir.execute(directive, pipeline, () => {
|
|
532
|
+
// process(nextDirective());
|
|
533
|
+
// });
|
|
534
|
+
// }
|
|
520
535
|
else if (directive_name === Directives.DEFLECT_TO_HELP_CENTER) {
|
|
521
536
|
const helpDir = new DirDeflectToHelpCenter({HELP_CENTER_API_ENDPOINT: this.HELP_CENTER_API_ENDPOINT, projectId: projectId});
|
|
522
537
|
helpDir.execute(directive, pipeline, 3, () => {
|
|
@@ -34,7 +34,7 @@ class SplitsChatbotPlug {
|
|
|
34
34
|
// to the original json message with split commands
|
|
35
35
|
let commands = TiledeskChatbotUtil.splitPars(message.text);
|
|
36
36
|
if (this.log) {
|
|
37
|
-
console.log("commands", commands)
|
|
37
|
+
console.log("commands", JSON.stringify(commands))
|
|
38
38
|
}
|
|
39
39
|
if (commands && commands.length > 1) {
|
|
40
40
|
if (!message.attributes) {
|
|
@@ -21,9 +21,9 @@ class WebhookChatbotPlug {
|
|
|
21
21
|
if (this.log) {console.log("WEBHOOK?", answer.attributes.webhook);}
|
|
22
22
|
if (answer.attributes && answer.attributes.webhook && answer.attributes.webhook === true) {
|
|
23
23
|
if (this.log) {console.log("EXECUTING WEBHOOK URL!", this.webhookurl);}
|
|
24
|
-
if (this.log) {console.log("EXECUTING WEBHOOK ON CONTEXT:", context);}
|
|
24
|
+
if (this.log) {console.log("EXECUTING WEBHOOK ON CONTEXT:", JSON.stringify(context));}
|
|
25
25
|
this.execWebhook(answer, context, this.webhookurl, (err, message_from_webhook) => {
|
|
26
|
-
if (this.log) {console.log("
|
|
26
|
+
if (this.log) {console.log("message_from_webhook:", message_from_webhook);}
|
|
27
27
|
if (err) {
|
|
28
28
|
console.error("Error calling webhook:", this.webhookurl)
|
|
29
29
|
pipeline.nextplug();
|
|
@@ -31,7 +31,7 @@ class WebhookChatbotPlug {
|
|
|
31
31
|
else {
|
|
32
32
|
if (this.log) {console.log("Webhook successfully end:", message_from_webhook);}
|
|
33
33
|
const pipeline_original_message = pipeline.message
|
|
34
|
-
if (this.log) {console.log("pipeline.message before webhook", pipeline.message);}
|
|
34
|
+
if (this.log) {console.log("pipeline.message before webhook", JSON.stringify(pipeline.message));}
|
|
35
35
|
|
|
36
36
|
// **** setting message from webhook,
|
|
37
37
|
// **** MERGING with original not overwritten data, manually
|
|
@@ -69,8 +69,8 @@ class WebhookChatbotPlug {
|
|
|
69
69
|
|
|
70
70
|
execWebhook(reply_message, context, webhookurl, callback) {
|
|
71
71
|
if (this.log) {
|
|
72
|
-
console.log("WEBHOOK. on context", context)
|
|
73
|
-
console.log("WEBHOOK. on message", reply_message)
|
|
72
|
+
console.log("WEBHOOK. on context", JSON.stringify(context));
|
|
73
|
+
console.log("WEBHOOK. on message", JSON.stringify(reply_message));
|
|
74
74
|
}
|
|
75
75
|
const HTTPREQUEST = {
|
|
76
76
|
url: webhookurl,
|
|
@@ -186,8 +186,8 @@ class WebhookChatbotPlug {
|
|
|
186
186
|
if (log) {
|
|
187
187
|
console.log("Response for url:", options.url);
|
|
188
188
|
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
189
|
-
console.log("******** Response for url:", res);
|
|
190
|
-
console.log("Response body:\n", res.data);
|
|
189
|
+
// console.log("******** Response for url:", JSON.stringify(res));
|
|
190
|
+
console.log("Response body:\n", JSON.stringify(res.data));
|
|
191
191
|
}
|
|
192
192
|
if (callback) {
|
|
193
193
|
callback(null, res);
|
|
@@ -49,7 +49,7 @@ class DirDepartment {
|
|
|
49
49
|
|
|
50
50
|
moveToDepartment(requestId, depName, callback) {
|
|
51
51
|
this.tdclient.getAllDepartments((err, deps) => {
|
|
52
|
-
if (this.log) {console.log("deps:", deps
|
|
52
|
+
if (this.log) {console.log("deps:", deps);}
|
|
53
53
|
if (err) {
|
|
54
54
|
console.error("getAllDepartments() error:", err);
|
|
55
55
|
callback();
|
|
@@ -61,8 +61,8 @@ class DirIfOnlineAgents {
|
|
|
61
61
|
callback();
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
|
-
this.go(action, () => {
|
|
65
|
-
callback();
|
|
64
|
+
this.go(action, (stop) => {
|
|
65
|
+
callback(stop);
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -76,6 +76,9 @@ class DirIfOnlineAgents {
|
|
|
76
76
|
}
|
|
77
77
|
const trueIntent = action.trueIntent;
|
|
78
78
|
const falseIntent = action.falseIntent;
|
|
79
|
+
const trueIntentAttributes = action.trueIntentAttributes;
|
|
80
|
+
const falseIntentAttributes = action.falseIntentAttributes;
|
|
81
|
+
let stopOnConditionMet = action.stopOnConditionMet;
|
|
79
82
|
this.tdclient.openNow((err, result) => {
|
|
80
83
|
if (this.log) {console.log("openNow():", result);}
|
|
81
84
|
if (err) {
|
|
@@ -95,10 +98,10 @@ class DirIfOnlineAgents {
|
|
|
95
98
|
if (this.log) {console.log("Agents count:", agents.length);}
|
|
96
99
|
if (agents.length > 0) {
|
|
97
100
|
if (trueIntent) {
|
|
98
|
-
let intentDirective = DirIntent.intentDirectiveFor(trueIntent);
|
|
101
|
+
let intentDirective = DirIntent.intentDirectiveFor(trueIntent, trueIntentAttributes);
|
|
99
102
|
if (this.log) {console.log("agents (openHours) => trueIntent");}
|
|
100
103
|
this.intentDir.execute(intentDirective, () => {
|
|
101
|
-
callback();
|
|
104
|
+
callback(stopOnConditionMet);
|
|
102
105
|
});
|
|
103
106
|
}
|
|
104
107
|
else {
|
|
@@ -107,10 +110,10 @@ class DirIfOnlineAgents {
|
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
112
|
else if (falseIntent) {
|
|
110
|
-
let intentDirective = DirIntent.intentDirectiveFor(falseIntent);
|
|
113
|
+
let intentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
|
|
111
114
|
if (this.log) {console.log("!agents (openHours) => falseIntent", falseIntent);}
|
|
112
115
|
this.intentDir.execute(intentDirective, () => {
|
|
113
|
-
callback();
|
|
116
|
+
callback(stopOnConditionMet);
|
|
114
117
|
});
|
|
115
118
|
}
|
|
116
119
|
else {
|
|
@@ -121,7 +124,7 @@ class DirIfOnlineAgents {
|
|
|
121
124
|
}
|
|
122
125
|
else if (result && !result.isopen) {
|
|
123
126
|
if (falseIntent) {
|
|
124
|
-
let intentDirective = DirIntent.intentDirectiveFor(falseIntent);
|
|
127
|
+
let intentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
|
|
125
128
|
if (this.log) {console.log("!agents (!openHours) => falseIntent");}
|
|
126
129
|
this.intentDir.execute(intentDirective, () => {
|
|
127
130
|
callback();
|
|
@@ -139,17 +142,6 @@ class DirIfOnlineAgents {
|
|
|
139
142
|
});
|
|
140
143
|
}
|
|
141
144
|
|
|
142
|
-
// intentDirectiveFor(intent) {
|
|
143
|
-
// let intentDirective = {
|
|
144
|
-
// action: {
|
|
145
|
-
// body: {
|
|
146
|
-
// intentName: intent
|
|
147
|
-
// }
|
|
148
|
-
// }
|
|
149
|
-
// }
|
|
150
|
-
// return intentDirective;
|
|
151
|
-
// }
|
|
152
|
-
|
|
153
145
|
parseParams(directive_parameter) {
|
|
154
146
|
let trueIntent = null;
|
|
155
147
|
let falseIntent = null;
|
|
@@ -67,8 +67,10 @@ class DirIfOpenHours {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
go(action, callback) {
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
const trueIntent = action.trueIntent;
|
|
71
|
+
const falseIntent = action.falseIntent;
|
|
72
|
+
const trueIntentAttributes = action.trueIntentAttributes;
|
|
73
|
+
const falseIntentAttributes = action.falseIntentAttributes;
|
|
72
74
|
const stopOnConditionMet = action.stopOnConditionMet;
|
|
73
75
|
if (trueIntent && trueIntent.trim() === "") {
|
|
74
76
|
trueIntent = null;
|
|
@@ -118,7 +118,29 @@ class DirIntent {
|
|
|
118
118
|
// }
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
static intentDirectiveFor(intent) {
|
|
121
|
+
static intentDirectiveFor(intent, json_params) {
|
|
122
|
+
let string_params = null;
|
|
123
|
+
if (json_params) {
|
|
124
|
+
try {
|
|
125
|
+
string_params = JSON.stringify(json_params);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.error("Error stringigying JSON PARAMS", json_params);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (string_params != null) {
|
|
132
|
+
intent += string_params
|
|
133
|
+
}
|
|
134
|
+
let intentDirective = {
|
|
135
|
+
action: {
|
|
136
|
+
intentName: intent
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return intentDirective;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
static fullIntentDirectiveFor(intent, json_params) {
|
|
143
|
+
let string_params = JSON.stringify(params);
|
|
122
144
|
let intentDirective = {
|
|
123
145
|
action: {
|
|
124
146
|
intentName: intent
|
|
@@ -56,10 +56,12 @@ class DirJSONCondition {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
async go(action, callback) {
|
|
59
|
-
const groups = action.jsonCondition.groups;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
// const groups = action.jsonCondition.groups;
|
|
60
|
+
const groups = action.groups; // NEXT
|
|
61
|
+
const trueIntent = action.trueIntent;
|
|
62
|
+
const falseIntent = action.falseIntent;
|
|
63
|
+
const trueIntentAttributes = action.trueIntentAttributes;
|
|
64
|
+
const falseIntentAttributes = action.falseIntentAttributes;
|
|
63
65
|
let stopOnConditionMet = action.stopOnConditionMet;
|
|
64
66
|
if (this.log) {console.log("groups:", JSON.stringify(groups));}
|
|
65
67
|
if (trueIntent && trueIntent.trim() === "") {
|
|
@@ -80,11 +82,11 @@ class DirJSONCondition {
|
|
|
80
82
|
}
|
|
81
83
|
let trueIntentDirective = null;
|
|
82
84
|
if (trueIntent) {
|
|
83
|
-
trueIntentDirective = DirIntent.intentDirectiveFor(trueIntent);
|
|
85
|
+
trueIntentDirective = DirIntent.intentDirectiveFor(trueIntent, trueIntentAttributes);
|
|
84
86
|
}
|
|
85
87
|
let falseIntentDirective = null;
|
|
86
88
|
if (falseIntent) {
|
|
87
|
-
falseIntentDirective = DirIntent.intentDirectiveFor(falseIntent);
|
|
89
|
+
falseIntentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
|
|
88
90
|
}
|
|
89
91
|
let variables = null;
|
|
90
92
|
if (this.context.tdcache) {
|
|
@@ -48,6 +48,20 @@ class DirMoveToAgent {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
async go(action, callback) {
|
|
51
|
+
let depId = null;
|
|
52
|
+
if (this.log) {console.log("DirMoveToAgent this.context.departmentId:", this.context.departmentId);}
|
|
53
|
+
if (this.context.departmentId) {
|
|
54
|
+
depId = this.context.departmentId
|
|
55
|
+
if (this.log) {console.log("DirMoveToAgent depId:", depId);}
|
|
56
|
+
}
|
|
57
|
+
else if (this.tdcache) {
|
|
58
|
+
depId =
|
|
59
|
+
await TiledeskChatbot.getParameterStatic(
|
|
60
|
+
this.tdcache, this.requestId, TiledeskChatbotConst.REQ_DEPARTMENT_ID_KEY
|
|
61
|
+
);
|
|
62
|
+
if (this.log) {console.log("DirMoveToAgent depId (cache):", depId);}
|
|
63
|
+
}
|
|
64
|
+
if (this.log) {console.log("DirMoveToAgent anyway depId is:", depId);}
|
|
51
65
|
if (action.whenOnlineOnly === true) {
|
|
52
66
|
this.tdclient.openNow( async (err, result) => {
|
|
53
67
|
if (err) {
|
|
@@ -56,11 +70,7 @@ class DirMoveToAgent {
|
|
|
56
70
|
}
|
|
57
71
|
else {
|
|
58
72
|
if (result && result.isopen) {
|
|
59
|
-
if (
|
|
60
|
-
depId =
|
|
61
|
-
await TiledeskChatbot.getParameterStatic(
|
|
62
|
-
this.tdcache, this.requestId, TiledeskChatbotConst.REQ_DEPARTMENT_ID_KEY
|
|
63
|
-
);
|
|
73
|
+
if (depId) {
|
|
64
74
|
this.tdclient.agent(this.requestId, depId, (err) => {
|
|
65
75
|
if (err) {
|
|
66
76
|
console.error("Error moving to agent during online hours:", err);
|
|
@@ -82,24 +92,29 @@ class DirMoveToAgent {
|
|
|
82
92
|
});
|
|
83
93
|
}
|
|
84
94
|
else {
|
|
85
|
-
if (this.tdcache) {
|
|
86
|
-
const depId =
|
|
87
|
-
await TiledeskChatbot.getParameterStatic(
|
|
88
|
-
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
// if (this.tdcache) {
|
|
96
|
+
// const depId =
|
|
97
|
+
// await TiledeskChatbot.getParameterStatic(
|
|
98
|
+
// this.tdcache, this.requestId, TiledeskChatbotConst.REQ_DEPARTMENT_ID_KEY
|
|
99
|
+
// );
|
|
100
|
+
if (depId) {
|
|
101
|
+
this.tdclient.agent(this.requestId, depId, (err) => {
|
|
102
|
+
if (err) {
|
|
103
|
+
console.error("Error moving to agent:", err);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
//console.log("Successfully moved to agent");
|
|
107
|
+
}
|
|
108
|
+
callback();
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
97
112
|
callback();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
|
|
102
|
-
}
|
|
113
|
+
}
|
|
114
|
+
// }
|
|
115
|
+
// else {
|
|
116
|
+
// callback();
|
|
117
|
+
// }
|
|
103
118
|
}
|
|
104
119
|
}
|
|
105
120
|
|
|
File without changes
|