@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,9 +1,12 @@
|
|
|
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
|
let https = require("https");
|
|
5
5
|
const { DirIntent } = require("./DirIntent");
|
|
6
6
|
require('dotenv').config();
|
|
7
|
+
const winston = require('../../utils/winston');
|
|
8
|
+
const httpUtils = require("../../utils/HttpUtils");
|
|
9
|
+
const integrationService = require("../../services/IntegrationService");
|
|
7
10
|
|
|
8
11
|
class DirAskGPT {
|
|
9
12
|
|
|
@@ -14,19 +17,21 @@ class DirAskGPT {
|
|
|
14
17
|
this.context = context;
|
|
15
18
|
this.tdcache = this.context.tdcache;
|
|
16
19
|
this.requestId = this.context.requestId;
|
|
20
|
+
this.projectId = this.context.projectId;
|
|
21
|
+
this.token = this.context.token;
|
|
17
22
|
this.intentDir = new DirIntent(context);
|
|
18
23
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
19
24
|
this.log = context.log;
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
execute(directive, callback) {
|
|
23
|
-
|
|
28
|
+
winston.verbose("Execute AskGPT directive");
|
|
24
29
|
let action;
|
|
25
30
|
if (directive.action) {
|
|
26
31
|
action = directive.action;
|
|
27
32
|
}
|
|
28
33
|
else {
|
|
29
|
-
|
|
34
|
+
winston.warn("DirAskGPT Incorrect directive: ", directive);
|
|
30
35
|
callback();
|
|
31
36
|
return;
|
|
32
37
|
}
|
|
@@ -36,9 +41,9 @@ class DirAskGPT {
|
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
async go(action, callback) {
|
|
39
|
-
|
|
44
|
+
winston.debug("(DirAskGPT) Action: ", action);
|
|
40
45
|
if (!this.tdcache) {
|
|
41
|
-
|
|
46
|
+
winston.error("Error: DirAskGPT tdcache is mandatory");
|
|
42
47
|
callback();
|
|
43
48
|
return;
|
|
44
49
|
}
|
|
@@ -49,19 +54,17 @@ class DirAskGPT {
|
|
|
49
54
|
let trueIntentAttributes = action.trueIntentAttributes;
|
|
50
55
|
let falseIntentAttributes = action.falseIntentAttributes;
|
|
51
56
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
console.log("DirAskGPT falseIntentAttributes", falseIntentAttributes)
|
|
57
|
-
}
|
|
57
|
+
winston.debug("(DirAskGPT) trueIntent " + trueIntent)
|
|
58
|
+
winston.debug("(DirAskGPT) falseIntent " + falseIntent)
|
|
59
|
+
winston.debug("(DirAskGPT) trueIntentAttributes " + trueIntentAttributes)
|
|
60
|
+
winston.debug("(DirAskGPT) falseIntentAttributes " + falseIntentAttributes)
|
|
58
61
|
|
|
59
62
|
// default values
|
|
60
63
|
let answer = "No answers";
|
|
61
64
|
let source = null;
|
|
62
65
|
|
|
63
66
|
if (!action.question || action.question === '') {
|
|
64
|
-
|
|
67
|
+
winston.error("(DirAskGPT) Error: question attribute is mandatory. Executing condition false...");
|
|
65
68
|
await this.#assignAttributes(action, answer, source);
|
|
66
69
|
if (falseIntent) {
|
|
67
70
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -71,7 +74,7 @@ class DirAskGPT {
|
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
if (!action.kbid) {
|
|
74
|
-
|
|
77
|
+
winston.error("(DirAskGPT) Error: kbid attribute is mandatory. Executing condition false...");
|
|
75
78
|
await this.#assignAttributes(action, answer, source);
|
|
76
79
|
if (falseIntent) {
|
|
77
80
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes)
|
|
@@ -90,22 +93,22 @@ class DirAskGPT {
|
|
|
90
93
|
const filled_question = filler.fill(action.question, requestVariables);
|
|
91
94
|
|
|
92
95
|
const kb_endpoint = process.env.KB_ENDPOINT;
|
|
93
|
-
|
|
96
|
+
winston.verbose("DirAskGPT KbEndpoint URL: ", kb_endpoint);
|
|
94
97
|
|
|
95
|
-
let key = await
|
|
98
|
+
let key = await integrationService.getKeyFromIntegrations(this.projectId, 'openai', this.token);
|
|
96
99
|
if (!key) {
|
|
97
|
-
|
|
100
|
+
winston.debug("(DirAskGPT) - Key not found in Integrations. Searching in kb settings...");
|
|
98
101
|
key = await this.getKeyFromKbSettings();
|
|
99
102
|
}
|
|
100
103
|
|
|
101
104
|
if (!key) {
|
|
102
|
-
|
|
105
|
+
winston.debug("(DirAskGPT) - Retrieve public gptkey")
|
|
103
106
|
key = process.env.GPTKEY;
|
|
104
107
|
publicKey = true;
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
if (!key) {
|
|
108
|
-
|
|
111
|
+
winston.error("(DirAskGPT) Error: gptkey is mandatory");
|
|
109
112
|
await this.#assignAttributes(action, answer);
|
|
110
113
|
if (falseIntent) {
|
|
111
114
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -119,7 +122,7 @@ class DirAskGPT {
|
|
|
119
122
|
if (publicKey === true) {
|
|
120
123
|
let keep_going = await this.checkQuoteAvailability();
|
|
121
124
|
if (keep_going === false) {
|
|
122
|
-
|
|
125
|
+
winston.debug("(DirAskGPT) - Quota exceeded for tokens. Skip the action")
|
|
123
126
|
callback();
|
|
124
127
|
return;
|
|
125
128
|
}
|
|
@@ -130,26 +133,25 @@ class DirAskGPT {
|
|
|
130
133
|
kbid: action.kbid,
|
|
131
134
|
gptkey: key
|
|
132
135
|
};
|
|
133
|
-
|
|
136
|
+
winston.debug("(DirAskGPT)DirAskGPT json:", json);
|
|
134
137
|
|
|
135
138
|
const HTTPREQUEST = {
|
|
136
139
|
url: kb_endpoint + "/qa",
|
|
137
140
|
json: json,
|
|
138
141
|
method: "POST"
|
|
139
142
|
}
|
|
140
|
-
|
|
143
|
+
winston.debug("(DirAskGPT) HttpRequest", HTTPREQUEST);
|
|
141
144
|
|
|
142
|
-
|
|
145
|
+
httpUtils.request(
|
|
143
146
|
HTTPREQUEST, async (err, resbody) => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
if (this.log) { console.log("DirAskGPT resbody:", resbody); }
|
|
147
|
+
|
|
148
|
+
winston.debug("(DirAskGPT) resbody:", resbody);
|
|
148
149
|
let answer = resbody.answer;
|
|
149
150
|
let source = resbody.source_url;
|
|
150
151
|
await this.#assignAttributes(action, answer, source);
|
|
151
|
-
|
|
152
|
+
|
|
152
153
|
if (err) {
|
|
154
|
+
winston.error("(DirAskGPT) error: ", err);
|
|
153
155
|
if (callback) {
|
|
154
156
|
if (falseIntent) {
|
|
155
157
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -205,7 +207,7 @@ class DirAskGPT {
|
|
|
205
207
|
})
|
|
206
208
|
}
|
|
207
209
|
else {
|
|
208
|
-
|
|
210
|
+
winston.debug("(DirAskGPT) No trueIntentDirective specified");
|
|
209
211
|
if (callback) {
|
|
210
212
|
callback();
|
|
211
213
|
}
|
|
@@ -220,7 +222,7 @@ class DirAskGPT {
|
|
|
220
222
|
});
|
|
221
223
|
}
|
|
222
224
|
else {
|
|
223
|
-
|
|
225
|
+
winston.debug("(DirAskGPT) No falseIntentDirective specified");
|
|
224
226
|
if (callback) {
|
|
225
227
|
callback();
|
|
226
228
|
}
|
|
@@ -229,109 +231,17 @@ class DirAskGPT {
|
|
|
229
231
|
}
|
|
230
232
|
|
|
231
233
|
async #assignAttributes(action, answer, source) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
console.log("assignAttributes source:", source)
|
|
236
|
-
}
|
|
234
|
+
winston.debug("(DirAskGPT) assignAttributes action:", action)
|
|
235
|
+
winston.debug("(DirAskGPT) assignAttributes answer:", answer)
|
|
236
|
+
winston.debug("(DirAskGPT) assignAttributes source:", source)
|
|
237
237
|
if (this.context.tdcache) {
|
|
238
238
|
if (action.assignReplyTo && answer) {
|
|
239
239
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignReplyTo, answer);
|
|
240
240
|
}
|
|
241
|
-
// console.log("--> action.assignSourceTo: ", action.assignSourceTo)
|
|
242
|
-
// console.log("--> source: ", source)
|
|
243
241
|
if (action.assignSourceTo && source) {
|
|
244
|
-
// console.log("--> source: ", source)
|
|
245
242
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignSourceTo, source);
|
|
246
243
|
}
|
|
247
|
-
// Debug log
|
|
248
|
-
if (this.log) {
|
|
249
|
-
const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
|
|
250
|
-
for (const [key, value] of Object.entries(all_parameters)) {
|
|
251
|
-
if (this.log) { console.log("(askgpt) request parameter:", key, "value:", value, "type:", typeof value) }
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
#myrequest(options, callback) {
|
|
258
|
-
if (this.log) {
|
|
259
|
-
console.log("API URL:", options.url);
|
|
260
|
-
console.log("** Options:", JSON.stringify(options));
|
|
261
|
-
}
|
|
262
|
-
let axios_options = {
|
|
263
|
-
url: options.url,
|
|
264
|
-
method: options.method,
|
|
265
|
-
params: options.params,
|
|
266
|
-
headers: options.headers
|
|
267
244
|
}
|
|
268
|
-
if (options.json !== null) {
|
|
269
|
-
axios_options.data = options.json
|
|
270
|
-
}
|
|
271
|
-
if (this.log) {
|
|
272
|
-
console.log("axios_options:", JSON.stringify(axios_options));
|
|
273
|
-
}
|
|
274
|
-
if (options.url.startsWith("https:")) {
|
|
275
|
-
const httpsAgent = new https.Agent({
|
|
276
|
-
rejectUnauthorized: false,
|
|
277
|
-
});
|
|
278
|
-
axios_options.httpsAgent = httpsAgent;
|
|
279
|
-
}
|
|
280
|
-
axios(axios_options)
|
|
281
|
-
.then((res) => {
|
|
282
|
-
if (this.log) {
|
|
283
|
-
console.log("Response for url:", options.url);
|
|
284
|
-
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
285
|
-
}
|
|
286
|
-
if (res && res.status == 200 && res.data) {
|
|
287
|
-
if (callback) {
|
|
288
|
-
callback(null, res.data);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
else {
|
|
292
|
-
if (callback) {
|
|
293
|
-
callback(new Error("Response status is not 200"), null);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
})
|
|
297
|
-
.catch((error) => {
|
|
298
|
-
console.error("(DirAskGPT) Axios error: ", JSON.stringify(error));
|
|
299
|
-
if (callback) {
|
|
300
|
-
callback(error, null);
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
async getKeyFromIntegrations() {
|
|
306
|
-
return new Promise((resolve) => {
|
|
307
|
-
|
|
308
|
-
const INTEGRATIONS_HTTPREQUEST = {
|
|
309
|
-
url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/openai",
|
|
310
|
-
headers: {
|
|
311
|
-
'Content-Type': 'application/json',
|
|
312
|
-
'Authorization': 'JWT ' + this.context.token
|
|
313
|
-
},
|
|
314
|
-
method: "GET"
|
|
315
|
-
}
|
|
316
|
-
if (this.log) { console.log("DirAskGPT INTEGRATIONS_HTTPREQUEST ", INTEGRATIONS_HTTPREQUEST) }
|
|
317
|
-
|
|
318
|
-
this.#myrequest(
|
|
319
|
-
INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
|
|
320
|
-
if (err) {
|
|
321
|
-
if (this.log) { console.error("DirAskGPT Get integrations error ", err); }
|
|
322
|
-
resolve(null);
|
|
323
|
-
} else {
|
|
324
|
-
|
|
325
|
-
if (integration &&
|
|
326
|
-
integration.value) {
|
|
327
|
-
resolve(integration.value.apikey)
|
|
328
|
-
}
|
|
329
|
-
else {
|
|
330
|
-
resolve(null)
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
})
|
|
334
|
-
})
|
|
335
245
|
}
|
|
336
246
|
|
|
337
247
|
async getKeyFromKbSettings() {
|
|
@@ -345,12 +255,12 @@ class DirAskGPT {
|
|
|
345
255
|
},
|
|
346
256
|
method: "GET"
|
|
347
257
|
}
|
|
348
|
-
|
|
258
|
+
winston.debug("(DirAskGPT) KB HttpRequest ", KB_HTTPREQUEST);
|
|
349
259
|
|
|
350
|
-
|
|
260
|
+
httpUtils.request(
|
|
351
261
|
KB_HTTPREQUEST, async (err, resbody) => {
|
|
352
262
|
if (err) {
|
|
353
|
-
|
|
263
|
+
winston.error("DirAskGPT Get kb settings error ", err?.response?.data);
|
|
354
264
|
resolve(null);
|
|
355
265
|
} else {
|
|
356
266
|
if (!resbody.gptkey) {
|