@tiledesk/tiledesk-tybot-connector 2.0.12-rc5 → 2.0.12-rc6
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/ExtApi.js +1 -8
- package/ExtUtil.js +5 -6
- 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/index.js +11 -23
- package/package.json +1 -1
- package/services/AIService.js +1 -1
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +10 -10
- 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/DirAddKbContent.js +333 -0
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirFlowLog.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +36 -54
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +1 -2
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +7 -9
- package/tiledeskChatbotPlugs/directives/DirIntent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirMake.js +1 -15
- package/tiledeskChatbotPlugs/directives/DirMessage.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirReply.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +8 -10
- package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +1 -15
- package/tiledeskChatbotPlugs/directives/Directives.js +1 -0
- package/utils/TiledeskChatbotUtil.js +14 -28
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
2
2
|
const { DirIntent } = require('./DirIntent');
|
|
3
3
|
const ms = require('minimist-string');
|
|
4
|
+
const winston = require('../../utils/winston');
|
|
4
5
|
|
|
5
6
|
class DirIfOpenHours {
|
|
6
7
|
|
|
@@ -26,9 +27,6 @@ class DirIfOpenHours {
|
|
|
26
27
|
let params;
|
|
27
28
|
params = this.parseParams(directive.parameter);
|
|
28
29
|
if (!params.trueIntent && !params.falseIntent) {
|
|
29
|
-
if (this.log) {
|
|
30
|
-
console.log("missing both params.trueIntent & params.falseIntent");
|
|
31
|
-
}
|
|
32
30
|
callback();
|
|
33
31
|
return;
|
|
34
32
|
}
|
|
@@ -60,14 +58,14 @@ class DirIfOpenHours {
|
|
|
60
58
|
if (falseIntent && falseIntent.trim() === "") {
|
|
61
59
|
falseIntent = null;
|
|
62
60
|
}
|
|
63
|
-
|
|
61
|
+
winston.verbose("(DirIfOpenHours) Action:", action);
|
|
64
62
|
if (!trueIntent && !falseIntent) {
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
winston.error("(DirIfOpenHours) Error: missing both action.trueIntent & action.falseIntent");
|
|
64
|
+
callback();
|
|
67
65
|
return;
|
|
68
66
|
}
|
|
69
67
|
this.tdClient.openNow((err, result) => {
|
|
70
|
-
|
|
68
|
+
winston.error("(DirIfOpenHours) openNow():", result)
|
|
71
69
|
if (err) {
|
|
72
70
|
console.error("*** DirIfOpenHours Error:", err);
|
|
73
71
|
callback();
|
|
@@ -75,7 +73,7 @@ class DirIfOpenHours {
|
|
|
75
73
|
else if (result && result.isopen) {
|
|
76
74
|
if (trueIntent) {
|
|
77
75
|
let intentDirective = DirIntent.intentDirectiveFor(trueIntent);
|
|
78
|
-
|
|
76
|
+
winston.debug("(DirIfOpenHours) (openHours) => trueIntent ");
|
|
79
77
|
this.intentDir.execute(intentDirective, () => {
|
|
80
78
|
callback(stopOnConditionMet);
|
|
81
79
|
});
|
|
@@ -87,7 +85,7 @@ class DirIfOpenHours {
|
|
|
87
85
|
}
|
|
88
86
|
else if (falseIntent) {
|
|
89
87
|
let intentDirective = DirIntent.intentDirectiveFor(falseIntent);
|
|
90
|
-
|
|
88
|
+
winston.debug("(DirIfOpenHours) (openHours) => falseIntent ");
|
|
91
89
|
this.intentDir.execute(intentDirective, () => {
|
|
92
90
|
callback(stopOnConditionMet);
|
|
93
91
|
});
|
|
@@ -204,21 +204,7 @@ class DirMake {
|
|
|
204
204
|
|
|
205
205
|
})
|
|
206
206
|
.catch((err) => {
|
|
207
|
-
|
|
208
|
-
// FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - START
|
|
209
|
-
let cache = [];
|
|
210
|
-
let error_log = JSON.stringify(err, function (key, value) { // try to use a separate function
|
|
211
|
-
if (typeof value === 'object' && value != null) {
|
|
212
|
-
if (cache.indexOf(value) !== -1) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
cache.push(value);
|
|
216
|
-
}
|
|
217
|
-
return value;
|
|
218
|
-
});
|
|
219
|
-
winston.error("(DirMake) An error occurred: ", error_log);
|
|
220
|
-
// FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END;
|
|
221
|
-
}
|
|
207
|
+
// FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END;
|
|
222
208
|
if (callback) {
|
|
223
209
|
let status = 1000;
|
|
224
210
|
let cache = [];
|
|
@@ -16,7 +16,6 @@ class DirMessage {
|
|
|
16
16
|
this.requestId = context.requestId;
|
|
17
17
|
this.tdcache = this.context.tdcache;
|
|
18
18
|
this.token = context.token;
|
|
19
|
-
this.log = this.context.log;
|
|
20
19
|
this.supportRequest = this.context.supportRequest
|
|
21
20
|
|
|
22
21
|
this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___", log: this.log });
|
|
@@ -84,7 +84,7 @@ class DirReply {
|
|
|
84
84
|
let command = commands[i];
|
|
85
85
|
if (command.type === 'message' && command.message && command.message.text) {
|
|
86
86
|
command.message.text = filler.fill(command.message.text, requestAttributes);
|
|
87
|
-
TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes
|
|
87
|
+
TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes);
|
|
88
88
|
winston.debug("DirReply command filled: " + command.message.text);
|
|
89
89
|
}
|
|
90
90
|
if (command.type === 'settings' && command.settings) {
|
|
@@ -21,6 +21,7 @@ class DirReplyV2 {
|
|
|
21
21
|
this.requestId = context.requestId;
|
|
22
22
|
this.token = context.token;
|
|
23
23
|
this.tdcache = context.tdcache;
|
|
24
|
+
this.intentDir = new DirIntent(context);
|
|
24
25
|
this.chatbot = context.chatbot;
|
|
25
26
|
this.reply = context.reply;
|
|
26
27
|
this.originalMessage = context.message;
|
|
@@ -59,11 +60,10 @@ class DirReplyV2 {
|
|
|
59
60
|
const message = action;
|
|
60
61
|
|
|
61
62
|
let current; // debug only
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
current = message.attributes.commands[1].message.text
|
|
65
|
-
}
|
|
63
|
+
if (message.attributes.commands[1].message.text) {
|
|
64
|
+
current = message.attributes.commands[1].message.text
|
|
66
65
|
}
|
|
66
|
+
|
|
67
67
|
let must_stop = false;
|
|
68
68
|
// fill
|
|
69
69
|
let requestAttributes = null;
|
|
@@ -72,11 +72,9 @@ class DirReplyV2 {
|
|
|
72
72
|
await TiledeskChatbot.allParametersStatic(
|
|
73
73
|
this.tdcache, this.requestId
|
|
74
74
|
);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
}
|
|
75
|
+
// for (const [key, value] of Object.entries(requestAttributes)) {
|
|
76
|
+
// const value_type = typeof value;
|
|
77
|
+
// }
|
|
80
78
|
|
|
81
79
|
TiledeskChatbotUtil.replaceJSONButtons(message, requestAttributes);
|
|
82
80
|
|
|
@@ -195,7 +193,7 @@ class DirReplyV2 {
|
|
|
195
193
|
let command = commands[i];
|
|
196
194
|
if (command.type === 'message' && command.message && command.message.text) {
|
|
197
195
|
command.message.text = filler.fill(command.message.text, requestAttributes);
|
|
198
|
-
TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes
|
|
196
|
+
TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes);
|
|
199
197
|
}
|
|
200
198
|
}
|
|
201
199
|
}
|
|
@@ -205,9 +205,7 @@ class DirSetAttributeV2 {
|
|
|
205
205
|
httpUtils.request(
|
|
206
206
|
HTTPREQUEST, async (err, resbody) => {
|
|
207
207
|
if (err) {
|
|
208
|
-
|
|
209
|
-
winston.error("(DirSetAttributeV2) persistOnTiledesk() error: ", err);
|
|
210
|
-
}
|
|
208
|
+
winston.error("(DirSetAttributeV2) persistOnTiledesk() error: ", err);
|
|
211
209
|
} else {
|
|
212
210
|
winston.debug("(DirSetAttributeV2) Attributes saved: ", resbody);
|
|
213
211
|
}
|
|
@@ -317,21 +317,7 @@ class DirWebRequestV2 {
|
|
|
317
317
|
}
|
|
318
318
|
})
|
|
319
319
|
.catch((err) => {
|
|
320
|
-
|
|
321
|
-
// FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - START
|
|
322
|
-
let cache = [];
|
|
323
|
-
let error_log = JSON.stringify(err, function (key, value) { // try to use a separate function
|
|
324
|
-
if (typeof value === 'object' && value != null) {
|
|
325
|
-
if (cache.indexOf(value) !== -1) {
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
cache.push(value);
|
|
329
|
-
}
|
|
330
|
-
return value;
|
|
331
|
-
});
|
|
332
|
-
winston.error("(DirWebRequestv2) An error occurred: ", error_log);
|
|
333
|
-
// FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END
|
|
334
|
-
}
|
|
320
|
+
// FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END
|
|
335
321
|
if (callback) {
|
|
336
322
|
let status = 1000;
|
|
337
323
|
let cache = [];
|
|
@@ -60,6 +60,7 @@ class Directives {
|
|
|
60
60
|
static ADD_TAGS = 'add_tags'
|
|
61
61
|
static WEB_RESPONSE = "web_response";
|
|
62
62
|
static FLOW_LOG = "flow_log";
|
|
63
|
+
static ADD_KB_CONTENT = "add_kb_content";
|
|
63
64
|
|
|
64
65
|
// static WHEN_ONLINE_MOVE_TO_AGENT = "whenonlinemovetoagent"; // DEPRECATED?
|
|
65
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
|
|
|
@@ -520,7 +520,7 @@ class TiledeskChatbotUtil {
|
|
|
520
520
|
static async updateRequestAttributes(chatbot, chatbotToken, message, projectId, requestId) {
|
|
521
521
|
// update request context
|
|
522
522
|
try {
|
|
523
|
-
|
|
523
|
+
winston.debug("Updating request variables. Message:", message);
|
|
524
524
|
const messageId = message._id;
|
|
525
525
|
const chat_url = `https://panel.tiledesk.com/v3/dashboard/#/project/${projectId}/wsrequest/${requestId}/messages`
|
|
526
526
|
|
|
@@ -591,12 +591,12 @@ class TiledeskChatbotUtil {
|
|
|
591
591
|
}
|
|
592
592
|
|
|
593
593
|
if (message && message.request && message.request.lead) {
|
|
594
|
-
|
|
594
|
+
winston.debug("(TiledeskChatbotUtil) Lead found with email: " + message.request.lead.email + " and lead.fullname " + message.request.lead.fullname);
|
|
595
595
|
let currentLeadEmail = await chatbot.getParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY);
|
|
596
|
-
|
|
596
|
+
winston.debug("(TiledeskChatbotUtil) You lead email from attributes: " + currentLeadEmail);
|
|
597
597
|
if (message.request.lead.email && !currentLeadEmail) {
|
|
598
598
|
// worth saving
|
|
599
|
-
|
|
599
|
+
winston.debug("(TiledeskChatbotUtil) worth saving email");
|
|
600
600
|
try {
|
|
601
601
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY, message.request.lead.email);
|
|
602
602
|
}
|
|
@@ -685,10 +685,10 @@ class TiledeskChatbotUtil {
|
|
|
685
685
|
message.attributes = {}
|
|
686
686
|
}
|
|
687
687
|
message.attributes.payload = { ...message.attributes.payload, ...message.request.attributes.payload }
|
|
688
|
-
|
|
688
|
+
winston.debug("(TiledeskChatbotUtil) Forced Set message.attributes.payload ", message.attributes.payload);
|
|
689
689
|
}
|
|
690
690
|
if (message.attributes) {
|
|
691
|
-
|
|
691
|
+
winston.debug("(TiledeskChatbotUtil) Ok message.attributes ", message.attributes);
|
|
692
692
|
|
|
693
693
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_ID_KEY, message.attributes.requester_id);
|
|
694
694
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_IP_ADDRESS_KEY, message.attributes.ipAddress);
|
|
@@ -722,12 +722,12 @@ class TiledeskChatbotUtil {
|
|
|
722
722
|
|
|
723
723
|
|
|
724
724
|
const _bot = chatbot.bot; // aka FaqKB
|
|
725
|
-
|
|
725
|
+
winston.debug("(TiledeskChatbotUtil) Adding Globals to context: ", _bot);
|
|
726
726
|
|
|
727
727
|
if (_bot.attributes && _bot.attributes.globals) {
|
|
728
|
-
|
|
728
|
+
winston.error("(TiledeskChatbotUtil) Got Globals: ", _bot.attributes.globals);
|
|
729
729
|
_bot.attributes.globals.forEach(async (global_var) => {
|
|
730
|
-
|
|
730
|
+
winston.error("(TiledeskChatbotUtil) Adding global: " + global_var.key + " value: " + global_var.value);
|
|
731
731
|
await chatbot.addParameter(global_var.key, global_var.value);
|
|
732
732
|
});
|
|
733
733
|
}
|
|
@@ -740,20 +740,6 @@ class TiledeskChatbotUtil {
|
|
|
740
740
|
// }
|
|
741
741
|
// );
|
|
742
742
|
|
|
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
743
|
} catch(error) {
|
|
758
744
|
winston.error("(TiledeskChatbotUtil) updateRequestAttributes Error: ", error);
|
|
759
745
|
process.exit(1)
|