@tiledesk/tiledesk-tybot-connector 0.5.0 → 2.0.0
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 +4 -83
- package/ExtUtil.js +0 -1
- package/Logger.js +105 -0
- package/TdCache.js +5 -3
- package/TiledeskClientTest.js +5 -28
- package/TiledeskExpression.js +6 -47
- package/{models → engine}/IntentForm.js +30 -44
- package/{models → engine}/IntentsMachineFactory.js +5 -4
- package/{models → engine}/MongodbBotsDataSource.js +31 -55
- package/{models → engine}/MongodbIntentsMachine.js +6 -5
- package/{models → engine}/TiledeskChatbot.js +82 -259
- package/{models → engine}/TiledeskChatbotConst.js +9 -0
- package/{models → engine}/TiledeskIntentsMachine.js +5 -15
- package/{models → engine/mock}/MockBotsDataSource.js +3 -19
- package/{models → engine/mock}/MockTdCache.js +0 -9
- package/index.js +103 -380
- package/logs/app.log +12723 -277
- package/logs/app1.log +62258 -0
- package/logs/app2.log +46280 -0
- package/logs/app3.log +31686 -0
- package/logs/app4.log +46163 -0
- package/logs/app5.log +33173 -0
- package/models/faq.js +2 -5
- package/package.json +5 -2
- package/{TiledeskServices → services}/AIService.js +4 -3
- package/{models/faqKbService.js → services/FaqKbService.js} +1 -2
- package/{models/faqService.js → services/FaqService.js} +4 -3
- package/services/IntegrationService.js +43 -0
- package/services/TilebotService.js +47 -0
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +49 -135
- package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +8 -14
- package/tiledeskChatbotPlugs/Filler.js +0 -1
- package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +12 -20
- package/tiledeskChatbotPlugs/MessagePipeline.js +5 -15
- package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +4 -13
- package/tiledeskChatbotPlugs/TiledeskRequestVariables.js +1 -1
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +21 -89
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirSetAttribute.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +23 -140
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +42 -128
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +37 -127
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +52 -145
- package/tiledeskChatbotPlugs/directives/DirAssign.js +12 -23
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +16 -12
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +56 -198
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +41 -101
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +9 -19
- package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirClose.js +4 -2
- package/tiledeskChatbotPlugs/directives/DirCode.js +16 -23
- package/tiledeskChatbotPlugs/directives/DirCondition.js +19 -25
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -82
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +10 -22
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +34 -89
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +17 -22
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +8 -8
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -12
- package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +2 -6
- package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -4
- package/tiledeskChatbotPlugs/directives/DirForm.js +17 -24
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +49 -139
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +8 -53
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +31 -91
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +24 -78
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -68
- package/tiledeskChatbotPlugs/directives/DirIntent.js +6 -100
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +15 -14
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
- package/tiledeskChatbotPlugs/directives/DirMake.js +21 -53
- package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +8 -87
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +6 -4
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +6 -4
- package/tiledeskChatbotPlugs/directives/DirQapla.js +26 -120
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +11 -19
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +5 -2
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +12 -58
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +11 -57
- package/tiledeskChatbotPlugs/directives/DirReply.js +36 -30
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +30 -72
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +9 -10
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +15 -40
- package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +8 -5
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +25 -113
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
- package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
- package/tiledeskChatbotPlugs/directives/DirWait.js +5 -6
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +14 -49
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +22 -77
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +11 -14
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +13 -42
- package/tiledeskChatbotPlugs/directives/Directives.js +0 -3
- package/utils/HttpUtils.js +128 -0
- package/{models → utils}/TiledeskChatbotUtil.js +164 -234
- package/utils/winston.js +42 -0
- package/TiledeskServices/utils.js +0 -99
- /package/{models → engine/mock}/MockIntentsMachine.js +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { TiledeskChatbotUtil } = require('@tiledesk/tiledesk-chatbot-util');
|
|
2
|
-
const { TiledeskChatbot } = require('../
|
|
2
|
+
const { TiledeskChatbot } = require('../engine/TiledeskChatbot.js');
|
|
3
3
|
const { Filler } = require('./Filler');
|
|
4
|
+
const winston = require('../utils/winston.js');
|
|
4
5
|
|
|
5
6
|
class FillParamsChatbotPlug {
|
|
6
7
|
|
|
@@ -20,17 +21,16 @@ class FillParamsChatbotPlug {
|
|
|
20
21
|
let message = pipeline.message;
|
|
21
22
|
if (message) {
|
|
22
23
|
if (message.attributes && (message.attributes.fillParams == undefined || message.attributes.fillParams == false)) { // defaults to disabled
|
|
23
|
-
|
|
24
|
+
winston.verbose("(FillParamsChatbotPlug) fillParams disabled.");
|
|
24
25
|
pipeline.nextplug();
|
|
25
26
|
return;
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
28
|
+
|
|
29
|
+
winston.verbose("(FillParamsChatbotPlug) fillParams: true");
|
|
30
30
|
const requestId = this.request.request_id;
|
|
31
|
-
|
|
31
|
+
winston.debug("(FillParamsChatbotPlug) all_parameters of requestId: " + requestId)
|
|
32
32
|
const all_parameters = await TiledeskChatbot.allParametersStatic(this.tdcache, requestId);
|
|
33
|
-
|
|
33
|
+
winston.debug("(FillParamsChatbotPlug) Got parameters: " + all_parameters);
|
|
34
34
|
if (!all_parameters) {
|
|
35
35
|
pipeline.nextplug();
|
|
36
36
|
return;
|
|
@@ -40,7 +40,6 @@ class FillParamsChatbotPlug {
|
|
|
40
40
|
const filled_message_text = filler.fill(message.text, all_parameters);
|
|
41
41
|
// const filled_message_text = this.fillWithRequestParams(message.text, all_parameters);
|
|
42
42
|
message.text = filled_message_text;
|
|
43
|
-
//console.log("message filled_message_text:", message)
|
|
44
43
|
if (!message.attributes) {
|
|
45
44
|
message.attributes = {}
|
|
46
45
|
}
|
|
@@ -54,7 +53,6 @@ class FillParamsChatbotPlug {
|
|
|
54
53
|
|
|
55
54
|
if (message.attributes && message.attributes.commands) {
|
|
56
55
|
let commands = message.attributes.commands;
|
|
57
|
-
// if (this.log) {console.log("commands for fillMessage:", JSON.stringify(commands));}
|
|
58
56
|
if (commands.length > 1) {
|
|
59
57
|
for (let i = 0; i < commands.length; i++) {
|
|
60
58
|
if (commands[i].type === 'message' && commands[i].message && commands[i].message.text) {
|
|
@@ -68,26 +66,22 @@ class FillParamsChatbotPlug {
|
|
|
68
66
|
pipeline.nextplug();
|
|
69
67
|
}
|
|
70
68
|
else {
|
|
71
|
-
|
|
69
|
+
winston.debug("(FillParamsChatbotPlug) Fillparams. No message.");
|
|
72
70
|
pipeline.nextplug();
|
|
73
71
|
}
|
|
74
72
|
|
|
75
73
|
}
|
|
76
74
|
|
|
77
75
|
// fillWithRequestParams(message_text, all_parameters) {
|
|
78
|
-
// if (this.log) {console.log("collected parameters:", JSON.stringify(all_parameters));}
|
|
79
76
|
// if (!message_text) {
|
|
80
|
-
// if (this.log) {console.log("fillWithRequestParams() Can't fill. message_text is null");}
|
|
81
77
|
// return;
|
|
82
78
|
// }
|
|
83
79
|
// if (all_parameters) {
|
|
84
80
|
// for (const [key, value] of Object.entries(all_parameters)) {
|
|
85
81
|
// // const value = all_parameters[key];
|
|
86
82
|
// const value_type = typeof value;
|
|
87
|
-
// if (this.log) {console.log("checking parameter:", key, "value:", value, "type:", value_type)}
|
|
88
83
|
// message_text = message_text.replace(new RegExp("(\\$\\{" + key + "\\})", 'i'), value);
|
|
89
84
|
// }
|
|
90
|
-
// if (this.log) {console.log("final:", message_text);}
|
|
91
85
|
// }
|
|
92
86
|
// return message_text;
|
|
93
87
|
// }
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { TiledeskChatbotUtil } = require('@tiledesk/tiledesk-chatbot-util');
|
|
2
|
+
const winston = require('../utils/winston');
|
|
2
3
|
|
|
3
4
|
class MarkbotChatbotPlug {
|
|
4
5
|
|
|
@@ -15,16 +16,14 @@ class MarkbotChatbotPlug {
|
|
|
15
16
|
|
|
16
17
|
exec(pipeline) {
|
|
17
18
|
let message = pipeline.message;
|
|
18
|
-
// console.log("markbot on message", message)
|
|
19
19
|
if (message.attributes && (message.attributes.markbot == undefined || message.attributes.markbot == false)) { // defaults to disabled
|
|
20
|
-
|
|
20
|
+
winston.verbose("(MarkbotChatbotPlug) Markbot disabled")
|
|
21
21
|
pipeline.nextplug();
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
// console.log("message.text", message.text)
|
|
26
25
|
if (!message.text) {
|
|
27
|
-
|
|
26
|
+
winston.verbose("(MarkbotChatbotPlug) No message.text (no content). Skipping markbot");
|
|
28
27
|
pipeline.message = null;
|
|
29
28
|
pipeline.nextplug();
|
|
30
29
|
return;
|
|
@@ -34,11 +33,9 @@ class MarkbotChatbotPlug {
|
|
|
34
33
|
if (message.attributes && message.attributes.commands) {
|
|
35
34
|
commands = message.attributes.commands;
|
|
36
35
|
}
|
|
37
|
-
|
|
38
|
-
// console.log("message.text:", incoming_message_text);
|
|
39
|
-
// console.log("message commands:", commands)
|
|
36
|
+
|
|
40
37
|
if (incoming_message_text === "" && !commands) {
|
|
41
|
-
|
|
38
|
+
winston.verbose("(MarkbotChatbotPlug) Message with no content. Ignoring");
|
|
42
39
|
pipeline.message = null;
|
|
43
40
|
pipeline.nextplug();
|
|
44
41
|
return;
|
|
@@ -48,9 +45,9 @@ class MarkbotChatbotPlug {
|
|
|
48
45
|
message.attributes = {}
|
|
49
46
|
}
|
|
50
47
|
if (incoming_message_text !== "") {
|
|
51
|
-
|
|
48
|
+
winston.verbose("(MarkbotChatbotPlug) markbotting main message...");
|
|
52
49
|
let parsed_reply = TiledeskChatbotUtil.parseReply(incoming_message_text);
|
|
53
|
-
|
|
50
|
+
winston.debug("(MarkbotChatbotPlug) parsed_reply", parsed_reply);
|
|
54
51
|
if (parsed_reply) {
|
|
55
52
|
message.text = parsed_reply.message.text;
|
|
56
53
|
if (!message.type || message.type === "text") {
|
|
@@ -61,7 +58,7 @@ class MarkbotChatbotPlug {
|
|
|
61
58
|
// if already present, do not modify metadata
|
|
62
59
|
message.metadata = parsed_reply.message.metadata;
|
|
63
60
|
}
|
|
64
|
-
|
|
61
|
+
winston.debug("(MarkbotChatbotPlug) parsed_reply.message.attributes", parsed_reply.message.attributes);
|
|
65
62
|
//this.mergeCurrentMessageButtons(message, parsed_reply);
|
|
66
63
|
if (parsed_reply.message.attributes) {
|
|
67
64
|
for(const [key, value] of Object.entries(parsed_reply.message.attributes)) {
|
|
@@ -71,30 +68,25 @@ class MarkbotChatbotPlug {
|
|
|
71
68
|
}
|
|
72
69
|
}
|
|
73
70
|
else {
|
|
74
|
-
|
|
71
|
+
winston.verbose("(MarkbotChatbotPlug) no message text: " + message.text);
|
|
75
72
|
}
|
|
76
73
|
|
|
77
74
|
// let commands = null;
|
|
78
75
|
// if (message.attributes && message.attributes.commands) {
|
|
79
76
|
// commands = message.attributes.commands;
|
|
80
77
|
if (commands) {
|
|
81
|
-
|
|
78
|
+
winston.debug("(MarkbotChatbotPlug) commands for markbot:", commands);
|
|
82
79
|
if (commands.length > 1) {
|
|
83
80
|
for (let i = 0; i < commands.length; i++) {
|
|
84
81
|
if (commands[i].type === 'message' && commands[i].message && commands[i].message.text) {
|
|
85
82
|
let parsed_reply = TiledeskChatbotUtil.parseReply(commands[i].message.text);
|
|
86
|
-
//console.log("PARSED***", parsed_reply);
|
|
87
83
|
commands[i].message = parsed_reply.message;
|
|
88
84
|
}
|
|
89
85
|
}
|
|
90
86
|
}
|
|
91
87
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
// }
|
|
95
|
-
// if (this.log) {console.log("Message out of Markbot:", JSON.stringify(message));}
|
|
96
|
-
pipeline.nextplug();
|
|
97
|
-
|
|
88
|
+
|
|
89
|
+
pipeline.nextplug();
|
|
98
90
|
}
|
|
99
91
|
|
|
100
92
|
/*mergeCurrentMessageButtons(message, parsed_reply) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const winston = require('../utils/winston');
|
|
2
|
+
|
|
1
3
|
class MessagePipeline {
|
|
2
4
|
|
|
3
5
|
/**
|
|
@@ -29,24 +31,18 @@ class MessagePipeline {
|
|
|
29
31
|
/*
|
|
30
32
|
exec(completionCallback) {
|
|
31
33
|
this.completionPromise = new Promise((resolve, reject) => {
|
|
32
|
-
console.log("The context", context)
|
|
33
34
|
const plug = this.nextplug();
|
|
34
35
|
if (!plug) {
|
|
35
|
-
console.log("NO PLUGS!");
|
|
36
36
|
if (completionCallback) {
|
|
37
|
-
console.log("completionCallback found.");
|
|
38
37
|
completionCallback();
|
|
39
38
|
}
|
|
40
|
-
console.log("Resolving...", this.message);
|
|
41
39
|
return resolve();
|
|
42
40
|
}
|
|
43
41
|
else {
|
|
44
42
|
plug.exec(this, () => {
|
|
45
43
|
if (completionCallback) {
|
|
46
|
-
console.log("completionCallback found.");
|
|
47
44
|
completionCallback();
|
|
48
45
|
}
|
|
49
|
-
console.log("Resolving...", this.message);
|
|
50
46
|
return resolve();
|
|
51
47
|
});
|
|
52
48
|
}
|
|
@@ -58,14 +54,10 @@ exec(completionCallback) {
|
|
|
58
54
|
/*execOn(message, context, completionCallback) {
|
|
59
55
|
return new Promise((resolve, reject) => {
|
|
60
56
|
this.message = message;
|
|
61
|
-
console.log("The context", context)
|
|
62
57
|
this.process(this.nextplug(), context, (message) => {
|
|
63
|
-
console.log("All plugs processed.", message)
|
|
64
58
|
if (completionCallback) {
|
|
65
|
-
console.log("completionCallback found.")
|
|
66
59
|
completionCallback(message);
|
|
67
60
|
}
|
|
68
|
-
console.log("Resolving...", message)
|
|
69
61
|
return resolve(message);
|
|
70
62
|
});
|
|
71
63
|
});
|
|
@@ -84,27 +76,25 @@ exec(completionCallback) {
|
|
|
84
76
|
|
|
85
77
|
nextplug() {
|
|
86
78
|
this.counter += 1;
|
|
87
|
-
|
|
79
|
+
winston.verbose("(MessagePipeline) processing plug: " + this.coounter);
|
|
88
80
|
if (this.counter < this.plugs.length) {
|
|
89
|
-
|
|
81
|
+
winston.verbose("(MessagePipeline) Still plugs...")
|
|
90
82
|
let nextp = this.plugs[this.counter];
|
|
91
83
|
nextp.exec(this);
|
|
92
84
|
}
|
|
93
85
|
else {
|
|
94
|
-
|
|
86
|
+
winston.verbose("(MessagePipeline) no more plugs");
|
|
95
87
|
this.resolve(this.message);
|
|
96
88
|
}
|
|
97
89
|
}
|
|
98
90
|
/*
|
|
99
91
|
nextplug() {
|
|
100
92
|
this.counter += 1;
|
|
101
|
-
console.log(`processing plug[${this.counter}]`);
|
|
102
93
|
if (this.counter < this.plugs.length) {
|
|
103
94
|
let nextp = this.plugs[this.counter];
|
|
104
95
|
return nextp;
|
|
105
96
|
}
|
|
106
97
|
else {
|
|
107
|
-
console.log("no more plugs");
|
|
108
98
|
return null;
|
|
109
99
|
}
|
|
110
100
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { TiledeskChatbotUtil } = require('@tiledesk/tiledesk-chatbot-util');
|
|
2
|
+
const winston = require('../utils/winston')
|
|
2
3
|
|
|
3
4
|
class SplitsChatbotPlug {
|
|
4
5
|
|
|
@@ -15,11 +16,8 @@ class SplitsChatbotPlug {
|
|
|
15
16
|
|
|
16
17
|
exec(pipeline) {
|
|
17
18
|
let message = pipeline.message;
|
|
18
|
-
// console.log("Splits disabled on message?", message);
|
|
19
19
|
if (message.attributes && (message.attributes.splits == undefined || message.attributes.splits == false)) { // defaults to disabled
|
|
20
|
-
|
|
21
|
-
console.log("Splits disabled.");
|
|
22
|
-
}
|
|
20
|
+
winston.verbose("(SplitsChatbotPlug) Splits disabled.");
|
|
23
21
|
pipeline.nextplug();
|
|
24
22
|
return;
|
|
25
23
|
}
|
|
@@ -27,24 +25,17 @@ class SplitsChatbotPlug {
|
|
|
27
25
|
pipeline.nextplug();
|
|
28
26
|
return;
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
console.log("Splitting...");
|
|
32
|
-
}
|
|
28
|
+
winston.verbose("(SplitsChatbotPlug) Splitting...");
|
|
33
29
|
// if splits found just a attributs.commands payload is attached
|
|
34
30
|
// to the original json message with split commands
|
|
35
31
|
let commands = TiledeskChatbotUtil.splitPars(message.text);
|
|
36
|
-
|
|
37
|
-
console.log("commands", JSON.stringify(commands))
|
|
38
|
-
}
|
|
32
|
+
winston.debug("(SplitsChatbotPlug) commands", commands)
|
|
39
33
|
if (commands && commands.length > 1) {
|
|
40
34
|
if (!message.attributes) {
|
|
41
35
|
message.attributes = {}
|
|
42
36
|
}
|
|
43
37
|
message.attributes.commands = commands;
|
|
44
38
|
}
|
|
45
|
-
if (this.log) {
|
|
46
|
-
// console.log("Message out of Splits plugin:", JSON.stringify(message));
|
|
47
|
-
}
|
|
48
39
|
pipeline.nextplug();
|
|
49
40
|
}
|
|
50
41
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
let axios = require('axios');
|
|
2
|
+
const winston = require('../utils/winston');
|
|
2
3
|
|
|
3
4
|
class WebhookChatbotPlug {
|
|
4
5
|
|
|
@@ -12,32 +13,32 @@ class WebhookChatbotPlug {
|
|
|
12
13
|
exec(pipeline) {
|
|
13
14
|
let answer = pipeline.message;
|
|
14
15
|
let context = pipeline.context;
|
|
15
|
-
|
|
16
|
+
winston.verbose("(WebhookChatbotPlug) webhook" + answer.attributes.webhook);
|
|
16
17
|
if (answer.attributes && answer.attributes.webhook && answer.attributes.webhook === true) {
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
winston.debug("(WebhookChatbotPlug) Executing webhook url " + this.webhookurl);
|
|
19
|
+
winston.debug("(WebhookChatbotPlug) Executing webhook on context: ", context);
|
|
19
20
|
if (!this.validWebhookURL(this.webhookurl)) {
|
|
20
|
-
|
|
21
|
+
winston.error("(WebhookChatbotPlug) Error. Invalid webhook URL: " + this.webhookurl + " on context: " + JSON.stringify(context));
|
|
21
22
|
pipeline.nextplug();
|
|
22
23
|
return;
|
|
23
24
|
}
|
|
24
25
|
this.execWebhook(answer, context, this.webhookurl, (err, message_from_webhook) => {
|
|
25
|
-
|
|
26
|
+
winston.debug("(WebhookChatbotPlug) message_from_webhook:", message_from_webhook);
|
|
26
27
|
if (err) {
|
|
27
|
-
|
|
28
|
+
winston.error("(WebhookChatbotPlug) Error calling webhook:", this.webhookurl)
|
|
28
29
|
pipeline.nextplug();
|
|
29
30
|
}
|
|
30
31
|
else {
|
|
31
|
-
|
|
32
|
+
winston.debug("(WebhookChatbotPlug) Webhook successfully end:", message_from_webhook);
|
|
32
33
|
const pipeline_original_message = pipeline.message
|
|
33
|
-
|
|
34
|
+
winston.debug("(WebhookChatbotPlug) pipeline.message before webhook", pipeline.message);
|
|
34
35
|
|
|
35
36
|
// **** setting message from webhook,
|
|
36
37
|
// **** MERGING with original not overwritten data, manually
|
|
37
38
|
pipeline.message = message_from_webhook;
|
|
38
39
|
// restore on message the original intent_info, necessary FOR further processING the message in the plugs pipeline
|
|
39
40
|
if (pipeline.message && !pipeline.message.attributes) {
|
|
40
|
-
|
|
41
|
+
winston.debug("(WebhookChatbotPlug) !pipeline.message.attributes", pipeline.message.attributes);
|
|
41
42
|
pipeline.message.attributes = {};
|
|
42
43
|
}
|
|
43
44
|
pipeline.message.attributes.intent_info = pipeline_original_message.attributes.intent_info;
|
|
@@ -59,11 +60,11 @@ class WebhookChatbotPlug {
|
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
62
|
else {
|
|
62
|
-
|
|
63
|
+
winston.verbose("(WebhookChatbotPlug) No Webhook!");
|
|
63
64
|
pipeline.nextplug();
|
|
64
65
|
return;
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
+
winston.verbose("(WebhookChatbotPlug) Start processing webhook...");
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
validWebhookURL(webhookurl) {
|
|
@@ -74,10 +75,8 @@ class WebhookChatbotPlug {
|
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
execWebhook(reply_message, context, webhookurl, callback) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
console.log("WEBHOOK. on message", JSON.stringify(reply_message));
|
|
80
|
-
}
|
|
78
|
+
winston.debug("(WebhookChatbotPlug) Webhook on context ", context);
|
|
79
|
+
winston.debug("(WebhookChatbotPlug) WEBHOOK on message ", reply_message);
|
|
81
80
|
const HTTPREQUEST = {
|
|
82
81
|
url: webhookurl,
|
|
83
82
|
headers: {
|
|
@@ -92,7 +91,7 @@ class WebhookChatbotPlug {
|
|
|
92
91
|
HTTPREQUEST,
|
|
93
92
|
function(err, res) {
|
|
94
93
|
if (err || (res && res.status >= 400) || (res && !res.data)) {
|
|
95
|
-
|
|
94
|
+
winston.error("(WebhookChatbotPlug) An error occurred calling intent's webhook url: " + webhookurl);
|
|
96
95
|
if (callback) {
|
|
97
96
|
callback(reply_message);
|
|
98
97
|
}
|
|
@@ -104,72 +103,6 @@ class WebhookChatbotPlug {
|
|
|
104
103
|
}
|
|
105
104
|
}, this.log
|
|
106
105
|
);
|
|
107
|
-
|
|
108
|
-
/*
|
|
109
|
-
return request({
|
|
110
|
-
uri : webhookurl,
|
|
111
|
-
headers: {
|
|
112
|
-
'Content-Type' : 'application/json',
|
|
113
|
-
'User-Agent': 'tiledesk-bot',
|
|
114
|
-
'Origin': webhook_origin
|
|
115
|
-
//'x-hook-secret': s.secret
|
|
116
|
-
},
|
|
117
|
-
method: 'POST',
|
|
118
|
-
json: true,
|
|
119
|
-
body: {payload:{text: text, bot: bot, message: message, intent: faq}, token: token},
|
|
120
|
-
// }).then(response => {
|
|
121
|
-
}, function(err, response, json){
|
|
122
|
-
if (err) {
|
|
123
|
-
winston.error("Error from webhook reply of getParsedMessage. Return standard reply", err);
|
|
124
|
-
|
|
125
|
-
return resolve(messageReply);
|
|
126
|
-
|
|
127
|
-
// return error
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
if (response.statusCode >= 400) {
|
|
131
|
-
winston.verbose("The ChatBot webhook return error http status code. Return standard reply", response);
|
|
132
|
-
return resolve(messageReply);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (!json) { //the webhook return empty body
|
|
136
|
-
winston.verbose("The ChatBot webhook return no json. Return standard reply", response);
|
|
137
|
-
return resolve(messageReply);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
winston.debug("webhookurl repl_message ", response);
|
|
141
|
-
|
|
142
|
-
var text = undefined;
|
|
143
|
-
if(json && json.text===undefined) {
|
|
144
|
-
winston.verbose("webhookurl json is defined but text not. return standard reply",{json:json, response:response});
|
|
145
|
-
// text = 'Field text is not defined in the webhook respose of the faq with id: '+ faq._id+ ". Error: " + JSON.stringify(response);
|
|
146
|
-
return resolve(messageReply);
|
|
147
|
-
}else {
|
|
148
|
-
text = json.text;
|
|
149
|
-
}
|
|
150
|
-
winston.debug("webhookurl text: "+ text);
|
|
151
|
-
|
|
152
|
-
// // let cloned_message = Object.assign({}, messageReply);
|
|
153
|
-
// let cloned_message = message;
|
|
154
|
-
// winston.debug("cloned_message : ",cloned_message);
|
|
155
|
-
|
|
156
|
-
// if (json.attributes) {
|
|
157
|
-
// if (!cloned_message.attributes) {
|
|
158
|
-
// cloned_message.attributes = {}
|
|
159
|
-
// }
|
|
160
|
-
// winston.debug("ChatBot webhook json.attributes: ",json.attributes);
|
|
161
|
-
// for(const [key, value] of Object.entries(json.attributes)) {
|
|
162
|
-
// cloned_message.attributes[key] = value
|
|
163
|
-
// }
|
|
164
|
-
// }
|
|
165
|
-
|
|
166
|
-
// winston.debug("cloned_message after attributes: ",cloned_message);
|
|
167
|
-
|
|
168
|
-
that.parseMicrolanguage(text, message, bot, faq, true, json).then(function(bot_answer) {
|
|
169
|
-
return resolve(bot_answer);
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
*/
|
|
173
106
|
}
|
|
174
107
|
|
|
175
108
|
// ************************************************
|
|
@@ -178,8 +111,8 @@ class WebhookChatbotPlug {
|
|
|
178
111
|
|
|
179
112
|
static myrequest(options, callback, log) {
|
|
180
113
|
if (log) {
|
|
181
|
-
|
|
182
|
-
|
|
114
|
+
winston.debug("(WebhookChatbotPlug) myrequest API URL:" + options.url);
|
|
115
|
+
winston.debug("(WebhookChatbotPlug) myrequest Options:", options);
|
|
183
116
|
}
|
|
184
117
|
axios(
|
|
185
118
|
{
|
|
@@ -190,17 +123,16 @@ class WebhookChatbotPlug {
|
|
|
190
123
|
})
|
|
191
124
|
.then(function (res) {
|
|
192
125
|
if (log) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
console.log("Response body:\n", JSON.stringify(res.data));
|
|
126
|
+
winston.debug("(WebhookChatbotPlug) myrequest Response for url:", options.url);
|
|
127
|
+
winston.debug("(WebhookChatbotPlug) myrequest Response headers:\n", res.headers);
|
|
128
|
+
winston.debug("(WebhookChatbotPlug) myrequest Response body:\n", res.data);
|
|
197
129
|
}
|
|
198
130
|
if (callback) {
|
|
199
131
|
callback(null, res);
|
|
200
132
|
}
|
|
201
133
|
})
|
|
202
134
|
.catch(function (error) {
|
|
203
|
-
|
|
135
|
+
winston.debug("(WebhookChatbotPlug) Axios error: ", error.response.data);
|
|
204
136
|
if (callback) {
|
|
205
137
|
callback(error, null, null);
|
|
206
138
|
}
|