@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,10 +1,11 @@
|
|
|
1
1
|
const axios = require("axios").default;
|
|
2
|
-
const { TiledeskChatbot } = require("../../
|
|
2
|
+
const { TiledeskChatbot } = require("../../engine/TiledeskChatbot");
|
|
3
3
|
const { Filler } = require("../Filler");
|
|
4
4
|
const { DirIntent } = require("./DirIntent");
|
|
5
5
|
let https = require("https");
|
|
6
6
|
require('dotenv').config();
|
|
7
|
-
|
|
7
|
+
const winston = require('../../utils/winston');
|
|
8
|
+
const integrationService = require("../../services/IntegrationService");
|
|
8
9
|
|
|
9
10
|
class DirHubspot {
|
|
10
11
|
|
|
@@ -15,19 +16,21 @@ class DirHubspot {
|
|
|
15
16
|
this.context = context;
|
|
16
17
|
this.tdcache = this.context.tdcache;
|
|
17
18
|
this.requestId = this.context.requestId;
|
|
19
|
+
this.projectId = this.context.projectId;
|
|
20
|
+
this.token = this.context.token;
|
|
18
21
|
this.intentDir = new DirIntent(context);
|
|
19
22
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
20
23
|
this.log = context.log;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
execute(directive, callback) {
|
|
24
|
-
|
|
27
|
+
winston.verbose("Execute Hubspot directive");
|
|
25
28
|
let action;
|
|
26
29
|
if (directive.action) {
|
|
27
30
|
action = directive.action;
|
|
28
31
|
}
|
|
29
32
|
else {
|
|
30
|
-
|
|
33
|
+
winston.warn("DirHubspot Incorrect directive: ", directive);
|
|
31
34
|
callback();
|
|
32
35
|
return;
|
|
33
36
|
}
|
|
@@ -37,9 +40,9 @@ class DirHubspot {
|
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
async go(action, callback) {
|
|
40
|
-
|
|
43
|
+
winston.debug("(DirHubspot) Action: ", action);
|
|
41
44
|
if (!this.tdcache) {
|
|
42
|
-
|
|
45
|
+
winston.error("(DirHubspot) Error: tdcache is mandatory");
|
|
43
46
|
callback();
|
|
44
47
|
return;
|
|
45
48
|
}
|
|
@@ -49,12 +52,10 @@ class DirHubspot {
|
|
|
49
52
|
let trueIntentAttributes = action.trueIntentAttributes;
|
|
50
53
|
let falseIntentAttributes = action.falseIntentAttributes;
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
console.log("DirAskGPT falseIntentAttributes", falseIntentAttributes)
|
|
57
|
-
}
|
|
55
|
+
winston.debug("(DirHubspot) trueIntent " + trueIntent)
|
|
56
|
+
winston.debug("(DirHubspot) falseIntent " + falseIntent)
|
|
57
|
+
winston.debug("(DirHubspot) trueIntentAttributes " + trueIntentAttributes)
|
|
58
|
+
winston.debug("(DirHubspot) falseIntentAttributes " + falseIntentAttributes)
|
|
58
59
|
|
|
59
60
|
let requestVariables = null;
|
|
60
61
|
requestVariables =
|
|
@@ -64,20 +65,20 @@ class DirHubspot {
|
|
|
64
65
|
|
|
65
66
|
//let token = action.token;
|
|
66
67
|
let bodyParameters = action.bodyParameters;
|
|
67
|
-
|
|
68
|
+
winston.debug("(DirHubspot) bodyParameters: ", bodyParameters);
|
|
68
69
|
|
|
69
70
|
if (!bodyParameters || bodyParameters === '') {
|
|
70
|
-
|
|
71
|
+
winston.error("(DirHubspot) Error: bodyParameters is undefined or null or empty string");
|
|
71
72
|
callback();
|
|
72
73
|
return;
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
const hubspot_base_url = process.env.HUBSPOT_ENDPOINT || "https://api.hubapi.com/crm/v3/";
|
|
76
|
-
|
|
77
|
+
winston.debug("(DirHubspot) hubspot_base_url " + hubspot_base_url);
|
|
77
78
|
|
|
78
|
-
let key = await
|
|
79
|
+
let key = await integrationService.getKeyFromIntegrations(this.projectId, 'hubspot', this.token);
|
|
79
80
|
if (!key) {
|
|
80
|
-
|
|
81
|
+
winston.debug("(DirHubspot) - Key not found in Integrations.");
|
|
81
82
|
if (falseIntent) {
|
|
82
83
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
83
84
|
callback(true);
|
|
@@ -87,11 +88,10 @@ class DirHubspot {
|
|
|
87
88
|
|
|
88
89
|
const filler = new Filler();
|
|
89
90
|
for (const [key, value] of Object.entries(bodyParameters)) {
|
|
90
|
-
if (this.log) { console.log("bodyParam:", key, "value:", value) }
|
|
91
91
|
let filled_value = filler.fill(value, requestVariables);
|
|
92
92
|
bodyParameters[key] = filled_value;
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
winston.debug("(DirHubspot) bodyParameters filled: ", bodyParameters);
|
|
95
95
|
|
|
96
96
|
let json = {
|
|
97
97
|
inputs: [
|
|
@@ -107,17 +107,13 @@ class DirHubspot {
|
|
|
107
107
|
json: json,
|
|
108
108
|
method: "POST"
|
|
109
109
|
}
|
|
110
|
-
|
|
110
|
+
winston.debug("(DirHubspot) HttpRequest ", HUBSPOT_HTTPREQUEST);
|
|
111
111
|
|
|
112
112
|
this.#myrequest(
|
|
113
113
|
HUBSPOT_HTTPREQUEST, async (err, resbody) => {
|
|
114
114
|
if (err) {
|
|
115
115
|
if (callback) {
|
|
116
|
-
|
|
117
|
-
console.error("(httprequest) DirHubspot err response:", err.response)
|
|
118
|
-
console.error("(httprequest) DirHubspot err data:", err.response.data)
|
|
119
|
-
};
|
|
120
|
-
|
|
116
|
+
winston.error("(DirHubspot) err response: ", err.response.data)
|
|
121
117
|
let result = null;
|
|
122
118
|
let status = null;
|
|
123
119
|
let error;
|
|
@@ -133,11 +129,9 @@ class DirHubspot {
|
|
|
133
129
|
error = err.response.data.message;
|
|
134
130
|
}
|
|
135
131
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
console.error("(httprequest) DirHubspot err data error:", error);
|
|
140
|
-
}
|
|
132
|
+
winston.debug("(DirHubspot) err data result: " + result);
|
|
133
|
+
winston.debug("(DirHubspot) err data status: " + status);
|
|
134
|
+
winston.debug("(DirHubspot) err data error: ", error);
|
|
141
135
|
|
|
142
136
|
await this.#assignAttributes(action, status, result, error);
|
|
143
137
|
if (falseIntent) {
|
|
@@ -149,7 +143,7 @@ class DirHubspot {
|
|
|
149
143
|
return;
|
|
150
144
|
}
|
|
151
145
|
} else if (callback) {
|
|
152
|
-
|
|
146
|
+
winston.debug("(DirHubspot) resbody: ", resbody);
|
|
153
147
|
|
|
154
148
|
let status = 201;
|
|
155
149
|
let error = null;
|
|
@@ -169,12 +163,10 @@ class DirHubspot {
|
|
|
169
163
|
}
|
|
170
164
|
|
|
171
165
|
async #assignAttributes(action, status, result, error) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
console.log("DirHubspot assignAttributes error:", error)
|
|
177
|
-
}
|
|
166
|
+
winston.debug("(DirHubspot) assignAttributes action: ", action)
|
|
167
|
+
winston.debug("(DirHubspot) assignAttributes status: " + status)
|
|
168
|
+
winston.debug("(DirHubspot) assignAttributes result: ", result)
|
|
169
|
+
winston.debug("(DirHubspot) assignAttributes error: ", error)
|
|
178
170
|
if (this.context.tdcache) {
|
|
179
171
|
if (action.assignStatusTo) {
|
|
180
172
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignStatusTo, status);
|
|
@@ -185,22 +177,10 @@ class DirHubspot {
|
|
|
185
177
|
if (action.assignErrorTo) {
|
|
186
178
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignErrorTo, error);
|
|
187
179
|
}
|
|
188
|
-
|
|
189
|
-
// Debug log
|
|
190
|
-
if (this.log) {
|
|
191
|
-
const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
|
|
192
|
-
for (const [key, value] of Object.entries(all_parameters)) {
|
|
193
|
-
if (this.log) { console.log("DirHubspot request parameter:", key, "value:", value, "type:", typeof value) }
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
180
|
}
|
|
197
181
|
}
|
|
198
182
|
|
|
199
183
|
#myrequest(options, callback) {
|
|
200
|
-
if (this.log) {
|
|
201
|
-
console.log("** API URL:", options.url);
|
|
202
|
-
console.log("** Options:", JSON.stringify(options));
|
|
203
|
-
}
|
|
204
184
|
let axios_options = {
|
|
205
185
|
url: options.url,
|
|
206
186
|
method: options.method,
|
|
@@ -210,9 +190,6 @@ class DirHubspot {
|
|
|
210
190
|
if (options.json !== null) {
|
|
211
191
|
axios_options.data = options.json
|
|
212
192
|
}
|
|
213
|
-
if (this.log) {
|
|
214
|
-
console.log("axios_options:", JSON.stringify(axios_options));
|
|
215
|
-
}
|
|
216
193
|
if (options.url.startsWith("https:")) {
|
|
217
194
|
const httpsAgent = new https.Agent({
|
|
218
195
|
rejectUnauthorized: false,
|
|
@@ -221,10 +198,6 @@ class DirHubspot {
|
|
|
221
198
|
}
|
|
222
199
|
axios(axios_options)
|
|
223
200
|
.then((res) => {
|
|
224
|
-
if (this.log) {
|
|
225
|
-
console.log("Response for url:", options.url);
|
|
226
|
-
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
227
|
-
}
|
|
228
201
|
if (res && (res.status == 200 || res.status == 201) && res.data) {
|
|
229
202
|
if (callback) {
|
|
230
203
|
callback(null, res.data);
|
|
@@ -253,7 +226,6 @@ class DirHubspot {
|
|
|
253
226
|
if (falseIntent) {
|
|
254
227
|
falseIntentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
|
|
255
228
|
}
|
|
256
|
-
if (this.log) { console.log('DirHubspot executeCondition/result', result) }
|
|
257
229
|
if (result === true) {
|
|
258
230
|
if (trueIntentDirective) {
|
|
259
231
|
this.intentDir.execute(trueIntentDirective, () => {
|
|
@@ -263,7 +235,7 @@ class DirHubspot {
|
|
|
263
235
|
});
|
|
264
236
|
}
|
|
265
237
|
else {
|
|
266
|
-
|
|
238
|
+
winston.debug("(DirHubspot) No trueIntentDirective specified");
|
|
267
239
|
if (callback) {
|
|
268
240
|
callback();
|
|
269
241
|
}
|
|
@@ -278,45 +250,13 @@ class DirHubspot {
|
|
|
278
250
|
});
|
|
279
251
|
}
|
|
280
252
|
else {
|
|
281
|
-
|
|
253
|
+
winston.debug("(DirHubspot) No falseIntentDirective specified");
|
|
282
254
|
if (callback) {
|
|
283
255
|
callback();
|
|
284
256
|
}
|
|
285
257
|
}
|
|
286
258
|
}
|
|
287
259
|
}
|
|
288
|
-
|
|
289
|
-
async getKeyFromIntegrations() {
|
|
290
|
-
return new Promise((resolve) => {
|
|
291
|
-
|
|
292
|
-
const INTEGRATIONS_HTTPREQUEST = {
|
|
293
|
-
url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/hubspot",
|
|
294
|
-
headers: {
|
|
295
|
-
'Content-Type': 'application/json',
|
|
296
|
-
'Authorization': 'JWT ' + this.context.token
|
|
297
|
-
},
|
|
298
|
-
method: "GET"
|
|
299
|
-
}
|
|
300
|
-
if (this.log) { console.log("DirGptTask INTEGRATIONS_HTTPREQUEST ", INTEGRATIONS_HTTPREQUEST) }
|
|
301
|
-
|
|
302
|
-
this.#myrequest(
|
|
303
|
-
INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
|
|
304
|
-
if (err) {
|
|
305
|
-
resolve(null);
|
|
306
|
-
} else {
|
|
307
|
-
|
|
308
|
-
if (integration &&
|
|
309
|
-
integration.value) {
|
|
310
|
-
resolve(integration.value.apikey)
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
resolve(null)
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
})
|
|
317
|
-
})
|
|
318
|
-
}
|
|
319
|
-
|
|
320
260
|
}
|
|
321
261
|
|
|
322
262
|
module.exports = { DirHubspot }
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
3
3
|
const { DirIntent } = require('./DirIntent');
|
|
4
4
|
const ms = require('minimist-string');
|
|
5
|
+
const winston = require('../../utils/winston');
|
|
5
6
|
|
|
6
7
|
class DirIfOnlineAgents {
|
|
7
8
|
|
|
@@ -25,6 +26,7 @@ class DirIfOnlineAgents {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
execute(directive, callback) {
|
|
29
|
+
winston.verbose("Execute IfOnlineAgents directive");
|
|
28
30
|
let action;
|
|
29
31
|
if (directive.action) {
|
|
30
32
|
action = directive.action
|
|
@@ -32,19 +34,13 @@ class DirIfOnlineAgents {
|
|
|
32
34
|
else if (directive.parameter) {
|
|
33
35
|
let params;
|
|
34
36
|
params = this.parseParams(directive.parameter);
|
|
35
|
-
// if (!params.trueIntent && !params.falseIntent) {
|
|
36
|
-
// if (this.log) {
|
|
37
|
-
// console.log("missing both params.trueIntent & params.falseIntent");
|
|
38
|
-
// }
|
|
39
|
-
// callback();
|
|
40
|
-
// return;
|
|
41
|
-
// }
|
|
42
37
|
action = {
|
|
43
38
|
trueIntent: params.trueIntent,
|
|
44
39
|
falseIntent: params.falseIntent
|
|
45
40
|
}
|
|
46
41
|
}
|
|
47
42
|
else {
|
|
43
|
+
winston.warn("DirIfOnlineAgents Incorrect directive: ", directive);
|
|
48
44
|
callback();
|
|
49
45
|
return;
|
|
50
46
|
}
|
|
@@ -54,56 +50,55 @@ class DirIfOnlineAgents {
|
|
|
54
50
|
}
|
|
55
51
|
|
|
56
52
|
go(action, callback) {
|
|
53
|
+
winston.debug("(DirIfOnlineAgents) Action: ", action);
|
|
54
|
+
|
|
57
55
|
if (!action.trueIntent && !action.falseIntent) {
|
|
58
|
-
|
|
59
|
-
console.log("Error DirIfOnlineAgents: missing both action.trueIntent & action.falseIntent");
|
|
60
|
-
}
|
|
56
|
+
winston.error("(DirIfOnlineAgents) Error: missing both action.trueIntent & action.falseIntent");
|
|
61
57
|
callback();
|
|
62
58
|
return;
|
|
63
59
|
}
|
|
64
60
|
const trueIntent = action.trueIntent;
|
|
65
61
|
const falseIntent = action.falseIntent;
|
|
66
|
-
if (this.log) {
|
|
67
|
-
console.log("(DirIfOnlineAgents) IfOnlineAgents:trueIntent:", trueIntent);
|
|
68
|
-
console.log("(DirIfOnlineAgents) IfOnlineAgents:falseIntent:", falseIntent);
|
|
69
|
-
}
|
|
70
62
|
const trueIntentAttributes = action.trueIntentAttributes;
|
|
71
63
|
const falseIntentAttributes = action.falseIntentAttributes;
|
|
64
|
+
|
|
65
|
+
winston.debug("(DirIfOnlineAgents) IfOnlineAgents:trueIntent: " + trueIntent);
|
|
66
|
+
winston.debug("(DirIfOnlineAgents) IfOnlineAgents:falseIntent: " + falseIntent);
|
|
67
|
+
|
|
72
68
|
let stopOnConditionMet = action.stopOnConditionMet;
|
|
73
69
|
this.tdClient.openNow((err, result) => {
|
|
74
|
-
|
|
70
|
+
winston.debug("(DirIfOnlineAgents) openNow(): ", result);
|
|
75
71
|
if (err) {
|
|
76
|
-
|
|
72
|
+
winston.error("(DirIfOnlineAgents) openNow Error: ", err);
|
|
77
73
|
callback();
|
|
78
74
|
return;
|
|
79
75
|
}
|
|
80
76
|
else {
|
|
81
77
|
if (result && result.isopen) {
|
|
82
78
|
this.tdClient.getProjectAvailableAgents((err, agents) => {
|
|
83
|
-
if (this.log) {console.log("Agents", agents);}
|
|
84
79
|
if (err) {
|
|
85
|
-
|
|
80
|
+
winston.error("(DirIfOnlineAgents) Error getting available agents: ", err);
|
|
86
81
|
callback();
|
|
87
82
|
}
|
|
88
83
|
else {
|
|
89
|
-
|
|
84
|
+
winston.debug("(DirIfOnlineAgents) Agents count: " + agents.length);
|
|
90
85
|
if (agents.length > 0) {
|
|
91
86
|
if (trueIntent) {
|
|
92
87
|
let intentDirective = DirIntent.intentDirectiveFor(trueIntent, trueIntentAttributes);
|
|
93
|
-
|
|
88
|
+
winston.debug("(DirIfOnlineAgents) agents (openHours) => trueIntent");
|
|
94
89
|
this.intentDir.execute(intentDirective, () => {
|
|
95
90
|
callback(stopOnConditionMet);
|
|
96
91
|
});
|
|
97
92
|
}
|
|
98
93
|
else {
|
|
99
|
-
|
|
94
|
+
winston.debug("(DirIfOnlineAgents) NO IfOnlineAgents trueIntent defined. callback()") // prod
|
|
100
95
|
callback();
|
|
101
96
|
return;
|
|
102
97
|
}
|
|
103
98
|
}
|
|
104
99
|
else if (falseIntent) {
|
|
105
100
|
let intentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
|
|
106
|
-
|
|
101
|
+
winston.debug("(DirIfOnlineAgents) !agents (openHours) => falseIntent: ", intentDirective);
|
|
107
102
|
this.intentDir.execute(intentDirective, () => {
|
|
108
103
|
callback(stopOnConditionMet);
|
|
109
104
|
});
|
|
@@ -117,8 +112,7 @@ class DirIfOnlineAgents {
|
|
|
117
112
|
else if (result && !result.isopen) {
|
|
118
113
|
if (falseIntent) {
|
|
119
114
|
let intentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
|
|
120
|
-
|
|
121
|
-
console.log("!agents (!openHours) => falseIntent BECAUSE CLOSED"); //PROD
|
|
115
|
+
winston.debug("(DirIfOnlineAgents) !agents (!openHours) => falseIntent BECAUSE CLOSED"); //PROD
|
|
122
116
|
this.intentDir.execute(intentDirective, () => {
|
|
123
117
|
callback();
|
|
124
118
|
});
|
|
@@ -128,8 +122,7 @@ class DirIfOnlineAgents {
|
|
|
128
122
|
}
|
|
129
123
|
}
|
|
130
124
|
else {
|
|
131
|
-
|
|
132
|
-
console.log("undeterminate result.");
|
|
125
|
+
winston.verbose("(DirIfOnlineAgents) undeterminate result.");
|
|
133
126
|
callback();
|
|
134
127
|
}
|
|
135
128
|
}
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
const { DirIntent } = require('./DirIntent');
|
|
3
3
|
const axios = require("axios").default;
|
|
4
4
|
let https = require("https");
|
|
5
|
-
const { TiledeskChatbot } = require('../../
|
|
5
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
6
6
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
7
|
+
const winston = require('../../utils/winston');
|
|
8
|
+
const httpUtils = require('../../utils/HttpUtils');
|
|
7
9
|
|
|
8
10
|
class DirIfOnlineAgentsV2 {
|
|
9
11
|
|
|
@@ -28,11 +30,13 @@ class DirIfOnlineAgentsV2 {
|
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
execute(directive, callback) {
|
|
33
|
+
winston.verbose("Execute IfOnlineAgentsV2 directive");
|
|
31
34
|
let action;
|
|
32
35
|
if (directive.action) {
|
|
33
36
|
action = directive.action
|
|
34
37
|
}
|
|
35
38
|
else {
|
|
39
|
+
winston.warn("DirIfOnlineAgentsV2 Incorrect directive: ", directive);
|
|
36
40
|
callback();
|
|
37
41
|
return;
|
|
38
42
|
}
|
|
@@ -42,22 +46,21 @@ class DirIfOnlineAgentsV2 {
|
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
async go(action, callback) {
|
|
45
|
-
|
|
49
|
+
winston.debug("(DirIfOnlineAgentsV2) Action: ", action);
|
|
50
|
+
|
|
46
51
|
if (!action.trueIntent && !action.falseIntent) {
|
|
47
|
-
|
|
48
|
-
console.log("Error DirIfOnlineAgents: missing both action.trueIntent & action.falseIntent");
|
|
49
|
-
}
|
|
52
|
+
winston.error("(DirIfOnlineAgentsV2) Error: missing both action.trueIntent & action.falseIntent");
|
|
50
53
|
callback();
|
|
51
54
|
return;
|
|
52
55
|
}
|
|
53
56
|
const trueIntent = action.trueIntent;
|
|
54
57
|
const falseIntent = action.falseIntent;
|
|
55
|
-
if (this.log) {
|
|
56
|
-
console.log("(DirIfOnlineAgents) IfOnlineAgents:trueIntent:", trueIntent);
|
|
57
|
-
console.log("(DirIfOnlineAgents) IfOnlineAgents:falseIntent:", falseIntent);
|
|
58
|
-
}
|
|
59
58
|
const trueIntentAttributes = action.trueIntentAttributes;
|
|
60
59
|
const falseIntentAttributes = action.falseIntentAttributes;
|
|
60
|
+
|
|
61
|
+
winston.debug("(DirIfOnlineAgentsV2) IfOnlineAgents:trueIntent: " + trueIntent);
|
|
62
|
+
winston.debug("(DirIfOnlineAgentsV2) IfOnlineAgents:falseIntent: " + falseIntent);
|
|
63
|
+
|
|
61
64
|
let stopOnConditionMet = true; //action.stopOnConditionMet;
|
|
62
65
|
|
|
63
66
|
try {
|
|
@@ -83,18 +86,15 @@ class DirIfOnlineAgentsV2 {
|
|
|
83
86
|
|
|
84
87
|
let agents;
|
|
85
88
|
if (selectedOption === "currentDep") {
|
|
86
|
-
|
|
89
|
+
winston.debug("(DirIfOnlineAgentsV2) currentDep");
|
|
87
90
|
let departmentId = await this.chatbot.getParameter("department_id");
|
|
88
|
-
|
|
91
|
+
winston.debug("(DirIfOnlineAgentsV2) this.context.departmentId: " + departmentId);
|
|
89
92
|
|
|
90
93
|
if (departmentId) {
|
|
91
|
-
if (this.log) {console.log("(DirIfOnlineAgents) agents = await this.getProjectAvailableAgents(", departmentId, ", true);"); }
|
|
92
94
|
agents = await this.getProjectAvailableAgents(departmentId, true);
|
|
93
|
-
if (this.log) {console.log("(DirIfOnlineAgents) agents:", agents); }
|
|
94
95
|
} else {
|
|
95
|
-
|
|
96
|
+
winston.error("(DirIfOnlineAgentsV2) no departmentId found in attributes");
|
|
96
97
|
await this.chatbot.addParameter("flowError", "(If online Agents) No departmentId found in attributes.");
|
|
97
|
-
if (this.log) {console.log("(DirIfOnlineAgents) flowError added in attributes", await this.chatbot.getParameter("flowError") ); }
|
|
98
98
|
if (falseIntent) { // no agents available
|
|
99
99
|
let intentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
|
|
100
100
|
this.intentDir.execute(intentDirective, () => {
|
|
@@ -108,29 +108,23 @@ class DirIfOnlineAgentsV2 {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
else if (selectedOption === "selectedDep") {
|
|
112
|
-
if (this.log) {console.log("(DirIfOnlineAgents) selectedOption === selectedDep", action.selectedDepartmentId); }
|
|
113
|
-
if (this.log) {console.log("(DirIfOnlineAgents) agents = await this.getProjectAvailableAgents(", action.selectedDepartmentId, ", true);"); }
|
|
114
|
-
|
|
111
|
+
else if (selectedOption === "selectedDep") {
|
|
115
112
|
agents = await this.getProjectAvailableAgents(action.selectedDepartmentId, true);
|
|
116
|
-
if (this.log) {console.log("(DirIfOnlineAgents) agents:", agents); }
|
|
117
113
|
}
|
|
118
114
|
else { // if (checkAll) => go project-wide
|
|
119
|
-
if (this.log) {console.log("(DirIfOnlineAgents) selectedOption === all | getProjectAvailableAgents(null, true)"); }
|
|
120
115
|
agents = await this.getProjectAvailableAgents(null, true);
|
|
121
|
-
if (this.log) {console.log("(DirIfOnlineAgents) agents:", agents); }
|
|
122
116
|
}
|
|
123
117
|
|
|
124
118
|
if (agents && agents.length > 0) {
|
|
125
119
|
if (trueIntent) {
|
|
126
120
|
let intentDirective = DirIntent.intentDirectiveFor(trueIntent, trueIntentAttributes);
|
|
127
|
-
|
|
121
|
+
winston.debug("(DirIfOnlineAgentsV2) agents (openHours) => trueIntent");
|
|
128
122
|
this.intentDir.execute(intentDirective, () => {
|
|
129
123
|
callback(stopOnConditionMet);
|
|
130
124
|
});
|
|
131
125
|
}
|
|
132
126
|
else {
|
|
133
|
-
|
|
127
|
+
winston.debug("(DirIfOnlineAgentsV2) No IfOnlineAgents trueIntent defined. callback()"); // prod
|
|
134
128
|
this.chatbot.addParameter("flowError", "(If online Agents) No IfOnlineAgents success path defined.");
|
|
135
129
|
callback();
|
|
136
130
|
return;
|
|
@@ -138,20 +132,20 @@ class DirIfOnlineAgentsV2 {
|
|
|
138
132
|
}
|
|
139
133
|
else if (falseIntent) { // no agents available
|
|
140
134
|
let intentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
|
|
141
|
-
|
|
135
|
+
winston.debug("(DirIfOnlineAgentsV2) !agents (openHours) => falseIntent", intentDirective);
|
|
142
136
|
this.intentDir.execute(intentDirective, () => {
|
|
143
137
|
callback(stopOnConditionMet);
|
|
144
138
|
});
|
|
145
139
|
}
|
|
146
140
|
else {
|
|
147
|
-
|
|
141
|
+
winston.error("(DirIfOnlineAgentsV2) Error: No falseIntent defined", intentDirective);
|
|
148
142
|
this.chatbot.addParameter("flowError", "(If online Agents) No path for 'no available agents' defined.");
|
|
149
143
|
callback();
|
|
150
144
|
}
|
|
151
145
|
} else {
|
|
152
146
|
if (falseIntent) {
|
|
153
147
|
let intentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
|
|
154
|
-
|
|
148
|
+
winston.debug("(DirIfOnlineAgentsV2) !agents (!openHours) => falseIntent");
|
|
155
149
|
this.intentDir.execute(intentDirective, () => {
|
|
156
150
|
callback();
|
|
157
151
|
});
|
|
@@ -162,7 +156,7 @@ class DirIfOnlineAgentsV2 {
|
|
|
162
156
|
}
|
|
163
157
|
}
|
|
164
158
|
catch(err) {
|
|
165
|
-
|
|
159
|
+
winston.error("(DirIfOnlineAgentsV2) An error occurred: ", err);
|
|
166
160
|
this.chatbot.addParameter("flowError", "(If online Agents) An error occurred: " + err);
|
|
167
161
|
callback();
|
|
168
162
|
}
|
|
@@ -171,7 +165,7 @@ class DirIfOnlineAgentsV2 {
|
|
|
171
165
|
async openNow() {
|
|
172
166
|
return new Promise( (resolve, reject) => {
|
|
173
167
|
this.tdClient.openNow(async (err, result) => {
|
|
174
|
-
|
|
168
|
+
winston.debug("(DirIfOnlineAgentsV2) openNow(): ", result);
|
|
175
169
|
if (err) {
|
|
176
170
|
reject(err);
|
|
177
171
|
}
|
|
@@ -197,7 +191,7 @@ class DirIfOnlineAgentsV2 {
|
|
|
197
191
|
// json: true,
|
|
198
192
|
method: 'GET',
|
|
199
193
|
};
|
|
200
|
-
|
|
194
|
+
httpUtils.request(
|
|
201
195
|
HTTPREQUEST,
|
|
202
196
|
function(err, resbody) {
|
|
203
197
|
if (err) {
|
|
@@ -217,54 +211,6 @@ class DirIfOnlineAgentsV2 {
|
|
|
217
211
|
|
|
218
212
|
}
|
|
219
213
|
|
|
220
|
-
#myrequest(options, callback) {
|
|
221
|
-
if (this.log) {
|
|
222
|
-
console.log("API URL:", options.url);
|
|
223
|
-
console.log("** Options:", JSON.stringify(options));
|
|
224
|
-
}
|
|
225
|
-
let axios_options = {
|
|
226
|
-
url: options.url,
|
|
227
|
-
method: options.method,
|
|
228
|
-
params: options.params,
|
|
229
|
-
headers: options.headers
|
|
230
|
-
}
|
|
231
|
-
if (options.json !== null) {
|
|
232
|
-
axios_options.data = options.json
|
|
233
|
-
}
|
|
234
|
-
if (this.log) {
|
|
235
|
-
console.log("axios_options:", JSON.stringify(axios_options));
|
|
236
|
-
}
|
|
237
|
-
if (options.url.startsWith("https:")) {
|
|
238
|
-
const httpsAgent = new https.Agent({
|
|
239
|
-
rejectUnauthorized: false,
|
|
240
|
-
});
|
|
241
|
-
axios_options.httpsAgent = httpsAgent;
|
|
242
|
-
}
|
|
243
|
-
axios(axios_options)
|
|
244
|
-
.then((res) => {
|
|
245
|
-
if (this.log) {
|
|
246
|
-
console.log("Response for url:", options.url);
|
|
247
|
-
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
248
|
-
}
|
|
249
|
-
if (res && res.status == 200 && res.data) {
|
|
250
|
-
if (callback) {
|
|
251
|
-
callback(null, res.data);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
if (callback) {
|
|
256
|
-
callback(new Error("Response status is not 200"), null);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
})
|
|
260
|
-
.catch((error) => {
|
|
261
|
-
console.error("(DirIfOnlineAgents) Axios error: ", JSON.stringify(error));
|
|
262
|
-
if (callback) {
|
|
263
|
-
callback(error, null);
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
|
|
268
214
|
fixToken(token) {
|
|
269
215
|
if (token.startsWith('JWT ')) {
|
|
270
216
|
return token
|