@tiledesk/tiledesk-tybot-connector 0.1.51 → 0.1.52
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 +7 -0
- package/TdCache.js +20 -0
- package/index.js +19 -14
- package/models/MongodbBotsDataSource.js +2 -1
- package/models/TiledeskChatbot.js +6 -0
- package/models/TiledeskChatbotConst.js +20 -0
- package/models/TiledeskChatbotUtil.js +4 -4
- package/package.json +1 -1
- package/test/conversation-actions-test.js +2 -2
- package/test/conversation-form-test.js +8 -8
- package/test/conversation-form_bot.js +2 -2
- package/test/filter_commands_test.js +1 -1
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +11 -3
- package/tiledeskChatbotPlugs/directives/DirCondition.js +4 -2
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirIntent.js +43 -59
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +41 -20
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
available on:
|
|
6
6
|
▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
|
|
7
7
|
|
|
8
|
+
### 0.1.52
|
|
9
|
+
- added tdChatbotName to request variables
|
|
10
|
+
- removed _ from _td prefix in tiledeskVariables (i.e. _tdDepartmentId => tdDepartmentId)
|
|
11
|
+
- added tdcache.hget()
|
|
12
|
+
- fixed bug on DirAgentHandoff. this.dirId missed on intent-to-intent crashed the application. Getting tdDepartmentId from Redis
|
|
13
|
+
- removed projectId from query getByIntentDisplayName(botId)
|
|
14
|
+
|
|
8
15
|
### 0.1.51
|
|
9
16
|
- only debug on pre
|
|
10
17
|
|
package/TdCache.js
CHANGED
|
@@ -198,6 +198,26 @@ class TdCache {
|
|
|
198
198
|
});
|
|
199
199
|
});
|
|
200
200
|
}
|
|
201
|
+
|
|
202
|
+
async hget(dict_key, key, callback) {
|
|
203
|
+
//console.log("hgetting dics", dict_key);
|
|
204
|
+
return new Promise( async (resolve, reject) => {
|
|
205
|
+
this.client.hget(dict_key, key, (err, value) => {
|
|
206
|
+
if (err) {
|
|
207
|
+
reject(err);
|
|
208
|
+
if (callback) {
|
|
209
|
+
callback(err, null);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
if (callback) {
|
|
214
|
+
callback(null, value);
|
|
215
|
+
}
|
|
216
|
+
resolve(value);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
}
|
|
201
221
|
|
|
202
222
|
async getJSON(key, callback) {
|
|
203
223
|
const value = await this.get(key);
|
package/index.js
CHANGED
|
@@ -18,6 +18,7 @@ const { MongodbIntentsMachine } = require('./models/MongodbIntentsMachine.js');
|
|
|
18
18
|
const { TiledeskIntentsMachine } = require('./models/TiledeskIntentsMachine.js');
|
|
19
19
|
// const { MockActions } = require('./MockActions');
|
|
20
20
|
const { MockBotsDataSource } = require('./models/MockBotsDataSource.js');
|
|
21
|
+
const { TiledeskChatbotConst } = require('./models/TiledeskChatbotConst');
|
|
21
22
|
|
|
22
23
|
//router.use(cors());
|
|
23
24
|
router.use(bodyParser.json({limit: '50mb'}));
|
|
@@ -200,29 +201,33 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
200
201
|
async function updateRequestVariables(chatbot, message, projectId, requestId) {
|
|
201
202
|
// update request context
|
|
202
203
|
const messageId = message._id;
|
|
203
|
-
await chatbot.addParameter(
|
|
204
|
-
|
|
204
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_PROJECT_ID_KEY, projectId);
|
|
205
|
+
// TODO add projectName too
|
|
206
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_REQUEST_ID_KEY, requestId);
|
|
207
|
+
if (chatbot.bot) {
|
|
208
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_NAME_KEY, chatbot.bot.name);
|
|
209
|
+
}
|
|
205
210
|
if (message.text) {
|
|
206
|
-
await chatbot.addParameter(
|
|
211
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_TEXT_KEY, message.text);
|
|
207
212
|
}
|
|
208
|
-
await chatbot.addParameter(
|
|
213
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_MESSAGE_ID_KEY, messageId);
|
|
209
214
|
if (message.request && message.request.location && message.request.location.country) {
|
|
210
|
-
await chatbot.addParameter(
|
|
215
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_COUNTRY_KEY, message.request.location.country);
|
|
211
216
|
}
|
|
212
217
|
if (message.request && message.request.location && message.request.location.city) {
|
|
213
|
-
await chatbot.addParameter(
|
|
218
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_CITY_KEY, message.request.location.city);
|
|
214
219
|
}
|
|
215
220
|
// console.log("message.request.language", message.request["language"])
|
|
216
221
|
if (message.request) {
|
|
217
|
-
await chatbot.addParameter(
|
|
218
|
-
await chatbot.addParameter(
|
|
219
|
-
await chatbot.addParameter(
|
|
222
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_SOURCE_PAGE_KEY, message.request.sourcePage);
|
|
223
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_LANGUAGE_KEY, message.request["language"]);
|
|
224
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_AGENT_KEY, message.request.userAgent);
|
|
220
225
|
}
|
|
221
226
|
if (message.attributes) {
|
|
222
|
-
await chatbot.addParameter(
|
|
223
|
-
await chatbot.addParameter(
|
|
224
|
-
await chatbot.addParameter(
|
|
225
|
-
await chatbot.addParameter(
|
|
227
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_ID_KEY, message.attributes.departmentId);
|
|
228
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_NAME_KEY, message.attributes.departmentName);
|
|
229
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_ID_KEY, message.attributes.requester_id);
|
|
230
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_IP_ADDRESS_KEY, message.attributes.ipAddress);
|
|
226
231
|
if (message.attributes.payload) {
|
|
227
232
|
try {
|
|
228
233
|
for (const [key, value] of Object.entries(message.attributes.payload)) {
|
|
@@ -420,7 +425,7 @@ router.get('/ext/parameters/requests/:requestid', async (req, res) => {
|
|
|
420
425
|
if (parameters) {
|
|
421
426
|
for (const [key, value] of Object.entries(parameters)) {
|
|
422
427
|
// console.log(key, value);
|
|
423
|
-
if (!key.startsWith("
|
|
428
|
+
if (!key.startsWith("td")) {
|
|
424
429
|
userParams[key] = value;
|
|
425
430
|
}
|
|
426
431
|
}
|
|
@@ -50,7 +50,8 @@ class MongodbBotsDataSource {
|
|
|
50
50
|
*/
|
|
51
51
|
async getByIntentDisplayName(botId, name) {
|
|
52
52
|
return new Promise((resolve, reject) => {
|
|
53
|
-
var query = { "id_project": this.projectId, "id_faq_kb": botId, "intent_display_name": name};
|
|
53
|
+
// var query = { "id_project": this.projectId, "id_faq_kb": botId, "intent_display_name": name};
|
|
54
|
+
var query = { "id_faq_kb": botId, "intent_display_name": name };
|
|
54
55
|
if (this.log) {console.debug('query', query);}
|
|
55
56
|
Faq.find(query).lean().exec( (err, faqs) => {
|
|
56
57
|
if (err) {
|
|
@@ -536,6 +536,12 @@ class TiledeskChatbot {
|
|
|
536
536
|
TiledeskChatbot.requestCacheKey(requestId) + ":parameters");
|
|
537
537
|
}
|
|
538
538
|
|
|
539
|
+
static async getParameterStatic(_tdcache, requestId, key) {
|
|
540
|
+
// const parameters_key = "tilebot:requests:" + requestId + ":parameters";
|
|
541
|
+
return await _tdcache.hget(
|
|
542
|
+
TiledeskChatbot.requestCacheKey(requestId) + ":parameters", key);
|
|
543
|
+
}
|
|
544
|
+
|
|
539
545
|
static async deleteParameterStatic(_tdcache, requestId, paramName) {
|
|
540
546
|
return await _tdcache.hdel(
|
|
541
547
|
TiledeskChatbot.requestCacheKey(requestId) + ":parameters", paramName);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class TiledeskChatbotConst {
|
|
2
|
+
|
|
3
|
+
static REQ_DEPARTMENT_ID_KEY = "tdDepartmentId";
|
|
4
|
+
static REQ_PROJECT_ID_KEY = "tdProjectId";
|
|
5
|
+
static REQ_REQUEST_ID_KEY = "tdRequestId";
|
|
6
|
+
static REQ_CHATBOT_NAME_KEY = "tdChatbotName";
|
|
7
|
+
static REQ_LAST_USER_TEXT_KEY = "tdLastUserText";
|
|
8
|
+
static REQ_LAST_MESSAGE_ID_KEY = "tdLastMessageId";
|
|
9
|
+
static REQ_COUNTRY_KEY = "tdCountry";
|
|
10
|
+
static REQ_CITY_KEY = "tdCity";
|
|
11
|
+
static REQ_USER_SOURCE_PAGE_KEY = "tdUserSourcePage";
|
|
12
|
+
static REQ_USER_LANGUAGE_KEY = "tdUserLanguage";
|
|
13
|
+
static REQ_USER_AGENT_KEY = "tdUserAgent";
|
|
14
|
+
static REQ_DEPARTMENT_NAME_KEY = "tdDepartmentName";
|
|
15
|
+
static REQ_END_USER_ID_KEY = "tdEndUserId";
|
|
16
|
+
static REQ_END_USER_IP_ADDRESS_KEY = "tdEndUserIpAddress";
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = { TiledeskChatbotConst };
|
|
@@ -50,15 +50,15 @@ class TiledeskChatbotUtil {
|
|
|
50
50
|
}
|
|
51
51
|
if (commands.length > 0) {
|
|
52
52
|
for (let i = commands.length - 1; i >= 0; i--) {
|
|
53
|
-
console.log("...commands[" + i + "]");
|
|
53
|
+
// console.log("...commands[" + i + "]");
|
|
54
54
|
if (commands[i].type === "message") { // is a message, not wait
|
|
55
|
-
console.log("commands[i]:", commands[i].message.lang);
|
|
55
|
+
// console.log("commands[i]:", commands[i].message.lang);
|
|
56
56
|
// console.log("commands[i]:", lang, (commands[i].message["lang"] === lang));
|
|
57
57
|
if (commands[i].message["lang"] && !(commands[i].message["lang"] === lang)) { // if there is a filter and the filter is false, remove
|
|
58
|
-
console.log("commands[i]lang:", commands[i]);
|
|
58
|
+
// console.log("commands[i]lang:", commands[i]);
|
|
59
59
|
commands.splice(i, 1);
|
|
60
60
|
if (commands[i-1]) {
|
|
61
|
-
console.log("commands[i-1]?:", commands[i-1]);
|
|
61
|
+
// console.log("commands[i-1]?:", commands[i-1]);
|
|
62
62
|
if (commands[i-1].type === "wait") {
|
|
63
63
|
commands.splice(i-1, 1);
|
|
64
64
|
i--;
|
package/package.json
CHANGED
|
@@ -83,8 +83,8 @@ describe('Conversation for actions test', async () => {
|
|
|
83
83
|
else {
|
|
84
84
|
// console.log("params /start:", params);
|
|
85
85
|
assert(params);
|
|
86
|
-
assert(params["
|
|
87
|
-
assert(params["
|
|
86
|
+
assert(params["tdLastMessageId"] === message_id);
|
|
87
|
+
assert(params["tdProjectId"] === PROJECT_ID);
|
|
88
88
|
listener.close(() => {
|
|
89
89
|
done();
|
|
90
90
|
});
|
|
@@ -105,8 +105,8 @@ describe('Conversation1 - Form filling', async () => {
|
|
|
105
105
|
else {
|
|
106
106
|
// console.log("params /start:", params);
|
|
107
107
|
assert(params);
|
|
108
|
-
assert(params["
|
|
109
|
-
assert(params["
|
|
108
|
+
assert(params["tdLastMessageId"] === message_id);
|
|
109
|
+
assert(params["tdProjectId"] === PROJECT_ID);
|
|
110
110
|
listener.close(() => {
|
|
111
111
|
done();
|
|
112
112
|
});
|
|
@@ -231,8 +231,8 @@ describe('Conversation1 - Form filling', async () => {
|
|
|
231
231
|
else {
|
|
232
232
|
// console.log("params2:", params);
|
|
233
233
|
assert(params);
|
|
234
|
-
assert(params["
|
|
235
|
-
assert(params["
|
|
234
|
+
assert(params["tdLastMessageId"] === message_id);
|
|
235
|
+
assert(params["tdProjectId"] === PROJECT_ID);
|
|
236
236
|
assert(params["your_fullname"] === reply_text);
|
|
237
237
|
assert(params["_tdTypeOf:your_fullname"]);
|
|
238
238
|
listener.close(() => {
|
|
@@ -818,7 +818,7 @@ describe('Conversation1 - Form filling', async () => {
|
|
|
818
818
|
// console.log("params /condition:", params);
|
|
819
819
|
assert(params);
|
|
820
820
|
// assert(params["city"] === "Milan");
|
|
821
|
-
assert(params["
|
|
821
|
+
assert(params["tdCountry"] === "IT");
|
|
822
822
|
let request = {
|
|
823
823
|
"payload": {
|
|
824
824
|
"_id": uuidv4(),
|
|
@@ -859,7 +859,7 @@ describe('Conversation1 - Form filling', async () => {
|
|
|
859
859
|
"type": "text",
|
|
860
860
|
"sender": "A-SENDER",
|
|
861
861
|
"recipient": REQUEST_ID,
|
|
862
|
-
"text": "/assign_params{\"
|
|
862
|
+
"text": "/assign_params{\"tdCountry\": \"IT\"}",
|
|
863
863
|
"id_project": PROJECT_ID,
|
|
864
864
|
"request": {
|
|
865
865
|
"request_id": REQUEST_ID,
|
|
@@ -894,7 +894,7 @@ describe('Conversation1 - Form filling', async () => {
|
|
|
894
894
|
// console.log("params /if_you_live_IT:", params);
|
|
895
895
|
assert(params);
|
|
896
896
|
// assert(params["city"] === "Milan");
|
|
897
|
-
assert(params["
|
|
897
|
+
assert(params["tdCountry"] === "US");
|
|
898
898
|
let request = {
|
|
899
899
|
"payload": {
|
|
900
900
|
"_id": uuidv4(),
|
|
@@ -935,7 +935,7 @@ describe('Conversation1 - Form filling', async () => {
|
|
|
935
935
|
"type": "text",
|
|
936
936
|
"sender": "A-SENDER",
|
|
937
937
|
"recipient": REQUEST_ID,
|
|
938
|
-
"text": "/assign_params{\"
|
|
938
|
+
"text": "/assign_params{\"tdCountry\": \"US\"}",
|
|
939
939
|
"id_project": PROJECT_ID,
|
|
940
940
|
"request": {
|
|
941
941
|
"request_id": REQUEST_ID,
|
|
@@ -770,7 +770,7 @@ const bot = {
|
|
|
770
770
|
"enabled": true,
|
|
771
771
|
"actions": [],
|
|
772
772
|
"question": "***",
|
|
773
|
-
"answer": "you live in ${
|
|
773
|
+
"answer": "you live in ${tdCity} (${tdCountry})",
|
|
774
774
|
"language": "en",
|
|
775
775
|
"intent_display_name": "location"
|
|
776
776
|
}, {
|
|
@@ -778,7 +778,7 @@ const bot = {
|
|
|
778
778
|
"enabled": true,
|
|
779
779
|
"actions": [],
|
|
780
780
|
"question": "***",
|
|
781
|
-
"answer": "\\_tdcondition --condition \"$
|
|
781
|
+
"answer": "\\_tdcondition --condition \"$tdCountry === \\\"IT\\\"\" --trueIntent \"live_in_italy\" --falseIntent \"live_outside_italy\"",
|
|
782
782
|
"language": "en",
|
|
783
783
|
"intent_display_name": "if_you_live_IT"
|
|
784
784
|
}, {
|
|
@@ -343,7 +343,7 @@ describe('filter commands()', function() {
|
|
|
343
343
|
];
|
|
344
344
|
|
|
345
345
|
TiledeskChatbotUtil.filterOnLanguage(commands, "en");
|
|
346
|
-
console.log("commands after", commands);
|
|
346
|
+
// console.log("commands after", commands);
|
|
347
347
|
// assert(commands.length == 6);
|
|
348
348
|
});
|
|
349
349
|
});
|
|
@@ -249,9 +249,17 @@ class DirectivesChatbotPlug {
|
|
|
249
249
|
}
|
|
250
250
|
else if (directive_name === Directives.CONDITION) {
|
|
251
251
|
// console.log("...DirCondition");
|
|
252
|
-
new DirCondition(context).execute(directive, async () => {
|
|
253
|
-
|
|
254
|
-
|
|
252
|
+
new DirCondition(context).execute(directive, async (stop) => {
|
|
253
|
+
if (stop == true) {
|
|
254
|
+
if (context.log) { console.log("Stopping Actions on:", directive);}
|
|
255
|
+
this.theend();
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
259
|
+
this.process(next_dir);
|
|
260
|
+
}
|
|
261
|
+
// let next_dir = await this.nextDirective(this.directives);
|
|
262
|
+
// this.process(next_dir);
|
|
255
263
|
});
|
|
256
264
|
}
|
|
257
265
|
else if (directive_name === Directives.ASSIGN) {
|
|
@@ -75,6 +75,8 @@ class DirCondition {
|
|
|
75
75
|
const condition = action.condition;
|
|
76
76
|
let trueIntent = action.trueIntent;
|
|
77
77
|
let falseIntent = action.falseIntent;
|
|
78
|
+
let stopOnConditionMet = action.stopOnConditionMet;
|
|
79
|
+
console.log("executing action:", action);
|
|
78
80
|
if (trueIntent && trueIntent.trim() === "") {
|
|
79
81
|
trueIntent = null;
|
|
80
82
|
}
|
|
@@ -131,7 +133,7 @@ class DirCondition {
|
|
|
131
133
|
if (result === true) {
|
|
132
134
|
if (trueIntentDirective) {
|
|
133
135
|
this.intentDir.execute(trueIntentDirective, () => {
|
|
134
|
-
callback();
|
|
136
|
+
callback(stopOnConditionMet);
|
|
135
137
|
});
|
|
136
138
|
}
|
|
137
139
|
else {
|
|
@@ -143,7 +145,7 @@ class DirCondition {
|
|
|
143
145
|
else {
|
|
144
146
|
if (falseIntentDirective) {
|
|
145
147
|
this.intentDir.execute(falseIntentDirective, () => {
|
|
146
|
-
callback();
|
|
148
|
+
callback(stopOnConditionMet);
|
|
147
149
|
});
|
|
148
150
|
}
|
|
149
151
|
else {
|
|
@@ -65,73 +65,57 @@ class DirIntent {
|
|
|
65
65
|
go(action, callback) {
|
|
66
66
|
// console.log("action intent:", action);
|
|
67
67
|
const intentName = action.intentName;
|
|
68
|
+
const intentId = action.intentId;
|
|
68
69
|
const projectId = this.supportRequest.id_project;
|
|
69
70
|
const requestId = this.supportRequest.request_id;
|
|
70
71
|
const botId = this.supportRequest.bot_id;
|
|
72
|
+
let intent_command;
|
|
71
73
|
if (intentName) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"senderFullname": "_tdinternal",
|
|
77
|
-
"type": "text",
|
|
78
|
-
"sender": "_tdinternal",
|
|
79
|
-
"recipient": requestId,
|
|
80
|
-
"text": intent_command,
|
|
81
|
-
"id_project": projectId,
|
|
82
|
-
"request": {
|
|
83
|
-
"request_id": requestId,
|
|
84
|
-
"id_project": projectId
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
"token": this.token
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// let intent_command_message = {
|
|
91
|
-
// //sender: "_tdsender", // bot doesn't reply to "himself" and "system"
|
|
92
|
-
// text: intent_command,
|
|
93
|
-
// attributes: {
|
|
94
|
-
// subtype: "info"
|
|
95
|
-
// }
|
|
96
|
-
// };
|
|
97
|
-
// send message to /ext/botId
|
|
98
|
-
// const req_body = {
|
|
99
|
-
// payload: message_to_bot,
|
|
100
|
-
// token: token
|
|
101
|
-
// }
|
|
102
|
-
// let extEndpoint = `${this.API_ENDPOINT}/modules/tilebot`;
|
|
103
|
-
// if (this.TILEBOT_ENDPOINT) {
|
|
104
|
-
// extEndpoint = `${this.TILEBOT_ENDPOINT}`;
|
|
105
|
-
// }
|
|
106
|
-
// const extapi = new ExtApi({
|
|
107
|
-
// ENDPOINT: extEndpoint,
|
|
108
|
-
// log: this.log
|
|
109
|
-
// });
|
|
110
|
-
if (this.log) {console.log("move to intent message:", intent_command_request);}
|
|
111
|
-
// extapi.sendSupportMessageExt(intent_command_message, projectId, requestId, token, () => {
|
|
112
|
-
// if (this.log) {console.log("command " + intent_command + " sent.");}
|
|
113
|
-
// callback();
|
|
114
|
-
// });
|
|
115
|
-
let TILEBOT_ENDPOINT;
|
|
116
|
-
// if (process.env.CHATBOT_ENDPOINT) {
|
|
117
|
-
// CHATBOT_ENDPOINT = process.env.CHATBOT_ENDPOINT;
|
|
118
|
-
// }
|
|
119
|
-
// else
|
|
120
|
-
if (this.TILEBOT_ENDPOINT) {
|
|
121
|
-
TILEBOT_ENDPOINT = this.TILEBOT_ENDPOINT;
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
TILEBOT_ENDPOINT = `${this.API_ENDPOINT}/modules/tilebot`
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
this.sendMessageToBot(TILEBOT_ENDPOINT, intent_command_request, botId, () => {
|
|
128
|
-
// console.log("sendMessageToBot() req_body sent:", intent_command_request);
|
|
129
|
-
callback();
|
|
130
|
-
});
|
|
74
|
+
intent_command = "/" + intentName;
|
|
75
|
+
}
|
|
76
|
+
else if (intentId) {
|
|
77
|
+
intent_command = "/#" + intentId;
|
|
131
78
|
}
|
|
132
79
|
else {
|
|
80
|
+
console.error("Invalid intent");
|
|
133
81
|
callback();
|
|
134
82
|
}
|
|
83
|
+
|
|
84
|
+
// if (intentName) {
|
|
85
|
+
// let intent_command = "/" + intentName;
|
|
86
|
+
let intent_command_request = {
|
|
87
|
+
"payload": {
|
|
88
|
+
"_id": uuidv4(),
|
|
89
|
+
"senderFullname": "_tdinternal",
|
|
90
|
+
"type": "text",
|
|
91
|
+
"sender": "_tdinternal",
|
|
92
|
+
"recipient": requestId,
|
|
93
|
+
"text": intent_command,
|
|
94
|
+
"id_project": projectId,
|
|
95
|
+
"request": {
|
|
96
|
+
"request_id": requestId,
|
|
97
|
+
"id_project": projectId
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"token": this.token
|
|
101
|
+
}
|
|
102
|
+
if (this.log) {console.log("move to intent message:", intent_command_request);}
|
|
103
|
+
let TILEBOT_ENDPOINT;
|
|
104
|
+
if (this.TILEBOT_ENDPOINT) {
|
|
105
|
+
TILEBOT_ENDPOINT = this.TILEBOT_ENDPOINT;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
TILEBOT_ENDPOINT = `${this.API_ENDPOINT}/modules/tilebot`
|
|
109
|
+
}
|
|
110
|
+
this.sendMessageToBot(TILEBOT_ENDPOINT, intent_command_request, botId, () => {
|
|
111
|
+
// console.log("sendMessageToBot() req_body sent:", intent_command_request);
|
|
112
|
+
callback();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// }
|
|
116
|
+
// else {
|
|
117
|
+
// callback();
|
|
118
|
+
// }
|
|
135
119
|
}
|
|
136
120
|
|
|
137
121
|
static intentDirectiveFor(intent) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
1
|
+
// const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
2
2
|
const { Directives } = require('./Directives');
|
|
3
|
+
const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
|
|
4
|
+
const { TiledeskChatbotConst } = require('../../models/TiledeskChatbotConst');
|
|
3
5
|
|
|
4
6
|
class DirMoveToAgent {
|
|
5
7
|
|
|
@@ -29,7 +31,7 @@ class DirMoveToAgent {
|
|
|
29
31
|
this.tdclient = context.tdclient;
|
|
30
32
|
this.tdcache = context.tdcache;
|
|
31
33
|
this.requestId = context.requestId;
|
|
32
|
-
this.depId = context.departmentId;
|
|
34
|
+
// this.depId = context.departmentId;
|
|
33
35
|
this.log = context.log;
|
|
34
36
|
}
|
|
35
37
|
|
|
@@ -44,24 +46,34 @@ class DirMoveToAgent {
|
|
|
44
46
|
callback();
|
|
45
47
|
});
|
|
46
48
|
}
|
|
47
|
-
|
|
49
|
+
|
|
50
|
+
async go(action, callback) {
|
|
48
51
|
if (action.whenOnlineOnly === true) {
|
|
49
|
-
this.tdclient.openNow((err, result) => {
|
|
52
|
+
this.tdclient.openNow( async (err, result) => {
|
|
50
53
|
if (err) {
|
|
51
54
|
console.error("Agent in DirOfflineHours Error:", err);
|
|
52
55
|
callback();
|
|
53
56
|
}
|
|
54
57
|
else {
|
|
55
58
|
if (result && result.isopen) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
if (this.tdcache) {
|
|
60
|
+
depId =
|
|
61
|
+
await TiledeskChatbot.getParameterStatic(
|
|
62
|
+
this.tdcache, this.requestId, TiledeskChatbotConst.REQ_DEPARTMENT_ID_KEY
|
|
63
|
+
);
|
|
64
|
+
this.tdclient.agent(this.requestId, depId, (err) => {
|
|
65
|
+
if (err) {
|
|
66
|
+
console.error("Error moving to agent during online hours:", err);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
//console.log("Successfully moved to agent during online hours");
|
|
70
|
+
}
|
|
71
|
+
callback();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
63
75
|
callback();
|
|
64
|
-
}
|
|
76
|
+
}
|
|
65
77
|
}
|
|
66
78
|
else {
|
|
67
79
|
callback();
|
|
@@ -70,15 +82,24 @@ class DirMoveToAgent {
|
|
|
70
82
|
});
|
|
71
83
|
}
|
|
72
84
|
else {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
85
|
+
if (this.tdcache) {
|
|
86
|
+
const depId =
|
|
87
|
+
await TiledeskChatbot.getParameterStatic(
|
|
88
|
+
this.tdcache, this.requestId, TiledeskChatbotConst.REQ_DEPARTMENT_ID_KEY
|
|
89
|
+
);
|
|
90
|
+
this.tdclient.agent(this.requestId, depId, (err) => {
|
|
91
|
+
if (err) {
|
|
92
|
+
console.error("Error moving to agent:", err);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
//console.log("Successfully moved to agent");
|
|
96
|
+
}
|
|
97
|
+
callback();
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
80
101
|
callback();
|
|
81
|
-
}
|
|
102
|
+
}
|
|
82
103
|
}
|
|
83
104
|
}
|
|
84
105
|
|