@tiledesk/tiledesk-tybot-connector 0.4.2 → 0.5.0-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 +28 -0
- package/ExtApi.js +3 -13
- package/ExtUtil.js +0 -1
- package/Logger.js +86 -0
- package/TdCache.js +5 -3
- package/TiledeskClientTest.js +5 -28
- package/TiledeskExpression.js +6 -47
- package/index.js +87 -273
- package/logs/app.log +12983 -275
- package/logs/app1.log +62258 -0
- package/logs/app2.log +46280 -0
- package/logs/app3.log +28864 -0
- package/models/IntentForm.js +30 -44
- package/models/IntentsMachineFactory.js +4 -3
- package/models/MockBotsDataSource.js +1 -17
- package/models/MockTdCache.js +0 -9
- package/models/MongodbBotsDataSource.js +29 -53
- package/models/MongodbIntentsMachine.js +5 -4
- package/models/TiledeskChatbot.js +79 -258
- package/models/TiledeskChatbotConst.js +9 -0
- package/models/TiledeskChatbotUtil.js +180 -232
- package/models/TiledeskIntentsMachine.js +5 -14
- package/models/faqKbService.js +0 -1
- package/package.json +5 -2
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +66 -139
- package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +7 -13
- 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/WebhookChatbotPlug.js +21 -89
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +15 -98
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +3 -3
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +32 -57
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +46 -70
- package/tiledeskChatbotPlugs/directives/DirAssign.js +11 -22
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +15 -11
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +48 -97
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +37 -68
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +8 -18
- package/tiledeskChatbotPlugs/directives/DirClose.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirCode.js +15 -22
- package/tiledeskChatbotPlugs/directives/DirCondition.js +18 -24
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -13
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +7 -19
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +30 -57
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +15 -20
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +7 -7
- 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 +15 -22
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +38 -65
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +27 -58
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +22 -40
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -32
- package/tiledeskChatbotPlugs/directives/DirIntent.js +16 -33
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +14 -13
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
- package/tiledeskChatbotPlugs/directives/DirMake.js +20 -52
- package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +10 -20
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +4 -2
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +4 -2
- package/tiledeskChatbotPlugs/directives/DirQapla.js +21 -50
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +9 -17
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +4 -1
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +10 -21
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +9 -19
- package/tiledeskChatbotPlugs/directives/DirReply.js +32 -35
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +27 -69
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +8 -9
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +13 -12
- package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +7 -4
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +22 -75
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
- package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
- package/tiledeskChatbotPlugs/directives/DirWait.js +4 -5
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +13 -48
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +11 -76
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +34 -7
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +11 -14
- package/tiledeskChatbotPlugs/directives/Directives.js +1 -3
- package/utils/winston.js +42 -0
- package/TdCache copy.js +0 -242
|
@@ -3,6 +3,8 @@ const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
|
|
|
3
3
|
const { TiledeskChatbotUtil } = require('../../models/TiledeskChatbotUtil');
|
|
4
4
|
let axios = require('axios');
|
|
5
5
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
6
|
+
const winston = require('../../utils/winston');
|
|
7
|
+
const { Logger } = require('../../Logger');
|
|
6
8
|
|
|
7
9
|
class DirReply {
|
|
8
10
|
|
|
@@ -16,6 +18,8 @@ class DirReply {
|
|
|
16
18
|
this.token = context.token;
|
|
17
19
|
this.tdcache = context.tdcache;
|
|
18
20
|
this.log = context.log;
|
|
21
|
+
this.supportRequest = this.context.supportRequest;
|
|
22
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest.draft });
|
|
19
23
|
|
|
20
24
|
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
21
25
|
this.tdClient = new TiledeskClient({
|
|
@@ -37,17 +41,21 @@ class DirReply {
|
|
|
37
41
|
action.attributes.fillParams = true;
|
|
38
42
|
}
|
|
39
43
|
else {
|
|
40
|
-
|
|
44
|
+
winston.error("DirReply Incorrect directive (no action provided):", directive);
|
|
41
45
|
callback();
|
|
42
46
|
return;
|
|
43
47
|
}
|
|
48
|
+
this.logger.info("Executing Action Reply ", directive.action)
|
|
49
|
+
|
|
44
50
|
this.go(action, () => {
|
|
51
|
+
this.logger.info("Action Reply terminated")
|
|
45
52
|
callback();
|
|
46
53
|
});
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
async go(action, callback) {
|
|
50
57
|
const message = action;
|
|
58
|
+
|
|
51
59
|
// fill
|
|
52
60
|
let requestAttributes = null;
|
|
53
61
|
if (this.tdcache) {
|
|
@@ -55,42 +63,42 @@ class DirReply {
|
|
|
55
63
|
await TiledeskChatbot.allParametersStatic(
|
|
56
64
|
this.tdcache, this.requestId
|
|
57
65
|
);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// if (this.log) {console.log("(DirReply) request parameter:", key, "value:", value, "type:", value_type)}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
66
|
+
|
|
67
|
+
TiledeskChatbotUtil.replaceJSONButtons(message, requestAttributes);
|
|
68
|
+
|
|
64
69
|
const filler = new Filler();
|
|
65
70
|
// fill text attribute
|
|
66
71
|
message.text = filler.fill(message.text, requestAttributes);
|
|
72
|
+
|
|
67
73
|
if (message.metadata) {
|
|
68
|
-
|
|
74
|
+
winston.debug("DirReply filling message 'metadata':", message.metadata);
|
|
69
75
|
if (message.metadata.src) {
|
|
70
76
|
message.metadata.src = filler.fill(message.metadata.src, requestAttributes);
|
|
77
|
+
this.logger.debug("Filled metadata.src with ", message.metadata.src);
|
|
71
78
|
}
|
|
72
79
|
if (message.metadata.name) {
|
|
73
80
|
message.metadata.name = filler.fill(message.metadata.name, requestAttributes);
|
|
81
|
+
this.logger.debug("Filled metadata.name with ", message.metadata.name);
|
|
74
82
|
}
|
|
75
83
|
}
|
|
76
|
-
|
|
84
|
+
winston.debug("DirReply filling commands'. Message:", message);
|
|
77
85
|
if (message.attributes && message.attributes.commands) {
|
|
78
|
-
if (this.log) {console.log("filling commands'. commands found.");}
|
|
79
86
|
let commands = message.attributes.commands;
|
|
80
|
-
|
|
87
|
+
winston.debug("DirReply commands: " + JSON.stringify(commands) + " length: " + commands.length);
|
|
88
|
+
|
|
81
89
|
if (commands.length > 0) {
|
|
82
|
-
if (this.log) {console.log("commands' found");}
|
|
83
90
|
for (let i = 0; i < commands.length; i++) {
|
|
84
91
|
let command = commands[i];
|
|
85
92
|
if (command.type === 'message' && command.message && command.message.text) {
|
|
86
93
|
command.message.text = filler.fill(command.message.text, requestAttributes);
|
|
94
|
+
this.logger.debug("Filled message.text with ", command.message.text)
|
|
87
95
|
TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes, this.log);
|
|
88
|
-
|
|
96
|
+
winston.debug("DirReply command filled: " + command.message.text);
|
|
89
97
|
}
|
|
90
98
|
if (command.type === 'settings' && command.settings) {
|
|
91
99
|
Object.keys(command.settings).forEach(k => {
|
|
92
100
|
command.settings[k] = filler.fill(command.settings[k], requestAttributes)
|
|
93
|
-
|
|
101
|
+
winston.debug("DirReply settings command filled: " + command.settings[k]);
|
|
94
102
|
})
|
|
95
103
|
}
|
|
96
104
|
}
|
|
@@ -98,11 +106,10 @@ class DirReply {
|
|
|
98
106
|
}
|
|
99
107
|
|
|
100
108
|
// EVALUATE EXPRESSION AND REMOVE BASED ON EVALUATION
|
|
101
|
-
|
|
109
|
+
winston.debug("DirReply message before filters: ", message);
|
|
102
110
|
if (message.attributes && message.attributes.commands) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
// TiledeskChatbotUtil.filterOnVariables(message.attributes.commands, requestAttributes);
|
|
111
|
+
winston.debug("DirReply filterOnVariables...on commands", message.attributes.commands)
|
|
112
|
+
winston.debug("DirReply filterOnVariables...on attributes", requestAttributes);
|
|
106
113
|
TiledeskChatbotUtil.filterOnVariables(message, requestAttributes);
|
|
107
114
|
}
|
|
108
115
|
// temporary send back of reserved attributes
|
|
@@ -122,7 +129,7 @@ class DirReply {
|
|
|
122
129
|
}
|
|
123
130
|
// userFlowAttributes
|
|
124
131
|
let userFlowAttributes = TiledeskChatbotUtil.userFlowAttributes(requestAttributes);
|
|
125
|
-
|
|
132
|
+
winston.debug("DirReply userFlowAttributes:", userFlowAttributes);
|
|
126
133
|
if (userFlowAttributes) {
|
|
127
134
|
message.attributes["flowAttributes"] = {};
|
|
128
135
|
for (const [key, value] of Object.entries(userFlowAttributes)) {
|
|
@@ -132,42 +139,32 @@ class DirReply {
|
|
|
132
139
|
}
|
|
133
140
|
}
|
|
134
141
|
catch(err) {
|
|
135
|
-
|
|
142
|
+
winston.error("DirReply An error occurred while JSON.parse(). Parsed value:" + value + " in allParametersStatic(). Error:", err);
|
|
136
143
|
}
|
|
137
144
|
}
|
|
138
145
|
}
|
|
139
146
|
}
|
|
140
|
-
|
|
147
|
+
|
|
141
148
|
let cleanMessage = message;
|
|
142
|
-
// cleanMessage = TiledeskChatbotUtil.removeEmptyReplyCommands(message);
|
|
143
|
-
// if (!TiledeskChatbotUtil.isValidReply(cleanMessage)) {
|
|
144
|
-
// console.log("invalid message", cleanMessage);
|
|
145
|
-
// callback(); // cancel reply operation
|
|
146
|
-
// return;
|
|
147
|
-
// }
|
|
148
|
-
|
|
149
149
|
cleanMessage.senderFullname = this.context.chatbot.bot.name;
|
|
150
|
-
|
|
150
|
+
winston.debug("DirReply reply with clean message: ", cleanMessage);
|
|
151
|
+
|
|
151
152
|
await TiledeskChatbotUtil.updateConversationTranscript(this.context.chatbot, cleanMessage);
|
|
152
|
-
// console.log("sending message!", cleanMessage);
|
|
153
153
|
this.tdClient.sendSupportMessage(
|
|
154
154
|
this.requestId,
|
|
155
155
|
cleanMessage,
|
|
156
156
|
(err) => {
|
|
157
157
|
if (err) {
|
|
158
|
-
|
|
158
|
+
winston.error("DirReply Error sending reply: ", err);
|
|
159
159
|
}
|
|
160
|
-
|
|
160
|
+
winston.verbose("DirReply reply message sent")
|
|
161
161
|
const delay = TiledeskChatbotUtil.totalMessageWait(cleanMessage);
|
|
162
|
-
// console.log("got total delay:", delay)
|
|
163
162
|
if (delay > 0 && delay <= 30000) { // prevent long delays
|
|
164
163
|
setTimeout(() => {
|
|
165
|
-
// console.log("callback after delay")
|
|
166
164
|
callback();
|
|
167
165
|
}, delay);
|
|
168
166
|
}
|
|
169
167
|
else {
|
|
170
|
-
// console.log("invalid delay.")
|
|
171
168
|
callback();
|
|
172
169
|
}
|
|
173
170
|
});
|
|
@@ -7,6 +7,7 @@ const { DirIntent } = require("./DirIntent");
|
|
|
7
7
|
const { DirMessageToBot } = require('./DirMessageToBot');
|
|
8
8
|
const { v4: uuidv4 } = require('uuid');
|
|
9
9
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
10
|
+
const winston = require('../../utils/winston');
|
|
10
11
|
|
|
11
12
|
class DirReplyV2 {
|
|
12
13
|
|
|
@@ -36,6 +37,7 @@ class DirReplyV2 {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
execute(directive, callback) {
|
|
40
|
+
winston.verbose("Execute ReplyV2 directive");
|
|
39
41
|
let action;
|
|
40
42
|
if (directive.action) {
|
|
41
43
|
action = directive.action;
|
|
@@ -45,7 +47,7 @@ class DirReplyV2 {
|
|
|
45
47
|
action.attributes.fillParams = true;
|
|
46
48
|
}
|
|
47
49
|
else {
|
|
48
|
-
|
|
50
|
+
winston.warn("DirReplyV2 Incorrect directive: ", directive);
|
|
49
51
|
callback();
|
|
50
52
|
return;
|
|
51
53
|
}
|
|
@@ -55,7 +57,7 @@ class DirReplyV2 {
|
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
async go(action, callback) {
|
|
58
|
-
|
|
60
|
+
winston.debug("(DirReplyV2) Action: ", action);
|
|
59
61
|
const message = action;
|
|
60
62
|
|
|
61
63
|
let current; // debug only
|
|
@@ -63,7 +65,6 @@ class DirReplyV2 {
|
|
|
63
65
|
if (message.attributes.commands[1].message.text) {
|
|
64
66
|
current = message.attributes.commands[1].message.text
|
|
65
67
|
}
|
|
66
|
-
console.log("current:", current);
|
|
67
68
|
}
|
|
68
69
|
let must_stop = false;
|
|
69
70
|
// fill
|
|
@@ -79,114 +80,93 @@ class DirReplyV2 {
|
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
TiledeskChatbotUtil.replaceJSONButtons(message, requestAttributes);
|
|
84
|
+
|
|
82
85
|
try {
|
|
83
86
|
// lock/unlock + no-match
|
|
84
87
|
// get buttons if available
|
|
85
88
|
const buttons = TiledeskChatbotUtil.allReplyButtons(message);
|
|
86
|
-
if (this.log) { console.log("Action Buttons:", JSON.stringify(buttons)); }
|
|
87
89
|
if (buttons && buttons.length > 0) {
|
|
88
90
|
const locked = await this.lockUnlock(action); // first execution returns locked, then unlocked
|
|
89
91
|
if (locked) { // fist execution returns (just) locked
|
|
90
|
-
if (this.log) { console.log("first time pass!"); }
|
|
91
92
|
must_stop = true; // you must stop after next callbacks (in this flow) if there are buttons
|
|
92
|
-
// console.log("action:", action);
|
|
93
93
|
if (action.noInputIntent) {
|
|
94
|
-
if (this.log) { console.log("NoInputIntent found:", action.noInputIntent); }
|
|
95
94
|
const noInputIntent = action.noInputIntent;
|
|
96
95
|
const noInputTimeout = action.noInputTimeout;
|
|
97
|
-
if (this.log) { console.log("noInputTimeout found:", noInputTimeout); }
|
|
98
96
|
if (noInputTimeout > 0 && noInputTimeout < 7776000) {
|
|
99
97
|
const timeout_id = uuidv4();
|
|
100
98
|
await this.chatbot.addParameter(TiledeskChatbotConst.USER_INPUT, timeout_id); // control variable. On each user input is removed
|
|
101
|
-
if (this.log) { console.log("Set userInput: false, checking...", await this.chatbot.getParameter(TiledeskChatbotConst.USER_INPUT)); }
|
|
102
99
|
setTimeout(async () => {
|
|
103
|
-
|
|
100
|
+
winston.debug("(DirReplyV2) noinput timeout triggered!");
|
|
104
101
|
const userInput = await this.chatbot.getParameter(TiledeskChatbotConst.USER_INPUT);
|
|
105
|
-
if (this.log) { console.log("got 'userInput':", userInput); }
|
|
106
102
|
if (userInput && userInput === timeout_id) {
|
|
107
|
-
if (this.log) { console.log("no 'userInput'. Executing noinput action:", noInputIntent); }
|
|
108
103
|
await this.chatbot.unlockIntent(this.requestId);
|
|
109
104
|
await this.chatbot.unlockAction(this.requestId);
|
|
110
|
-
|
|
105
|
+
winston.debug("(DirReplyV2) Unlocked (for noInput) ReplyV2");
|
|
111
106
|
let noinput_action = DirIntent.intentDirectiveFor(noInputIntent, null);
|
|
112
107
|
this.intentDir.execute(noinput_action, () => {
|
|
113
|
-
|
|
108
|
+
winston.debug("(DirReplyV2) noinput action invoked", noinput_action);
|
|
114
109
|
});
|
|
115
110
|
}
|
|
116
111
|
else {
|
|
117
|
-
|
|
112
|
+
winston.debug("(DirReplyV2) Skipping noinput action because of userInput", userInput);
|
|
118
113
|
}
|
|
119
114
|
}, noInputTimeout);
|
|
120
115
|
}
|
|
121
116
|
}
|
|
122
117
|
}
|
|
123
118
|
else { // second execution
|
|
124
|
-
|
|
119
|
+
|
|
125
120
|
const last_user_text = await this.chatbot.getParameter(TiledeskChatbotConst.REQ_LAST_USER_TEXT_v2_KEY);
|
|
126
|
-
if (this.log) { console.log("got last user text"); }
|
|
127
121
|
const button = TiledeskChatbotUtil.buttonByText(last_user_text, buttons);
|
|
128
|
-
|
|
122
|
+
|
|
129
123
|
// invoke button
|
|
130
124
|
if (button && button.action) {
|
|
131
|
-
if (this.log) { console.log("moving to button action", button.action); }
|
|
132
125
|
let button_action = DirIntent.intentDirectiveFor(button.action, null);
|
|
133
|
-
if (this.log) { console.log("action with .intentName:", button_action); }
|
|
134
126
|
this.intentDir.execute(button_action, () => {
|
|
135
|
-
|
|
127
|
+
winston.debug("(DirReplyV2) action invoked", button_action);
|
|
136
128
|
});
|
|
137
|
-
if (this.log) { console.log("callback(true) + return", current); }
|
|
138
129
|
callback(true); // must_stop = true
|
|
139
130
|
return;
|
|
140
131
|
}
|
|
141
132
|
else { // no match (treating text buttons as no-match for the moment)
|
|
142
133
|
// if noMatchIntent invoke
|
|
143
134
|
// const button = TiledeskChatbotUtil.buttonByText("nomatch", buttons);
|
|
144
|
-
|
|
135
|
+
winston.debug("(DirReplyV2) nomatch button found ", button);
|
|
145
136
|
// // invoke button
|
|
146
137
|
// if (button && button.action) {
|
|
147
|
-
// console.log("moving to nomatch action", button.action);
|
|
148
138
|
// let button_action = DirIntent.intentDirectiveFor(button.action, null);
|
|
149
139
|
// this.intentDir.execute(button_action, () => {
|
|
150
|
-
// console.log("nomatch action invoked", button_action);
|
|
151
140
|
// });
|
|
152
|
-
// console.log("callback(true) + return 2", current);
|
|
153
141
|
// callback(true);
|
|
154
142
|
// return;
|
|
155
143
|
// }
|
|
156
144
|
if (action.noMatchIntent) {
|
|
157
|
-
if (this.log) { console.log("moving to nomatch action", action.noMatchIntent); }
|
|
158
145
|
let nomatch_action = DirIntent.intentDirectiveFor(action.noMatchIntent, null);
|
|
159
146
|
this.intentDir.execute(nomatch_action, () => {
|
|
160
|
-
|
|
147
|
+
winston.debug("(DirReplyV2) nomatch action invoked", nomatch_action);
|
|
161
148
|
});
|
|
162
|
-
if (this.log) { console.log("callback(true) + return no-match", current); }
|
|
163
149
|
callback(true); // must_stop = true
|
|
164
150
|
return;
|
|
165
151
|
}
|
|
166
152
|
else {
|
|
167
153
|
// const defaultFallbackAction = { action: { intentName: "defaultFallback" } };
|
|
168
154
|
|
|
169
|
-
// console.log("re-send original message:",JSON.stringify(this.originalMessage));
|
|
170
155
|
const messageDir = new DirMessageToBot(this.context);
|
|
171
156
|
messageDir.execute( { action: { message: this.originalMessage } }, () => {
|
|
172
|
-
|
|
157
|
+
winston.debug("(DirReplyV2) messageDir invoked");
|
|
173
158
|
});
|
|
174
|
-
if (this.log) { console.log("callback(true) + return no-match", current); }
|
|
175
159
|
callback(true); // must_stop = true
|
|
176
160
|
return;
|
|
177
161
|
|
|
178
162
|
// const textAction = { action: { text: last_user_text } };
|
|
179
|
-
// console.log("textAction invoked:",textAction ); //, defaultFallbackAction);
|
|
180
163
|
// this.intentDir.execute( textAction, () => {
|
|
181
|
-
// if (this.log) { console.log("textAction invoked", textAction); }
|
|
182
164
|
// });
|
|
183
|
-
// if (this.log) { console.log("callback(true) + return no-match", current); }
|
|
184
165
|
// callback(true); // must_stop = true
|
|
185
166
|
// return;
|
|
186
167
|
|
|
187
168
|
|
|
188
169
|
// // there is no "no-match", go on...
|
|
189
|
-
// if (this.log) { console.log("callback(false) + return 3", current); }
|
|
190
170
|
// callback(false);
|
|
191
171
|
// return;
|
|
192
172
|
}
|
|
@@ -195,16 +175,14 @@ class DirReplyV2 {
|
|
|
195
175
|
}
|
|
196
176
|
}
|
|
197
177
|
catch(error) {
|
|
198
|
-
|
|
178
|
+
winston.error("(DirReplyV2) Error: ", error);
|
|
199
179
|
}
|
|
200
180
|
|
|
201
|
-
|
|
202
|
-
if (this.log) { console.log("proceding normally to render and send the reply", current); }
|
|
203
181
|
const filler = new Filler();
|
|
182
|
+
|
|
204
183
|
// fill text attribute
|
|
205
184
|
message.text = filler.fill(message.text, requestAttributes);
|
|
206
185
|
if (message.metadata) {
|
|
207
|
-
if (this.log) {console.log("filling message 'metadata':", JSON.stringify(message.metadata));}
|
|
208
186
|
if (message.metadata.src) {
|
|
209
187
|
message.metadata.src = filler.fill(message.metadata.src, requestAttributes);
|
|
210
188
|
}
|
|
@@ -212,29 +190,22 @@ class DirReplyV2 {
|
|
|
212
190
|
message.metadata.name = filler.fill(message.metadata.name, requestAttributes);
|
|
213
191
|
}
|
|
214
192
|
}
|
|
215
|
-
if (this.log) {console.log("filling commands'. Message:", JSON.stringify(message));}
|
|
216
193
|
if (message.attributes && message.attributes.commands) {
|
|
217
|
-
if (this.log) {console.log("filling commands'. commands found.");}
|
|
218
194
|
let commands = message.attributes.commands;
|
|
219
|
-
if (this.log) {console.log("commands:", JSON.stringify(commands), commands.length);}
|
|
220
195
|
if (commands.length > 0) {
|
|
221
|
-
if (this.log) {console.log("commands' found");}
|
|
222
196
|
for (let i = 0; i < commands.length; i++) {
|
|
223
197
|
let command = commands[i];
|
|
224
198
|
if (command.type === 'message' && command.message && command.message.text) {
|
|
225
199
|
command.message.text = filler.fill(command.message.text, requestAttributes);
|
|
226
200
|
TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes, this.log);
|
|
227
|
-
if (this.log) {console.log("command filled:", command.message.text);}
|
|
228
201
|
}
|
|
229
202
|
}
|
|
230
203
|
}
|
|
231
204
|
}
|
|
232
205
|
|
|
233
206
|
// EVALUATE EXPRESSION AND REMOVE BASED ON EVALUATION
|
|
234
|
-
|
|
207
|
+
winston.debug("(DirReplyV2) message before filters:", message);
|
|
235
208
|
if (message.attributes && message.attributes.commands) {
|
|
236
|
-
if (this.log) {console.log("filterOnVariables...on commands", JSON.stringify(message.attributes.commands));}
|
|
237
|
-
if (this.log) {console.log("filterOnVariables...on attributes", requestAttributes);}
|
|
238
209
|
// TiledeskChatbotUtil.filterOnVariables(message.attributes.commands, requestAttributes);
|
|
239
210
|
TiledeskChatbotUtil.filterOnVariables(message, requestAttributes);
|
|
240
211
|
}
|
|
@@ -256,7 +227,6 @@ class DirReplyV2 {
|
|
|
256
227
|
}
|
|
257
228
|
// userFlowAttributes
|
|
258
229
|
let userFlowAttributes = TiledeskChatbotUtil.userFlowAttributes(requestAttributes);
|
|
259
|
-
if (this.log) { console.log("userFlowAttributes:", userFlowAttributes); }
|
|
260
230
|
if (userFlowAttributes) {
|
|
261
231
|
message.attributes["flowAttributes"] = {};
|
|
262
232
|
for (const [key, value] of Object.entries(userFlowAttributes)) {
|
|
@@ -266,7 +236,7 @@ class DirReplyV2 {
|
|
|
266
236
|
}
|
|
267
237
|
}
|
|
268
238
|
catch(err) {
|
|
269
|
-
|
|
239
|
+
winston.errpr("(DirReplyV2) An error occurred while JSON.parse(). Parsed value: " + value + " in allParametersStatic(). Error: " + JSON.stringify(err));
|
|
270
240
|
}
|
|
271
241
|
}
|
|
272
242
|
}
|
|
@@ -276,33 +246,29 @@ class DirReplyV2 {
|
|
|
276
246
|
let cleanMessage = message;
|
|
277
247
|
// cleanMessage = TiledeskChatbotUtil.removeEmptyReplyCommands(message);
|
|
278
248
|
// if (!TiledeskChatbotUtil.isValidReply(cleanMessage)) {
|
|
279
|
-
// console.log("invalid message", cleanMessage);
|
|
280
249
|
// callback(); // cancel reply operation
|
|
281
250
|
// return;
|
|
282
251
|
// }
|
|
283
|
-
// console.log("valid message!", cleanMessage);
|
|
284
252
|
cleanMessage.senderFullname = this.context.chatbot.bot.name;
|
|
285
|
-
|
|
253
|
+
winston.debug("(DirReplyV2) Reply: ", cleanMessage);
|
|
286
254
|
await TiledeskChatbotUtil.updateConversationTranscript(this.context.chatbot, cleanMessage);
|
|
287
255
|
this.tdClient.sendSupportMessage(
|
|
288
256
|
this.requestId,
|
|
289
257
|
cleanMessage,
|
|
290
258
|
(err) => {
|
|
291
259
|
if (err) {
|
|
292
|
-
|
|
260
|
+
winston.error("(DirReplyV2) Error sending reply: ", err);
|
|
293
261
|
}
|
|
294
|
-
|
|
262
|
+
winston.debug("(DirReplyV2) Reply message sent");
|
|
295
263
|
const delay = TiledeskChatbotUtil.totalMessageWait(cleanMessage);
|
|
296
|
-
// console.log("got total delay:", delay)
|
|
297
264
|
if (delay > 0 && delay <= 30000) { // prevent long delays
|
|
298
|
-
|
|
265
|
+
winston.debug("(DirReplyV2) start timeout callback(" + must_stop + ") for:", current);
|
|
299
266
|
setTimeout(async () => {
|
|
300
|
-
|
|
267
|
+
winston.debug("(DirReplyV2) callback(" + must_stop + ") after delay", current);
|
|
301
268
|
callback(must_stop);
|
|
302
269
|
}, delay);
|
|
303
270
|
}
|
|
304
271
|
else {
|
|
305
|
-
// console.log("invalid delay.")
|
|
306
272
|
callback(must_stop);
|
|
307
273
|
}
|
|
308
274
|
});
|
|
@@ -312,32 +278,24 @@ class DirReplyV2 {
|
|
|
312
278
|
|
|
313
279
|
async lockUnlock(action, callback) {
|
|
314
280
|
let lockedAction = await this.chatbot.currentLockedAction(this.requestId);
|
|
315
|
-
|
|
281
|
+
|
|
316
282
|
if (!lockedAction) {
|
|
317
|
-
// console.log("(DirReplyV2) !lockedAction");
|
|
318
283
|
const intent_name = this.reply.attributes.intent_info.intent_name
|
|
319
284
|
const actionId = action["_tdActionId"];
|
|
320
|
-
// console.log("(DirReplyV2) intent_name:", intent_name);
|
|
321
|
-
// console.log("(DirReplyV2) actionId:", actionId);
|
|
322
285
|
await this.chatbot.lockIntent(this.requestId, intent_name);
|
|
323
|
-
// console.log("(DirReplyV2) lockIntent");
|
|
324
286
|
await this.chatbot.lockAction(this.requestId, actionId);
|
|
325
|
-
// console.log("(DirReplyV2) lockAction");
|
|
326
287
|
let _lockedAction = await this.chatbot.currentLockedAction(this.requestId);
|
|
327
288
|
let _lockedIntent = await this.chatbot.currentLockedIntent(this.requestId);
|
|
328
|
-
// console.log("(DirReplyV2) _lockedAction", _lockedAction);
|
|
329
|
-
// console.log("(DirReplyV2) _lockedIntent", _lockedIntent);
|
|
330
289
|
// callback();
|
|
331
290
|
return true;
|
|
332
291
|
} else {
|
|
333
292
|
try {
|
|
334
293
|
await this.chatbot.unlockIntent(this.requestId);
|
|
335
294
|
await this.chatbot.unlockAction(this.requestId);
|
|
336
|
-
// console.log("unlocked ReplyV2");
|
|
337
295
|
return false;
|
|
338
296
|
}
|
|
339
297
|
catch(e) {
|
|
340
|
-
|
|
298
|
+
winston.error("(DirReplyV2) Error", e);
|
|
341
299
|
}
|
|
342
300
|
}
|
|
343
301
|
}
|
|
@@ -27,6 +27,7 @@ class DirSendEmail {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
execute(directive, callback) {
|
|
30
|
+
winston.verbose("Execute SendEmail directive");
|
|
30
31
|
let action;
|
|
31
32
|
if (directive.action) {
|
|
32
33
|
action = directive.action;
|
|
@@ -40,7 +41,7 @@ class DirSendEmail {
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
else {
|
|
43
|
-
|
|
44
|
+
winston.warn("DirSendEmail Incorrect directive: ", directive);
|
|
44
45
|
callback();
|
|
45
46
|
return;
|
|
46
47
|
}
|
|
@@ -50,8 +51,7 @@ class DirSendEmail {
|
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
async go(action, completion) {
|
|
53
|
-
|
|
54
|
-
if (this.log) {console.log("email action:", JSON.stringify(action));}
|
|
54
|
+
winston.debug("(DirSendEmail) Action: ", action);
|
|
55
55
|
if (action.subject && action.text && action.to) {
|
|
56
56
|
try {
|
|
57
57
|
let requestVariables = null;
|
|
@@ -72,19 +72,18 @@ class DirSendEmail {
|
|
|
72
72
|
to: filled_to,
|
|
73
73
|
replyto: reply_to
|
|
74
74
|
}
|
|
75
|
-
// console.log("email message:", JSON.stringify(message));
|
|
76
75
|
const message_echo = await this.tdClient.sendEmail(message);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
winston.debug("(DirSendEmail) filled_subject: " + filled_subject);
|
|
77
|
+
winston.debug("(DirSendEmail) filled_text: " + filled_text);
|
|
78
|
+
winston.debug("(DirSendEmail) filled_to: " + filled_to);
|
|
79
|
+
winston.debug("(DirSendEmail) reply_to: " + reply_to);
|
|
81
80
|
if (completion) {
|
|
82
81
|
completion(null, message_echo);
|
|
83
82
|
}
|
|
84
83
|
return message_echo;
|
|
85
84
|
}
|
|
86
85
|
catch(err) {
|
|
87
|
-
|
|
86
|
+
winston.error("(DirSendEmail) sendEmail error: ", err);
|
|
88
87
|
if (completion) {
|
|
89
88
|
completion(err);
|
|
90
89
|
}
|
|
@@ -2,6 +2,7 @@ const axios = require("axios").default;
|
|
|
2
2
|
const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
|
|
3
3
|
const { Filler } = require("../Filler");
|
|
4
4
|
const { DirIntent } = require("./DirIntent");
|
|
5
|
+
const winston = require('../../utils/winston');
|
|
5
6
|
|
|
6
7
|
let whatsapp_api_url;
|
|
7
8
|
|
|
@@ -21,13 +22,13 @@ class DirSendWhatsapp {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
execute(directive, callback) {
|
|
24
|
-
|
|
25
|
+
winston.verbose("Execute SendWhatsapp directive");
|
|
25
26
|
let action;
|
|
26
27
|
if (directive.action) {
|
|
27
28
|
action = directive.action;
|
|
28
29
|
}
|
|
29
30
|
else {
|
|
30
|
-
|
|
31
|
+
winston.warn("DirSendWhatsapp Incorrect directive: ", directive);
|
|
31
32
|
callback();
|
|
32
33
|
return;
|
|
33
34
|
}
|
|
@@ -38,9 +39,9 @@ class DirSendWhatsapp {
|
|
|
38
39
|
|
|
39
40
|
async go(action, callback) {
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
winston.debug("(DirSendWhatsapp) Action: ", action);
|
|
42
43
|
if (!this.tdcache) {
|
|
43
|
-
|
|
44
|
+
winston.error("(DirSendWhatsapp) Error: tdcache is mandatory");
|
|
44
45
|
callback();
|
|
45
46
|
return;
|
|
46
47
|
}
|
|
@@ -80,7 +81,7 @@ class DirSendWhatsapp {
|
|
|
80
81
|
} else {
|
|
81
82
|
whatsapp_api_url = this.API_ENDPOINT + "/modules/whatsapp/api"
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
+
winston.debug("(DirSendWhatsapp) whatsapp_api_url: " + whatsapp_api_url);
|
|
84
85
|
|
|
85
86
|
const HTTPREQUEST = {
|
|
86
87
|
url: whatsapp_api_url + "/tiledesk/broadcast",
|
|
@@ -91,12 +92,12 @@ class DirSendWhatsapp {
|
|
|
91
92
|
method: 'POST'
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
|
|
95
|
+
winston.debug("(DirSendWhatsapp) HttpRequest: ", HTTPREQUEST);
|
|
95
96
|
|
|
96
97
|
this.#myrequest(
|
|
97
98
|
HTTPREQUEST, async (err, resbody) => {
|
|
98
99
|
if (err) {
|
|
99
|
-
|
|
100
|
+
winston.error("(DirSendWhatsapp) error: ", err)
|
|
100
101
|
await this.chatbot.addParameter("flowError", "SendWhatsapp Error: " + err);
|
|
101
102
|
if (callback) {
|
|
102
103
|
if (falseIntent) {
|
|
@@ -118,7 +119,7 @@ class DirSendWhatsapp {
|
|
|
118
119
|
return;
|
|
119
120
|
}
|
|
120
121
|
} else {
|
|
121
|
-
|
|
122
|
+
winston.debug("(DirSendWhatsapp) unexpected resbody: ", resbody);
|
|
122
123
|
if (callback) {
|
|
123
124
|
if (falseIntent) {
|
|
124
125
|
await this.#executeCondition(false, trueIntent, null, falseIntent, null);
|
|
@@ -151,7 +152,7 @@ class DirSendWhatsapp {
|
|
|
151
152
|
})
|
|
152
153
|
}
|
|
153
154
|
else {
|
|
154
|
-
|
|
155
|
+
winston.debug("(DirSendWhatsapp) No trueIntentDirective specified");
|
|
155
156
|
if (callback) {
|
|
156
157
|
callback();
|
|
157
158
|
}
|
|
@@ -166,7 +167,7 @@ class DirSendWhatsapp {
|
|
|
166
167
|
});
|
|
167
168
|
}
|
|
168
169
|
else {
|
|
169
|
-
|
|
170
|
+
winston.debug("(DirSendWhatsapp) No falseIntentDirective specified");
|
|
170
171
|
if (callback) {
|
|
171
172
|
callback();
|
|
172
173
|
}
|
|
@@ -209,7 +210,7 @@ class DirSendWhatsapp {
|
|
|
209
210
|
resolve(receiver);
|
|
210
211
|
|
|
211
212
|
} catch(err) {
|
|
212
|
-
|
|
213
|
+
winston.error("(DirSendWhatsapp) fillWholeReceiver error: ", err)
|
|
213
214
|
resolve(null);
|
|
214
215
|
}
|
|
215
216
|
|
|
@@ -236,7 +237,7 @@ class DirSendWhatsapp {
|
|
|
236
237
|
}
|
|
237
238
|
}
|
|
238
239
|
}).catch((err) => {
|
|
239
|
-
|
|
240
|
+
winston.error("(DirSendWhatsapp) Axios errro: ", err);
|
|
240
241
|
if (callback) {
|
|
241
242
|
callback(err, null, null);
|
|
242
243
|
}
|