@tiledesk/tiledesk-tybot-connector 2.0.16-rc4 → 2.0.16
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 +3 -28
- package/Logger.js +4 -14
- package/TdCache copy.js +242 -0
- package/engine/mock/MockBotsDataSource.js +2 -1
- package/index.js +0 -3
- package/logs/app.log +44714 -5981
- package/logs/app1.log +16653 -0
- package/package.json +2 -2
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +11 -29
- package/tiledeskChatbotPlugs/directives/DirAddKbContent.js +21 -20
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +6 -5
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +8 -7
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +21 -53
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +5 -4
- package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirClose.js +3 -2
- package/tiledeskChatbotPlugs/directives/DirCode.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirCondition.js +4 -3
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +4 -3
- package/tiledeskChatbotPlugs/directives/DirFlowLog.js +5 -5
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +5 -4
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +4 -3
- package/tiledeskChatbotPlugs/directives/DirIntent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +5 -4
- package/tiledeskChatbotPlugs/directives/DirMake.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirQapla.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirReply.js +5 -6
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirWait.js +3 -2
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +9 -8
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +418 -0
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +3 -2
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +2 -1
- package/tiledeskChatbotPlugs/directives/Directives.js +0 -1
- package/utils/TiledeskChatbotUtil.js +25 -4
- package/logs/app4.log +0 -46163
- package/logs/app5.log +0 -39983
- package/logs/app6.log +0 -50376
- package/logs/app7.log +0 -43568
- package/logs/app8.log +0 -4779
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiledesk/tiledesk-tybot-connector",
|
|
3
|
-
"version": "2.0.16
|
|
3
|
+
"version": "2.0.16",
|
|
4
4
|
"description": "Tiledesk Tybot connector",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"@tiledesk/tiledesk-chatbot-client": "^0.5.30",
|
|
16
16
|
"@tiledesk/tiledesk-chatbot-util": "^0.8.39",
|
|
17
17
|
"@tiledesk/tiledesk-client": "^0.10.13",
|
|
18
|
-
"@tiledesk/tiledesk-multi-worker": "^0.3.
|
|
18
|
+
"@tiledesk/tiledesk-multi-worker": "^0.3.1-rc10",
|
|
19
19
|
"accept-language-parser": "^1.5.0",
|
|
20
20
|
"app-root-path": "^3.1.0",
|
|
21
21
|
"axios": "^1.7.7",
|
|
@@ -54,13 +54,13 @@ const { DirMoveToUnassigned } = require('./directives/DirMoveToUnassigned');
|
|
|
54
54
|
const { DirAddTags } = require('./directives/DirAddTags');
|
|
55
55
|
const { DirSendWhatsapp } = require('./directives/DirSendWhatsapp');
|
|
56
56
|
const { DirReplaceBotV3 } = require('./directives/DirReplaceBotV3');
|
|
57
|
-
const { DirAiPrompt } = require('./directives/DirAiPrompt');
|
|
57
|
+
const { DirAiTask, DirAiPrompt } = require('./directives/DirAiPrompt');
|
|
58
58
|
const { DirWebResponse } = require('./directives/DirWebResponse');
|
|
59
59
|
const { DirConnectBlock } = require('./directives/DirConnectBlock');
|
|
60
|
-
const { DirAddKbContent } = require('./directives/DirAddKbContent');
|
|
61
|
-
const { DirFlowLog } = require('./directives/DirFlowLog');
|
|
62
60
|
|
|
63
61
|
const winston = require('../utils/winston');
|
|
62
|
+
const { DirFlowLog } = require('./directives/DirFlowLog');
|
|
63
|
+
const { DirAddKbContent } = require('./directives/DirAddKbContent');
|
|
64
64
|
|
|
65
65
|
class DirectivesChatbotPlug {
|
|
66
66
|
|
|
@@ -219,13 +219,14 @@ class DirectivesChatbotPlug {
|
|
|
219
219
|
directive_name = directive.name.toLowerCase();
|
|
220
220
|
}
|
|
221
221
|
if (directive && directive.action) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
222
|
+
const action_id = directive.action["_tdActionId"];
|
|
223
|
+
const locked_action_id = await this.chatbot.currentLockedAction(this.supportRequest.request_id);
|
|
224
|
+
if ( locked_action_id && (locked_action_id !== action_id) ) {
|
|
225
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
226
|
+
this.process(next_dir);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
229
230
|
}
|
|
230
231
|
if (directive == null || (directive !== null && directive["name"] === undefined)) {
|
|
231
232
|
winston.debug("(DirectivesChatbotPlug) stop process(). directive is (null?): ", directive);
|
|
@@ -703,19 +704,6 @@ class DirectivesChatbotPlug {
|
|
|
703
704
|
}
|
|
704
705
|
});
|
|
705
706
|
}
|
|
706
|
-
else if (directive_name === Directives.WEBHOOK) {
|
|
707
|
-
// console.log(".....DirIntent")
|
|
708
|
-
new DirIntent(context).execute(directive, async (stop) => {
|
|
709
|
-
if (stop) {
|
|
710
|
-
if (context.log) { console.log("Stopping Actions on:", JSON.stringify(directive));}
|
|
711
|
-
this.theend();
|
|
712
|
-
}
|
|
713
|
-
else {
|
|
714
|
-
let next_dir = await this.nextDirective(this.directives);
|
|
715
|
-
this.process(next_dir);
|
|
716
|
-
}
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
707
|
else if (directive_name === Directives.WEB_RESPONSE) {
|
|
720
708
|
new DirWebResponse(context).execute(directive, async () => {
|
|
721
709
|
let next_dir = await this.nextDirective(this.directives);
|
|
@@ -728,12 +716,6 @@ class DirectivesChatbotPlug {
|
|
|
728
716
|
this.process(next_dir);
|
|
729
717
|
})
|
|
730
718
|
}
|
|
731
|
-
else if (directive_name === Directives.ADD_KB_CONTENT) {
|
|
732
|
-
new DirAddKbContent(context).execute(directive, async () => {
|
|
733
|
-
let next_dir = await this.nextDirective(this.directives);
|
|
734
|
-
this.process(next_dir);
|
|
735
|
-
});
|
|
736
|
-
}
|
|
737
719
|
else {
|
|
738
720
|
let next_dir = await this.nextDirective(this.directives);
|
|
739
721
|
this.process(next_dir);
|
|
@@ -32,19 +32,20 @@ class DirAddKbContent {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
execute(directive, callback) {
|
|
35
|
-
|
|
35
|
+
this.logger.info("Execute AskKnowledgeBase action")
|
|
36
|
+
winston.debug("DirAskGPTV2 directive: ", directive);
|
|
36
37
|
let action;
|
|
37
38
|
if (directive.action) {
|
|
38
39
|
action = directive.action;
|
|
39
40
|
}
|
|
40
41
|
else {
|
|
41
42
|
this.logger.error("Incorrect action for ", directive.name, directive)
|
|
42
|
-
winston.debug("
|
|
43
|
+
winston.debug("DirAskGPTV2 Incorrect directive: ", directive);
|
|
43
44
|
callback();
|
|
44
45
|
return;
|
|
45
46
|
}
|
|
46
47
|
this.go(action, (stop) => {
|
|
47
|
-
this.logger.
|
|
48
|
+
this.logger.info("Acion AskKnowledgeBase completed");
|
|
48
49
|
callback(stop);
|
|
49
50
|
})
|
|
50
51
|
}
|
|
@@ -85,7 +86,7 @@ class DirAddKbContent {
|
|
|
85
86
|
|
|
86
87
|
let key = await integrationService.getKeyFromIntegrations(this.projectId, 'openai', this.token);
|
|
87
88
|
if (!key) {
|
|
88
|
-
this.logger.
|
|
89
|
+
this.logger.debug("[DirAddKbContent] OpenAI key not found in Integration. Using shared OpenAI key");
|
|
89
90
|
winston.verbose("[DirAddKbContent] - Key not found in Integrations. Searching in kb settings...");
|
|
90
91
|
key = await this.getKeyFromKbSettings();
|
|
91
92
|
}
|
|
@@ -95,7 +96,7 @@ class DirAddKbContent {
|
|
|
95
96
|
key = process.env.GPTKEY;
|
|
96
97
|
publicKey = true;
|
|
97
98
|
} else {
|
|
98
|
-
this.logger.
|
|
99
|
+
this.logger.debug("[DirAddKbContent] use your own OpenAI key")
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
if (!key) {
|
|
@@ -108,7 +109,7 @@ class DirAddKbContent {
|
|
|
108
109
|
if (publicKey === true) {
|
|
109
110
|
let keep_going = await this.checkQuoteAvailability();
|
|
110
111
|
if (keep_going === false) {
|
|
111
|
-
this.logger.warn("[
|
|
112
|
+
this.logger.warn("[DirAddKbContent] Tokens quota exceeded. Skip the action")
|
|
112
113
|
winston.verbose("[DirAddKbContent] - Quota exceeded for tokens. Skip the action")
|
|
113
114
|
await this.chatbot.addParameter("flowError", "[DirAddKbContent] Error: tokens quota exceeded");
|
|
114
115
|
callback(true);
|
|
@@ -121,17 +122,17 @@ class DirAddKbContent {
|
|
|
121
122
|
if (action.namespaceAsName) {
|
|
122
123
|
// Namespace could be an attribute
|
|
123
124
|
const filled_namespace = filler.fill(action.namespace, requestVariables)
|
|
124
|
-
this.logger.
|
|
125
|
+
this.logger.debug("[DirAddKbContent] Searching namespace by name ", filled_namespace);
|
|
125
126
|
ns = await this.getNamespace(filled_namespace, null);
|
|
126
127
|
namespace = ns?.id;
|
|
127
128
|
winston.verbose("[DirAddKbContent] - Retrieved namespace id from name " + namespace);
|
|
128
129
|
} else {
|
|
129
|
-
this.logger.
|
|
130
|
+
this.logger.debug("[DirAddKbContent] Searching namespace by id ", namespace);
|
|
130
131
|
ns = await this.getNamespace(null, namespace);
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
if (!ns) {
|
|
134
|
-
this.logger.error("[
|
|
135
|
+
this.logger.error("[DirAddKbContent] Namespace not found");
|
|
135
136
|
await this.chatbot.addParameter("flowError", "[DirAddKbContent] Error: namespace not found");
|
|
136
137
|
callback();
|
|
137
138
|
return;
|
|
@@ -144,7 +145,7 @@ class DirAddKbContent {
|
|
|
144
145
|
}
|
|
145
146
|
|
|
146
147
|
if (!namespace) {
|
|
147
|
-
this.logger.error("[
|
|
148
|
+
this.logger.error("[DirAddKbContent] Namespace is undefined")
|
|
148
149
|
winston.verbose("[DirAddKbContent] - Error: namespace is undefined")
|
|
149
150
|
await this.chatbot.addParameter("flowError", "[DirAddKbContent] Error: namespace is undefined");
|
|
150
151
|
callback(true);
|
|
@@ -176,7 +177,7 @@ class DirAddKbContent {
|
|
|
176
177
|
HTTPREQUEST, async (err, resbody) => {
|
|
177
178
|
|
|
178
179
|
if (err) {
|
|
179
|
-
this.logger.error("[
|
|
180
|
+
this.logger.error("[DirAddKbContent] error: " + JSON.stringify(err?.response));
|
|
180
181
|
winston.error("[DirAddKbContent] error: ", err?.response);
|
|
181
182
|
if (callback) {
|
|
182
183
|
callback();
|
|
@@ -206,12 +207,12 @@ class DirAddKbContent {
|
|
|
206
207
|
},
|
|
207
208
|
method: "GET"
|
|
208
209
|
}
|
|
209
|
-
winston.debug("
|
|
210
|
+
winston.debug("DirAskGPTV2 KB HttpRequest", KB_HTTPREQUEST);
|
|
210
211
|
|
|
211
212
|
httpUtils.request(
|
|
212
213
|
KB_HTTPREQUEST, async (err, resbody) => {
|
|
213
214
|
if (err) {
|
|
214
|
-
winston.error("
|
|
215
|
+
winston.error("DirAskGPTV2 Get kb settings error ", err?.response?.data);
|
|
215
216
|
resolve(null);
|
|
216
217
|
} else {
|
|
217
218
|
if (!resbody.gptkey) {
|
|
@@ -236,12 +237,12 @@ class DirAddKbContent {
|
|
|
236
237
|
},
|
|
237
238
|
method: "GET"
|
|
238
239
|
}
|
|
239
|
-
winston.debug("
|
|
240
|
+
winston.debug("DirAskGPTV2 check quote availability HttpRequest", HTTPREQUEST);
|
|
240
241
|
|
|
241
242
|
httpUtils.request(
|
|
242
243
|
HTTPREQUEST, async (err, resbody) => {
|
|
243
244
|
if (err) {
|
|
244
|
-
winston.error("
|
|
245
|
+
winston.error("DirAskGPTV2 Check quote availability err: ", err);
|
|
245
246
|
resolve(true)
|
|
246
247
|
} else {
|
|
247
248
|
if (resbody.isAvailable === true) {
|
|
@@ -267,12 +268,12 @@ class DirAddKbContent {
|
|
|
267
268
|
json: tokens_usage,
|
|
268
269
|
method: "POST"
|
|
269
270
|
}
|
|
270
|
-
winston.debug("
|
|
271
|
+
winston.debug("DirAskGPTV2 update quote HttpRequest ", HTTPREQUEST);
|
|
271
272
|
|
|
272
273
|
httpUtils.request(
|
|
273
274
|
HTTPREQUEST, async (err, resbody) => {
|
|
274
275
|
if (err) {
|
|
275
|
-
winston.error("
|
|
276
|
+
winston.error("DirAskGPTV2 Increment tokens quote err: ", err);
|
|
276
277
|
reject(false)
|
|
277
278
|
} else {
|
|
278
279
|
resolve(true);
|
|
@@ -292,14 +293,14 @@ class DirAddKbContent {
|
|
|
292
293
|
},
|
|
293
294
|
method: "GET"
|
|
294
295
|
}
|
|
295
|
-
winston.debug("
|
|
296
|
+
winston.debug("DirAskGPTV2 get all namespaces HttpRequest", HTTPREQUEST);
|
|
296
297
|
httpUtils.request(
|
|
297
298
|
HTTPREQUEST, async (err, namespaces) => {
|
|
298
299
|
if (err) {
|
|
299
|
-
winston.error("
|
|
300
|
+
winston.error("DirAskGPTV2 get all namespaces err: ", err);
|
|
300
301
|
resolve(null)
|
|
301
302
|
} else {
|
|
302
|
-
winston.debug("
|
|
303
|
+
winston.debug("DirAskGPTV2 get all namespaces resbody: ", namespaces);
|
|
303
304
|
if (name) {
|
|
304
305
|
let namespace = namespaces.find(n => n.name === name);
|
|
305
306
|
resolve(namespace);
|
|
@@ -30,6 +30,7 @@ class DirAddTags {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
execute(directive, callback) {
|
|
33
|
+
this.logger.info("[Add Tag] Executing action")
|
|
33
34
|
winston.verbose("Execute AddTags action");
|
|
34
35
|
let action;
|
|
35
36
|
if (directive.action) {
|
|
@@ -42,7 +43,7 @@ class DirAddTags {
|
|
|
42
43
|
return;
|
|
43
44
|
}
|
|
44
45
|
this.go(action, (stop) => {
|
|
45
|
-
this.logger.
|
|
46
|
+
this.logger.info("[Add Tag] Action completed");
|
|
46
47
|
callback(stop);
|
|
47
48
|
})
|
|
48
49
|
}
|
|
@@ -84,7 +85,7 @@ class DirAddTags {
|
|
|
84
85
|
if(target === 'request'){
|
|
85
86
|
|
|
86
87
|
let newTags = filled_tags.split(',').filter(tag => tag !== '').map(el => el.trim())
|
|
87
|
-
this.logger.
|
|
88
|
+
this.logger.debug("[Add Tag] Adding following tags to conversation: ", newTags)
|
|
88
89
|
|
|
89
90
|
if(action.pushToList){
|
|
90
91
|
newTags.forEach(async (tag) => {
|
|
@@ -98,7 +99,7 @@ class DirAddTags {
|
|
|
98
99
|
|
|
99
100
|
winston.debug('(DirAddTags) UPDATE request with newTags', newTags)
|
|
100
101
|
let updatedRequest = await this.updateRequestWithTags(newTags)
|
|
101
|
-
this.logger.
|
|
102
|
+
this.logger.info("[Add Tag] Tags added to conversation")
|
|
102
103
|
if(!updatedRequest){
|
|
103
104
|
callback();
|
|
104
105
|
return;
|
|
@@ -109,7 +110,7 @@ class DirAddTags {
|
|
|
109
110
|
/** use case: LEAD */
|
|
110
111
|
if(target === 'lead'){
|
|
111
112
|
let newTags = filled_tags.split(',').filter(tag => tag !== '').map(el => el.trim())
|
|
112
|
-
this.logger.
|
|
113
|
+
this.logger.debug("[Add Tag] Adding following tags to lead: ", newTags)
|
|
113
114
|
|
|
114
115
|
let request = await this.tdClient.getRequestById(this.requestId);
|
|
115
116
|
winston.debug('(DirAddTags) request detail: ', request)
|
|
@@ -131,7 +132,7 @@ class DirAddTags {
|
|
|
131
132
|
|
|
132
133
|
winston.debug('(DirAddTags) UPDATE lead with newTags ', newTags)
|
|
133
134
|
let updatedLead = await this.updateLeadWithTags(request.lead._id, newTags)
|
|
134
|
-
this.logger.
|
|
135
|
+
this.logger.info("[Add Tag] Tags added to lead")
|
|
135
136
|
if(!updatedLead){
|
|
136
137
|
callback();
|
|
137
138
|
return;
|
|
@@ -33,6 +33,7 @@ class DirAiPrompt {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
execute(directive, callback) {
|
|
36
|
+
this.logger.info("[AI Prompt] Executing action");
|
|
36
37
|
winston.verbose("Execute AiPrompt directive");
|
|
37
38
|
let action;
|
|
38
39
|
if (directive.action) {
|
|
@@ -45,7 +46,7 @@ class DirAiPrompt {
|
|
|
45
46
|
return;
|
|
46
47
|
}
|
|
47
48
|
this.go(action, (stop) => {
|
|
48
|
-
this.logger.
|
|
49
|
+
this.logger.info("[AI Prompt] Action completed");
|
|
49
50
|
callback(stop);
|
|
50
51
|
})
|
|
51
52
|
}
|
|
@@ -91,7 +92,7 @@ class DirAiPrompt {
|
|
|
91
92
|
const filled_context = filler.fill(action.context, requestVariables);
|
|
92
93
|
|
|
93
94
|
if (action.history) {
|
|
94
|
-
this.logger.
|
|
95
|
+
this.logger.info("[AI Prompt] using chat transcript");
|
|
95
96
|
let transcript_string = await TiledeskChatbot.getParameterStatic(
|
|
96
97
|
this.context.tdcache,
|
|
97
98
|
this.context.requestId,
|
|
@@ -211,7 +212,7 @@ class DirAiPrompt {
|
|
|
211
212
|
|
|
212
213
|
winston.debug("DirAiPrompt resbody: ", resbody);
|
|
213
214
|
answer = resbody.answer;
|
|
214
|
-
this.logger.
|
|
215
|
+
this.logger.info("[AI Prompt] answer: ", answer);
|
|
215
216
|
|
|
216
217
|
await this.#assignAttributes(action, answer);
|
|
217
218
|
|
|
@@ -299,7 +300,7 @@ class DirAiPrompt {
|
|
|
299
300
|
}
|
|
300
301
|
if (result === true) {
|
|
301
302
|
if (trueIntentDirective) {
|
|
302
|
-
this.logger.
|
|
303
|
+
this.logger.info("[AI Prompt] executing true condition");
|
|
303
304
|
this.intentDir.execute(trueIntentDirective, () => {
|
|
304
305
|
if (callback) {
|
|
305
306
|
callback();
|
|
@@ -307,7 +308,7 @@ class DirAiPrompt {
|
|
|
307
308
|
})
|
|
308
309
|
}
|
|
309
310
|
else {
|
|
310
|
-
this.logger.
|
|
311
|
+
this.logger.info("[AI Prompt] no block connected to true condition");
|
|
311
312
|
winston.debug("DirAiPrompt No trueIntentDirective specified");
|
|
312
313
|
if (callback) {
|
|
313
314
|
callback();
|
|
@@ -316,7 +317,7 @@ class DirAiPrompt {
|
|
|
316
317
|
}
|
|
317
318
|
else {
|
|
318
319
|
if (falseIntentDirective) {
|
|
319
|
-
this.logger.
|
|
320
|
+
this.logger.info("[AI Prompt] executing false condition");
|
|
320
321
|
this.intentDir.execute(falseIntentDirective, () => {
|
|
321
322
|
if (callback) {
|
|
322
323
|
callback();
|
|
@@ -324,7 +325,7 @@ class DirAiPrompt {
|
|
|
324
325
|
});
|
|
325
326
|
}
|
|
326
327
|
else {
|
|
327
|
-
this.logger.
|
|
328
|
+
this.logger.info("[AI Prompt] no block connected to false condition");
|
|
328
329
|
winston.debug("DirAiPrompt No falseIntentDirective specified");
|
|
329
330
|
if (callback) {
|
|
330
331
|
callback();
|
|
@@ -31,6 +31,7 @@ class DirAskGPTV2 {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
execute(directive, callback) {
|
|
34
|
+
this.logger.info("[Ask Knowledge Base] Executing action");
|
|
34
35
|
winston.debug("DirAskGPTV2 directive: ", directive);
|
|
35
36
|
let action;
|
|
36
37
|
if (directive.action) {
|
|
@@ -43,7 +44,7 @@ class DirAskGPTV2 {
|
|
|
43
44
|
return;
|
|
44
45
|
}
|
|
45
46
|
this.go(action, (stop) => {
|
|
46
|
-
this.logger.
|
|
47
|
+
this.logger.info("[Ask Knowledge Base] Action completed");
|
|
47
48
|
callback(stop);
|
|
48
49
|
})
|
|
49
50
|
}
|
|
@@ -75,10 +76,8 @@ class DirAskGPTV2 {
|
|
|
75
76
|
let temperature;
|
|
76
77
|
let max_tokens;
|
|
77
78
|
let top_k;
|
|
78
|
-
let alpha;
|
|
79
79
|
let transcript;
|
|
80
80
|
let citations = false;
|
|
81
|
-
let chunks_only = false;
|
|
82
81
|
let engine;
|
|
83
82
|
//let default_context = "You are an helpful assistant for question-answering tasks.\nUse ONLY the following pieces of retrieved context to answer the question.\nIf you don't know the answer, just say that you don't know.\nIf none of the retrieved context answer the question, add this word to the end <NOANS>\n\n{context}";
|
|
84
83
|
|
|
@@ -125,18 +124,10 @@ class DirAskGPTV2 {
|
|
|
125
124
|
max_tokens = action.max_tokens;
|
|
126
125
|
}
|
|
127
126
|
|
|
128
|
-
if (action.alpha) {
|
|
129
|
-
alpha = action.alpha;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
127
|
if (action.citations) {
|
|
133
128
|
citations = action.citations;
|
|
134
129
|
}
|
|
135
130
|
|
|
136
|
-
if (action.chunks_only) {
|
|
137
|
-
chunks_only = action.chunks_only;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
131
|
let requestVariables = null;
|
|
141
132
|
requestVariables =
|
|
142
133
|
await TiledeskChatbot.allParametersStatic(
|
|
@@ -148,7 +139,7 @@ class DirAskGPTV2 {
|
|
|
148
139
|
const filled_context = filler.fill(action.context, requestVariables)
|
|
149
140
|
|
|
150
141
|
if (action.history) {
|
|
151
|
-
this.logger.
|
|
142
|
+
this.logger.info("[Ask Knowledge Base] use chat transcript")
|
|
152
143
|
let transcript_string = await TiledeskChatbot.getParameterStatic(
|
|
153
144
|
this.context.tdcache,
|
|
154
145
|
this.context.requestId,
|
|
@@ -170,7 +161,7 @@ class DirAskGPTV2 {
|
|
|
170
161
|
|
|
171
162
|
let key = await integrationService.getKeyFromIntegrations(this.projectId, 'openai', this.token);
|
|
172
163
|
if (!key) {
|
|
173
|
-
this.logger.
|
|
164
|
+
this.logger.debug("[Ask Knowledge Base] OpenAI key not found in Integration. Using shared OpenAI key");
|
|
174
165
|
winston.verbose("DirAskGPTV2 - Key not found in Integrations. Searching in kb settings...");
|
|
175
166
|
key = await this.getKeyFromKbSettings();
|
|
176
167
|
}
|
|
@@ -180,7 +171,7 @@ class DirAskGPTV2 {
|
|
|
180
171
|
key = process.env.GPTKEY;
|
|
181
172
|
publicKey = true;
|
|
182
173
|
} else {
|
|
183
|
-
this.logger.
|
|
174
|
+
this.logger.debug("[Ask Knowledge Base] use your own OpenAI key")
|
|
184
175
|
}
|
|
185
176
|
|
|
186
177
|
if (!key) {
|
|
@@ -195,7 +186,7 @@ class DirAskGPTV2 {
|
|
|
195
186
|
return;
|
|
196
187
|
}
|
|
197
188
|
|
|
198
|
-
if (publicKey === true
|
|
189
|
+
if (publicKey === true) {
|
|
199
190
|
let keep_going = await this.checkQuoteAvailability();
|
|
200
191
|
if (keep_going === false) {
|
|
201
192
|
this.logger.warn("[Ask Knowledge Base] Tokens quota exceeded. Skip the action")
|
|
@@ -209,18 +200,16 @@ class DirAskGPTV2 {
|
|
|
209
200
|
|
|
210
201
|
let ns;
|
|
211
202
|
|
|
212
|
-
console.log("namespace: ", namespace)
|
|
213
203
|
if (action.namespaceAsName) {
|
|
214
204
|
// Namespace could be an attribute
|
|
215
205
|
const filled_namespace = filler.fill(action.namespace, requestVariables)
|
|
216
|
-
this.logger.
|
|
206
|
+
this.logger.debug("[Ask Knowledge Base] Searching namespace by name ", filled_namespace);
|
|
217
207
|
ns = await this.getNamespace(filled_namespace, null);
|
|
218
208
|
namespace = ns?.id;
|
|
219
209
|
winston.verbose("DirAskGPTV2 - Retrieved namespace id from name " + namespace);
|
|
220
210
|
} else {
|
|
221
|
-
this.logger.
|
|
211
|
+
this.logger.debug("[Ask Knowledge Base] Searching namespace by id ", namespace);
|
|
222
212
|
ns = await this.getNamespace(null, namespace);
|
|
223
|
-
console.log("ns ?: ", ns)
|
|
224
213
|
}
|
|
225
214
|
|
|
226
215
|
if (!ns) {
|
|
@@ -271,16 +260,7 @@ class DirAskGPTV2 {
|
|
|
271
260
|
if (max_tokens) {
|
|
272
261
|
json.max_tokens = max_tokens;
|
|
273
262
|
}
|
|
274
|
-
|
|
275
|
-
if (engine.type === 'serverless') {
|
|
276
|
-
json.search_type = 'hybrid';
|
|
277
|
-
json.alpha = alpha;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
if (chunks_only && chunks_only === true) {
|
|
281
|
-
json.search_type = 'chunks';
|
|
282
|
-
}
|
|
283
|
-
|
|
263
|
+
|
|
284
264
|
if (!action.advancedPrompt) {
|
|
285
265
|
if (filled_context) {
|
|
286
266
|
json.system_context = filled_context + "\n" + contexts[model];
|
|
@@ -326,34 +306,22 @@ class DirAskGPTV2 {
|
|
|
326
306
|
}
|
|
327
307
|
else if (resbody.success === true) {
|
|
328
308
|
winston.debug("DirAskGPTV2 resbody: ", resbody);
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
return;
|
|
309
|
+
await this.#assignAttributes(action, resbody.answer, resbody.source, resbody.content_chunks);
|
|
310
|
+
if (publicKey === true) {
|
|
311
|
+
let tokens_usage = {
|
|
312
|
+
tokens: resbody.prompt_token_size,
|
|
313
|
+
model: json.model
|
|
335
314
|
}
|
|
336
|
-
|
|
337
|
-
|
|
315
|
+
this.updateQuote(tokens_usage);
|
|
316
|
+
}
|
|
338
317
|
|
|
339
|
-
|
|
340
|
-
await this.#
|
|
341
|
-
|
|
342
|
-
let tokens_usage = {
|
|
343
|
-
tokens: resbody.prompt_token_size,
|
|
344
|
-
model: json.model
|
|
345
|
-
}
|
|
346
|
-
this.updateQuote(tokens_usage);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
if (trueIntent) {
|
|
350
|
-
await this.#executeCondition(true, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
351
|
-
callback(true);
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
callback();
|
|
318
|
+
if (trueIntent) {
|
|
319
|
+
await this.#executeCondition(true, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
320
|
+
callback(true);
|
|
355
321
|
return;
|
|
356
322
|
}
|
|
323
|
+
callback();
|
|
324
|
+
return;
|
|
357
325
|
} else {
|
|
358
326
|
await this.#assignAttributes(action, answer, source);
|
|
359
327
|
if (falseIntent) {
|
|
@@ -25,6 +25,7 @@ class DirAssistant {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
execute(directive, callback) {
|
|
28
|
+
this.logger.info("[ChatGPT Assistant] Executing action");
|
|
28
29
|
winston.verbose("Execute Assistant directive");
|
|
29
30
|
let action;
|
|
30
31
|
if (directive.action) {
|
|
@@ -37,7 +38,7 @@ class DirAssistant {
|
|
|
37
38
|
return;
|
|
38
39
|
}
|
|
39
40
|
this.go(action, (stop) => {
|
|
40
|
-
this.logger.
|
|
41
|
+
this.logger.info("[ChatGPT Assistant] Action completed");
|
|
41
42
|
callback(stop);
|
|
42
43
|
});
|
|
43
44
|
}
|
|
@@ -26,6 +26,7 @@ class DirBrevo {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
execute(directive, callback) {
|
|
29
|
+
this.logger.info("[Brevo] Executing action");
|
|
29
30
|
winston.verbose("Execute DirBrevo directive");
|
|
30
31
|
let action;
|
|
31
32
|
if (directive.action) {
|
|
@@ -38,7 +39,7 @@ class DirBrevo {
|
|
|
38
39
|
return;
|
|
39
40
|
}
|
|
40
41
|
this.go(action, (stop) => {
|
|
41
|
-
this.logger.
|
|
42
|
+
this.logger.info("[Brevo] Action completed");
|
|
42
43
|
callback(stop);
|
|
43
44
|
})
|
|
44
45
|
}
|
|
@@ -22,6 +22,7 @@ class DirCaptureUserReply {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
execute(directive, callback) {
|
|
25
|
+
this.logger.info("[Capture User Reply] Executing action");
|
|
25
26
|
winston.verbose("Execute CaptureUserReply directive");
|
|
26
27
|
let action;
|
|
27
28
|
if (directive.action) {
|
|
@@ -47,7 +48,7 @@ class DirCaptureUserReply {
|
|
|
47
48
|
const actionId = action["_tdActionId"];;
|
|
48
49
|
await this.chatbot.lockIntent(this.requestId, intent_name);
|
|
49
50
|
await this.chatbot.lockAction(this.requestId, actionId);
|
|
50
|
-
this.logger.
|
|
51
|
+
this.logger.info("[Capture User Reply] Waiting for user reply...");
|
|
51
52
|
callback();
|
|
52
53
|
return;
|
|
53
54
|
} else {
|
|
@@ -62,7 +63,7 @@ class DirCaptureUserReply {
|
|
|
62
63
|
}
|
|
63
64
|
try {
|
|
64
65
|
const user_reply = this.message.text;
|
|
65
|
-
this.logger.
|
|
66
|
+
this.logger.info("[Capture User Reply] User replied with: ", user_reply);
|
|
66
67
|
if (this.context.tdcache) {
|
|
67
68
|
if (action.assignResultTo) {
|
|
68
69
|
winston.debug("(DirCaptureUserReply) assign assignResultTo: " + action.assignResultTo);
|
|
@@ -73,12 +74,12 @@ class DirCaptureUserReply {
|
|
|
73
74
|
if (callback) {
|
|
74
75
|
if (goToIntent) {
|
|
75
76
|
this.#executeGoTo(goToIntent, () => {
|
|
76
|
-
this.logger.
|
|
77
|
+
this.logger.info("[Capture User Reply] Action completed");
|
|
77
78
|
callback(); // continue the flow
|
|
78
79
|
});
|
|
79
80
|
}
|
|
80
81
|
else {
|
|
81
|
-
this.logger.
|
|
82
|
+
this.logger.info("[Capture User Reply] Action completed");
|
|
82
83
|
callback(); // continue the flow
|
|
83
84
|
}
|
|
84
85
|
|
|
@@ -15,8 +15,9 @@ class DirClearTranscript {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
execute(directive, callback) {
|
|
18
|
+
this.logger.info("[Clear Transcript] Executing action");
|
|
18
19
|
TiledeskChatbotUtil.clearConversationTranscript(this.context.chatbot, () => {
|
|
19
|
-
this.logger.
|
|
20
|
+
this.logger.info("[Clear Transcript] Action completed");
|
|
20
21
|
callback();
|
|
21
22
|
});
|
|
22
23
|
}
|
|
@@ -20,6 +20,7 @@ class DirClose {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
execute(directive, callback) {
|
|
23
|
+
this.logger.info("[Close] Executing action");
|
|
23
24
|
winston.verbose("Execute Close directive");
|
|
24
25
|
this.tdClient.closeRequest(this.requestId, async (err) => {
|
|
25
26
|
if (err) {
|
|
@@ -27,10 +28,10 @@ class DirClose {
|
|
|
27
28
|
winston.error("(DirClose) Error: ", err);
|
|
28
29
|
}
|
|
29
30
|
else {
|
|
30
|
-
this.logger.
|
|
31
|
+
this.logger.info("[Close] Request closed");
|
|
31
32
|
await this.chatbot.deleteParameter(TiledeskChatbotConst.USER_INPUT);
|
|
32
33
|
}
|
|
33
|
-
this.logger.
|
|
34
|
+
this.logger.info("[Close] Action completed");
|
|
34
35
|
callback();
|
|
35
36
|
});
|
|
36
37
|
}
|
|
@@ -17,6 +17,7 @@ class DirCode {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
execute(directive, callback) {
|
|
20
|
+
this.logger.info("[Code] Executing action");
|
|
20
21
|
winston.verbose("Execute Code directive");
|
|
21
22
|
let action;
|
|
22
23
|
if (directive.action) {
|
|
@@ -29,7 +30,7 @@ class DirCode {
|
|
|
29
30
|
return;
|
|
30
31
|
}
|
|
31
32
|
this.go(action, (stop) => {
|
|
32
|
-
this.logger.
|
|
33
|
+
this.logger.info("[Code] Action completed");
|
|
33
34
|
callback(stop);
|
|
34
35
|
});
|
|
35
36
|
|