@tiledesk/tiledesk-tybot-connector 2.0.9 → 2.0.10-rc2
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 +27 -2
- package/ExtApi.js +1 -8
- package/ExtUtil.js +5 -6
- package/Logger.js +27 -17
- package/engine/IntentForm.js +0 -1
- package/engine/IntentsMachineFactory.js +4 -4
- package/engine/MongodbBotsDataSource.js +0 -1
- package/engine/MongodbIntentsMachine.js +0 -1
- package/engine/TiledeskChatbot.js +11 -16
- package/engine/TiledeskIntentsMachine.js +1 -2
- package/engine/mock/MockBotsDataSource.js +1 -2
- package/index.js +22 -25
- package/logs/app.log +11066 -20247
- package/logs/app2.log +46280 -0
- package/logs/app3.log +31686 -0
- package/logs/app4.log +46163 -0
- package/logs/app5.log +39983 -0
- package/logs/app6.log +5964 -0
- package/package.json +3 -2
- package/services/AIService.js +1 -1
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +31 -18
- package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +1 -2
- package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +1 -3
- package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +1 -3
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +7 -9
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfNotOpenHours.js +3 -10
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfOpenHours.js +2 -9
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +16 -4
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +16 -0
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +16 -0
- package/tiledeskChatbotPlugs/directives/DirAssign.js +5 -8
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +4 -6
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirClose.js +0 -2
- package/tiledeskChatbotPlugs/directives/DirCode.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirCondition.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +2 -5
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirFlowLog.js +76 -0
- package/tiledeskChatbotPlugs/directives/DirForm.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +36 -55
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +1 -4
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +1 -4
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +0 -2
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +8 -12
- package/tiledeskChatbotPlugs/directives/DirIntent.js +6 -5
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirMake.js +1 -16
- package/tiledeskChatbotPlugs/directives/DirMessage.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +1 -4
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +0 -3
- package/tiledeskChatbotPlugs/directives/DirQapla.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +1 -2
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirReply.js +7 -18
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +8 -13
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +1 -4
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirWait.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +14 -15
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +6 -40
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +0 -1
- package/tiledeskChatbotPlugs/directives/Directives.js +2 -0
- package/utils/TiledeskChatbotUtil.js +19 -57
- package/TdCache copy.js +0 -242
- package/logs/app1.log +0 -16071
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +0 -417
|
@@ -4,6 +4,7 @@ const { Filler } = require('../Filler');
|
|
|
4
4
|
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
5
5
|
const { DirIntent } = require('./DirIntent');
|
|
6
6
|
const winston = require('../../utils/winston');
|
|
7
|
+
const { Logger } = require('../../Logger');
|
|
7
8
|
|
|
8
9
|
class DirWebRequestV2 {
|
|
9
10
|
|
|
@@ -17,6 +18,7 @@ class DirWebRequestV2 {
|
|
|
17
18
|
this.chatbot = context.chatbot;
|
|
18
19
|
this.intentDir = new DirIntent(context);
|
|
19
20
|
this.log = context.log;
|
|
21
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest.draft });
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
execute(directive, callback) {
|
|
@@ -30,7 +32,9 @@ class DirWebRequestV2 {
|
|
|
30
32
|
callback();
|
|
31
33
|
return;
|
|
32
34
|
}
|
|
35
|
+
this.logger.info("Executing WebRequest action ", directive.action)
|
|
33
36
|
this.go(action, (stop) => {
|
|
37
|
+
this.logger.info("WebRequest action terminated")
|
|
34
38
|
callback(stop);
|
|
35
39
|
}).catch((err) => {
|
|
36
40
|
// do not nothing
|
|
@@ -65,6 +69,7 @@ class DirWebRequestV2 {
|
|
|
65
69
|
const url = filler.fill(action.url, requestAttributes);
|
|
66
70
|
|
|
67
71
|
let headers = await this.getHeadersFromAction(action, filler, requestAttributes).catch( async (err) => {
|
|
72
|
+
this.logger.error("WebRequest: error getting headers");
|
|
68
73
|
await this.chatbot.addParameter("flowError", "Error getting headers");
|
|
69
74
|
if (falseIntent) {
|
|
70
75
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -76,6 +81,7 @@ class DirWebRequestV2 {
|
|
|
76
81
|
});
|
|
77
82
|
|
|
78
83
|
let json = await this.getJsonFromAction(action, filler, requestAttributes).catch( async (err) => {
|
|
84
|
+
this.logger.error("WebRequest: error parsing json body");
|
|
79
85
|
await this.chatbot.addParameter("flowError", "Error parsing json body");
|
|
80
86
|
if (falseIntent) {
|
|
81
87
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -107,8 +113,10 @@ class DirWebRequestV2 {
|
|
|
107
113
|
let error = res.error;
|
|
108
114
|
await this.#assignAttributes(action, resbody, status, error)
|
|
109
115
|
winston.debug("DirWebRequestV2 resbody:", resbody);
|
|
116
|
+
this.logger.info("WebRequest resbody: ", resbody);
|
|
110
117
|
|
|
111
118
|
if (err) {
|
|
119
|
+
this.logger.error("WebRequest error: ", err);
|
|
112
120
|
winston.log("webRequest error: ", err);
|
|
113
121
|
if (callback) {
|
|
114
122
|
if (falseIntent) {
|
|
@@ -130,6 +138,7 @@ class DirWebRequestV2 {
|
|
|
130
138
|
return;
|
|
131
139
|
}
|
|
132
140
|
else {
|
|
141
|
+
this.logger.warn("WebRequest status ", status);
|
|
133
142
|
if (falseIntent) {
|
|
134
143
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
135
144
|
callback(true);
|
|
@@ -228,6 +237,7 @@ class DirWebRequestV2 {
|
|
|
228
237
|
}
|
|
229
238
|
if (result === true) {
|
|
230
239
|
if (trueIntentDirective) {
|
|
240
|
+
this.logger.info("WebRequest: executing true condition");
|
|
231
241
|
this.intentDir.execute(trueIntentDirective, () => {
|
|
232
242
|
if (callback) {
|
|
233
243
|
callback();
|
|
@@ -235,6 +245,7 @@ class DirWebRequestV2 {
|
|
|
235
245
|
});
|
|
236
246
|
}
|
|
237
247
|
else {
|
|
248
|
+
this.logger.info("WebRequest: no block connected to true condition");
|
|
238
249
|
winston.debug("DirWebRequestV2 No trueIntentDirective specified");
|
|
239
250
|
if (callback) {
|
|
240
251
|
callback();
|
|
@@ -243,6 +254,7 @@ class DirWebRequestV2 {
|
|
|
243
254
|
}
|
|
244
255
|
else {
|
|
245
256
|
if (falseIntentDirective) {
|
|
257
|
+
this.logger.info("WebRequest: executing false condition");
|
|
246
258
|
this.intentDir.execute(falseIntentDirective, () => {
|
|
247
259
|
if (callback) {
|
|
248
260
|
callback();
|
|
@@ -250,6 +262,7 @@ class DirWebRequestV2 {
|
|
|
250
262
|
});
|
|
251
263
|
}
|
|
252
264
|
else {
|
|
265
|
+
this.logger.info("WebRequest: no block connected to false condition");
|
|
253
266
|
winston.debug("DirWebRequestV2 No falseIntentDirective specified");
|
|
254
267
|
if (callback) {
|
|
255
268
|
callback();
|
|
@@ -302,21 +315,7 @@ class DirWebRequestV2 {
|
|
|
302
315
|
}
|
|
303
316
|
})
|
|
304
317
|
.catch((err) => {
|
|
305
|
-
|
|
306
|
-
// FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - START
|
|
307
|
-
let cache = [];
|
|
308
|
-
let error_log = JSON.stringify(err, function (key, value) { // try to use a separate function
|
|
309
|
-
if (typeof value === 'object' && value != null) {
|
|
310
|
-
if (cache.indexOf(value) !== -1) {
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
cache.push(value);
|
|
314
|
-
}
|
|
315
|
-
return value;
|
|
316
|
-
});
|
|
317
|
-
winston.error("(DirWebRequestv2) An error occurred: ", error_log);
|
|
318
|
-
// FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END
|
|
319
|
-
}
|
|
318
|
+
// FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END
|
|
320
319
|
if (callback) {
|
|
321
320
|
let status = 1000;
|
|
322
321
|
let cache = [];
|
|
@@ -3,6 +3,7 @@ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
|
3
3
|
const { TiledeskChatbotUtil } = require('../../utils/TiledeskChatbotUtil');
|
|
4
4
|
const winston = require('../../utils/winston');
|
|
5
5
|
let axios = require('axios');
|
|
6
|
+
const { Logger } = require('../../Logger');
|
|
6
7
|
|
|
7
8
|
class DirWebResponse {
|
|
8
9
|
|
|
@@ -15,7 +16,7 @@ class DirWebResponse {
|
|
|
15
16
|
this.requestId = context.requestId;
|
|
16
17
|
this.token = context.token;
|
|
17
18
|
this.tdcache = context.tdcache;
|
|
18
|
-
this.
|
|
19
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest.draft });
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
execute(directive, callback) {
|
|
@@ -29,8 +30,9 @@ class DirWebResponse {
|
|
|
29
30
|
callback();
|
|
30
31
|
return;
|
|
31
32
|
}
|
|
33
|
+
this.logger.info("Executing WebResponse action ", directive.action)
|
|
32
34
|
this.go(action, () => {
|
|
33
|
-
|
|
35
|
+
this.logger.info("WebResponse action terminated")
|
|
34
36
|
callback();
|
|
35
37
|
});
|
|
36
38
|
}
|
|
@@ -59,6 +61,8 @@ class DirWebResponse {
|
|
|
59
61
|
payload: json
|
|
60
62
|
}
|
|
61
63
|
|
|
64
|
+
this.logger.debug("WebResponse payload: ", webResponse);
|
|
65
|
+
|
|
62
66
|
const topic = `/webhooks/${this.requestId}`;
|
|
63
67
|
|
|
64
68
|
try {
|
|
@@ -96,42 +100,4 @@ class DirWebResponse {
|
|
|
96
100
|
|
|
97
101
|
}
|
|
98
102
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* A stub to send message to the "ext/botId" endpoint, hosted by tilebot on:
|
|
103
|
-
* /${TILEBOT_ROUTE}/ext/${botId}
|
|
104
|
-
*
|
|
105
|
-
* @param {Object} webResponse. The webhook response to send back
|
|
106
|
-
* @param {Object} projectId. The projectId
|
|
107
|
-
* @param {string} botId. Tiledesk botId
|
|
108
|
-
* @param {string} token. User token
|
|
109
|
-
*/
|
|
110
|
-
// function sendResponse(webResponse, projectId, botId, callback) {
|
|
111
|
-
// const url = `${WEBHOOK_URL}/${projectId}/${botId}`;
|
|
112
|
-
// const HTTPREQUEST = {
|
|
113
|
-
// url: url,
|
|
114
|
-
// headers: {
|
|
115
|
-
// 'Content-Type': 'application/json'
|
|
116
|
-
// },
|
|
117
|
-
// json: webResponse,
|
|
118
|
-
// method: 'POST'
|
|
119
|
-
// };
|
|
120
|
-
// myrequest(
|
|
121
|
-
// HTTPREQUEST,
|
|
122
|
-
// function (err, resbody) {
|
|
123
|
-
// if (err) {
|
|
124
|
-
// if (callback) {
|
|
125
|
-
// callback(err);
|
|
126
|
-
// }
|
|
127
|
-
// }
|
|
128
|
-
// else {
|
|
129
|
-
// if (callback) {
|
|
130
|
-
// callback(null, resbody);
|
|
131
|
-
// }
|
|
132
|
-
// }
|
|
133
|
-
// }, false
|
|
134
|
-
// );
|
|
135
|
-
// }
|
|
136
|
-
|
|
137
103
|
module.exports = { DirWebResponse };
|
|
@@ -58,7 +58,9 @@ class Directives {
|
|
|
58
58
|
static MOVE_TO_UNASSIGNED = "move_to_unassigned";
|
|
59
59
|
static CONNECT_BLOCK = "connect_block";
|
|
60
60
|
static ADD_TAGS = 'add_tags'
|
|
61
|
+
static WEBHOOK = 'webhook';
|
|
61
62
|
static WEB_RESPONSE = "web_response";
|
|
63
|
+
static FLOW_LOG = "flow_log";
|
|
62
64
|
|
|
63
65
|
// static WHEN_ONLINE_MOVE_TO_AGENT = "whenonlinemovetoagent"; // DEPRECATED?
|
|
64
66
|
// static WHEN_OFFLINE_HOURS = "whenofflinehours"; // DEPRECATED // adds a message on top of the original message when offline hours opts: --replace
|
|
@@ -252,24 +252,24 @@ class TiledeskChatbotUtil {
|
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
-
static fillCommandAttachments(command, variables
|
|
256
|
-
|
|
255
|
+
static fillCommandAttachments(command, variables) {
|
|
256
|
+
winston.debug("(TiledeskChatbotUtils) Filling command button: ", command)
|
|
257
257
|
if (command.message && command.message.attributes && command.message.attributes.attachment && command.message.attributes.attachment.buttons && command.message.attributes.attachment.buttons.length > 0) {
|
|
258
258
|
let buttons = command.message.attributes.attachment.buttons;
|
|
259
259
|
const filler = new Filler();
|
|
260
260
|
buttons.forEach(button => {
|
|
261
261
|
if (button.link) {
|
|
262
262
|
button.link = filler.fill(button.link, variables);
|
|
263
|
-
|
|
263
|
+
winston.debug("(TiledeskChatbotUtils) button.link filled: " + button.link)
|
|
264
264
|
}
|
|
265
265
|
if (button.value) {
|
|
266
266
|
button.value = filler.fill(button.value, variables);
|
|
267
|
-
|
|
267
|
+
winston.debug("(TiledeskChatbotUtils) button.value filled: " + button.value)
|
|
268
268
|
}
|
|
269
269
|
});
|
|
270
270
|
}
|
|
271
271
|
else {
|
|
272
|
-
|
|
272
|
+
winston.debug("(TiledeskChatbotUtils) No attachments to fill in command")
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
|
|
@@ -319,55 +319,31 @@ class TiledeskChatbotUtil {
|
|
|
319
319
|
json_buttons.forEach(button => {
|
|
320
320
|
if (button.value && button.type === "action" && button.action) {
|
|
321
321
|
button.show_echo = true;
|
|
322
|
-
// console.log("pushing:", button)
|
|
323
322
|
final_buttons.push(button);
|
|
324
323
|
}
|
|
325
324
|
else if (button.value && button.type === "text") {
|
|
326
325
|
button.show_echo = true;
|
|
327
|
-
// console.log("pushing:", button)
|
|
328
326
|
final_buttons.push(button);
|
|
329
327
|
}
|
|
330
328
|
else if (button.value && button.type === "url" && button.link) {
|
|
331
329
|
button.show_echo = true;
|
|
332
|
-
// console.log("pushing:", button)
|
|
333
330
|
final_buttons.push(button);
|
|
334
331
|
}
|
|
335
332
|
else {
|
|
336
|
-
|
|
333
|
+
winston.verbose("Invalid button. Skipping:", button);
|
|
337
334
|
}
|
|
338
335
|
});
|
|
339
336
|
}
|
|
340
|
-
|
|
341
|
-
// "buttons": [
|
|
342
|
-
// {
|
|
343
|
-
// "type": "action",
|
|
344
|
-
// "value": "Button1", // obbligatorio sempre
|
|
345
|
-
// "action": "#bb347206-d639-4926-94c9-e94930623dce", // mandatory
|
|
346
|
-
// "show_echo": true, // lo inserisco sempre
|
|
347
|
-
// "alias": "button1 alias"
|
|
348
|
-
// },
|
|
349
|
-
// {
|
|
350
|
-
// "type": "text",
|
|
351
|
-
// "value": "Button2 text", // obbligatorio sempre
|
|
352
|
-
// "show_echo": true // lo inserisco sempre
|
|
353
|
-
// },
|
|
354
|
-
// {
|
|
355
|
-
// "type": "url",
|
|
356
|
-
// "value": "Button3 link", // obbligatorio sempre
|
|
357
|
-
// "link": "http://", // obbligatorio
|
|
358
|
-
// "show_echo": true // lo inserisco sempre
|
|
359
|
-
// }
|
|
360
|
-
// ]
|
|
361
337
|
}
|
|
362
338
|
catch(error) {
|
|
363
|
-
|
|
339
|
+
winston.warn("Invalid json_buttons:", error)
|
|
364
340
|
}
|
|
365
341
|
if (final_buttons && final_buttons.length > 0) {
|
|
366
342
|
command.message.attributes.attachment.buttons = final_buttons;
|
|
367
343
|
delete command.message.attributes.attachment.json_buttons;
|
|
368
344
|
}
|
|
369
345
|
else {
|
|
370
|
-
|
|
346
|
+
winston.verbose("Invalid json_buttons. Skipping...")
|
|
371
347
|
}
|
|
372
348
|
}
|
|
373
349
|
}
|
|
@@ -520,7 +496,7 @@ class TiledeskChatbotUtil {
|
|
|
520
496
|
static async updateRequestAttributes(chatbot, chatbotToken, message, projectId, requestId) {
|
|
521
497
|
// update request context
|
|
522
498
|
try {
|
|
523
|
-
|
|
499
|
+
winston.debug("Updating request variables. Message:", message);
|
|
524
500
|
const messageId = message._id;
|
|
525
501
|
const chat_url = `https://panel.tiledesk.com/v3/dashboard/#/project/${projectId}/wsrequest/${requestId}/messages`
|
|
526
502
|
|
|
@@ -591,12 +567,12 @@ class TiledeskChatbotUtil {
|
|
|
591
567
|
}
|
|
592
568
|
|
|
593
569
|
if (message && message.request && message.request.lead) {
|
|
594
|
-
|
|
570
|
+
winston.debug("(TiledeskChatbotUtil) Lead found with email: " + message.request.lead.email + " and lead.fullname " + message.request.lead.fullname);
|
|
595
571
|
let currentLeadEmail = await chatbot.getParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY);
|
|
596
|
-
|
|
572
|
+
winston.debug("(TiledeskChatbotUtil) You lead email from attributes: " + currentLeadEmail);
|
|
597
573
|
if (message.request.lead.email && !currentLeadEmail) {
|
|
598
574
|
// worth saving
|
|
599
|
-
|
|
575
|
+
winston.debug("(TiledeskChatbotUtil) worth saving email");
|
|
600
576
|
try {
|
|
601
577
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY, message.request.lead.email);
|
|
602
578
|
}
|
|
@@ -605,10 +581,10 @@ class TiledeskChatbotUtil {
|
|
|
605
581
|
}
|
|
606
582
|
}
|
|
607
583
|
let currentLeadName = await chatbot.getParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY);
|
|
608
|
-
|
|
584
|
+
winston.debug("(TiledeskChatbotUtil) You lead email from attributes: " + currentLeadEmail);
|
|
609
585
|
if (message.request.lead.fullname && !currentLeadName) {
|
|
610
586
|
// worth saving
|
|
611
|
-
|
|
587
|
+
winston.debug("(TiledeskChatbotUtil) worth saving email");
|
|
612
588
|
try {
|
|
613
589
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY, message.request.lead.fullname);
|
|
614
590
|
}
|
|
@@ -685,10 +661,10 @@ class TiledeskChatbotUtil {
|
|
|
685
661
|
message.attributes = {}
|
|
686
662
|
}
|
|
687
663
|
message.attributes.payload = { ...message.attributes.payload, ...message.request.attributes.payload }
|
|
688
|
-
|
|
664
|
+
winston.debug("(TiledeskChatbotUtil) Forced Set message.attributes.payload ", message.attributes.payload);
|
|
689
665
|
}
|
|
690
666
|
if (message.attributes) {
|
|
691
|
-
|
|
667
|
+
winston.debug("(TiledeskChatbotUtil) Ok message.attributes ", message.attributes);
|
|
692
668
|
|
|
693
669
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_ID_KEY, message.attributes.requester_id);
|
|
694
670
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_IP_ADDRESS_KEY, message.attributes.ipAddress);
|
|
@@ -722,12 +698,12 @@ class TiledeskChatbotUtil {
|
|
|
722
698
|
|
|
723
699
|
|
|
724
700
|
const _bot = chatbot.bot; // aka FaqKB
|
|
725
|
-
|
|
701
|
+
winston.debug("(TiledeskChatbotUtil) Adding Globals to context: ", _bot);
|
|
726
702
|
|
|
727
703
|
if (_bot.attributes && _bot.attributes.globals) {
|
|
728
|
-
|
|
704
|
+
winston.error("(TiledeskChatbotUtil) Got Globals: ", _bot.attributes.globals);
|
|
729
705
|
_bot.attributes.globals.forEach(async (global_var) => {
|
|
730
|
-
|
|
706
|
+
winston.error("(TiledeskChatbotUtil) Adding global: " + global_var.key + " value: " + global_var.value);
|
|
731
707
|
await chatbot.addParameter(global_var.key, global_var.value);
|
|
732
708
|
});
|
|
733
709
|
}
|
|
@@ -740,20 +716,6 @@ class TiledeskChatbotUtil {
|
|
|
740
716
|
// }
|
|
741
717
|
// );
|
|
742
718
|
|
|
743
|
-
if (chatbot.log) {
|
|
744
|
-
if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) requestId: " + requestId); }
|
|
745
|
-
if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Key: " + TiledeskChatbotConst.REQ_PROJECT_ID_KEY); }
|
|
746
|
-
|
|
747
|
-
let proj_ = await chatbot.getParameter(TiledeskChatbotConst.REQ_PROJECT_ID_KEY);
|
|
748
|
-
if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) request parameter proj_: " + proj_); }
|
|
749
|
-
|
|
750
|
-
const all_parameters = await chatbot.allParameters();
|
|
751
|
-
for (const [key, value] of Object.entries(all_parameters)) {
|
|
752
|
-
const value_type = typeof value;
|
|
753
|
-
if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Request Attribute: " + key + " value: " + value + " type: " + value_type); }
|
|
754
|
-
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
719
|
} catch(error) {
|
|
758
720
|
winston.error("(TiledeskChatbotUtil) updateRequestAttributes Error: ", error);
|
|
759
721
|
process.exit(1)
|
package/TdCache copy.js
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
const redis = require('redis');
|
|
2
|
-
|
|
3
|
-
class TdCache {
|
|
4
|
-
|
|
5
|
-
constructor(config) {
|
|
6
|
-
this.redis_host = config.host;
|
|
7
|
-
this.redis_port = config.port;
|
|
8
|
-
this.redis_password = config.password;
|
|
9
|
-
this.client = null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async connect(callback) {
|
|
13
|
-
// client = redis.createClient();
|
|
14
|
-
return new Promise( async (resolve, reject) => {
|
|
15
|
-
this.client = redis.createClient(
|
|
16
|
-
{
|
|
17
|
-
host: this.redis_host,
|
|
18
|
-
port: this.redis_port,
|
|
19
|
-
password: this.redis_password
|
|
20
|
-
});
|
|
21
|
-
this.client.on('error', err => {
|
|
22
|
-
reject(err);
|
|
23
|
-
if (callback) {
|
|
24
|
-
callback(err);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
// this.client.on('connect', function() {
|
|
28
|
-
// console.log('Redis Connected!');
|
|
29
|
-
// });
|
|
30
|
-
this.client.on('ready',function() {
|
|
31
|
-
console.log("connected")
|
|
32
|
-
resolve();
|
|
33
|
-
if (callback) {
|
|
34
|
-
callback();
|
|
35
|
-
}
|
|
36
|
-
//console.log("Redis is ready.");
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async set(key, value, options) {
|
|
42
|
-
//console.log("setting key value", key, value)
|
|
43
|
-
if (!options) {
|
|
44
|
-
options = {EX: 86400}
|
|
45
|
-
}
|
|
46
|
-
return new Promise( async (resolve, reject) => {
|
|
47
|
-
if (options && options.EX) {
|
|
48
|
-
//console.log("expires:", options.EX)
|
|
49
|
-
try {
|
|
50
|
-
await this.client.set(
|
|
51
|
-
key,
|
|
52
|
-
value,
|
|
53
|
-
'EX', options.EX);
|
|
54
|
-
}
|
|
55
|
-
catch(error) {
|
|
56
|
-
reject(error)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
try {
|
|
61
|
-
//console.log("setting here...key", key, value)
|
|
62
|
-
await this.client.set(
|
|
63
|
-
key,
|
|
64
|
-
value);
|
|
65
|
-
}
|
|
66
|
-
catch(error) {
|
|
67
|
-
console.error("Error", error);
|
|
68
|
-
reject(error)
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (options && options.callback) {
|
|
72
|
-
options.callback();
|
|
73
|
-
}
|
|
74
|
-
//console.log("resolving...", key);
|
|
75
|
-
return resolve();
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async incr(key) {
|
|
80
|
-
// console.log("incr key:", key)
|
|
81
|
-
return new Promise( async (resolve, reject) => {
|
|
82
|
-
try {
|
|
83
|
-
// console.log("incr here...key", key)
|
|
84
|
-
await this.client.incr(key);
|
|
85
|
-
}
|
|
86
|
-
catch(error) {
|
|
87
|
-
console.error("Error on incr:", error);
|
|
88
|
-
reject(error)
|
|
89
|
-
}
|
|
90
|
-
return resolve();
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async hset(dict_key, key, value, options) {
|
|
95
|
-
//console.log("hsetting dict_key key value", dict_key, key, value)
|
|
96
|
-
return new Promise( async (resolve, reject) => {
|
|
97
|
-
if (options && options.EX) {
|
|
98
|
-
//console.log("expires:", options.EX)
|
|
99
|
-
try {
|
|
100
|
-
await this.client.hset(
|
|
101
|
-
dict_key,
|
|
102
|
-
key,
|
|
103
|
-
value,
|
|
104
|
-
'EX', options.EX);
|
|
105
|
-
}
|
|
106
|
-
catch(error) {
|
|
107
|
-
reject(error)
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
try {
|
|
112
|
-
//console.log("setting here...key", key, value)
|
|
113
|
-
await this.client.hset(
|
|
114
|
-
dict_key,
|
|
115
|
-
key,
|
|
116
|
-
value);
|
|
117
|
-
}
|
|
118
|
-
catch(error) {
|
|
119
|
-
console.error("Error", error);
|
|
120
|
-
reject(error)
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (options && options.callback) {
|
|
124
|
-
options.callback();
|
|
125
|
-
}
|
|
126
|
-
return resolve();
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
async hdel(dict_key, key, options) {
|
|
131
|
-
//console.log("hsetting dict_key key value", dict_key, key, value)
|
|
132
|
-
return new Promise( async (resolve, reject) => {
|
|
133
|
-
if (options && options.EX) {
|
|
134
|
-
//console.log("expires:", options.EX)
|
|
135
|
-
try {
|
|
136
|
-
await this.client.hdel(
|
|
137
|
-
dict_key,
|
|
138
|
-
key,
|
|
139
|
-
'EX', options.EX);
|
|
140
|
-
}
|
|
141
|
-
catch(error) {
|
|
142
|
-
reject(error)
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
try {
|
|
147
|
-
//console.log("setting here...key", key, value)
|
|
148
|
-
await this.client.hdel(
|
|
149
|
-
dict_key,
|
|
150
|
-
key);
|
|
151
|
-
}
|
|
152
|
-
catch(error) {
|
|
153
|
-
console.error("Error", error);
|
|
154
|
-
reject(error);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
if (options && options.callback) {
|
|
158
|
-
options.callback();
|
|
159
|
-
}
|
|
160
|
-
return resolve();
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
async setJSON(key, value, options) {
|
|
165
|
-
const _string = JSON.stringify(value);
|
|
166
|
-
return await this.set(key, _string, options);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
async get(key, callback) {
|
|
170
|
-
//console.log("getting key", key)
|
|
171
|
-
return new Promise( async (resolve, reject) => {
|
|
172
|
-
this.client.get(key, (err, value) => {
|
|
173
|
-
if (err) {
|
|
174
|
-
reject(err);
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
if (callback) {
|
|
178
|
-
callback(value);
|
|
179
|
-
}
|
|
180
|
-
return resolve(value);
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
async hgetall(dict_key, callback) {
|
|
187
|
-
//console.log("hgetting dics", dict_key);
|
|
188
|
-
return new Promise( async (resolve, reject) => {
|
|
189
|
-
this.client.hgetall(dict_key, (err, value) => {
|
|
190
|
-
if (err) {
|
|
191
|
-
reject(err);
|
|
192
|
-
if (callback) {
|
|
193
|
-
callback(err, null);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
if (callback) {
|
|
198
|
-
callback(null, value);
|
|
199
|
-
}
|
|
200
|
-
resolve(value);
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
async hget(dict_key, key, callback) {
|
|
207
|
-
//console.log("hgetting dics", dict_key);
|
|
208
|
-
return new Promise( async (resolve, reject) => {
|
|
209
|
-
this.client.hget(dict_key, key, (err, value) => {
|
|
210
|
-
if (err) {
|
|
211
|
-
reject(err);
|
|
212
|
-
if (callback) {
|
|
213
|
-
callback(err, null);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
if (callback) {
|
|
218
|
-
callback(null, value);
|
|
219
|
-
}
|
|
220
|
-
resolve(value);
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
async getJSON(key, callback) {
|
|
227
|
-
const value = await this.get(key);
|
|
228
|
-
return JSON.parse(value);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
async del(key, callback) {
|
|
232
|
-
return new Promise( async (resolve, reject) => {
|
|
233
|
-
await this.client.del(key);
|
|
234
|
-
if (callback) {
|
|
235
|
-
callback();
|
|
236
|
-
}
|
|
237
|
-
return resolve();
|
|
238
|
-
})
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
module.exports = { TdCache };
|