@tiledesk/tiledesk-tybot-connector 2.0.10-rc2 → 2.0.10-rc20
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/Logger.js +6 -1
- package/logs/app.log +28600 -21124
- package/logs/app1.log +41129 -0
- package/logs/app2.log +16449 -45594
- package/logs/app6.log +44412 -0
- package/logs/app7.log +4726 -0
- package/package.json +2 -2
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +7 -0
- package/tiledeskChatbotPlugs/directives/DirAddKbContent.js +333 -0
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +13 -19
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +17 -17
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +19 -16
- package/tiledeskChatbotPlugs/directives/DirAssign.js +0 -6
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +1 -6
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +13 -2
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +11 -6
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +10 -0
- package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +5 -0
- package/tiledeskChatbotPlugs/directives/DirClose.js +8 -7
- package/tiledeskChatbotPlugs/directives/DirCode.js +9 -0
- package/tiledeskChatbotPlugs/directives/DirCondition.js +13 -0
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +7 -7
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +11 -1
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +1 -6
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +14 -0
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +14 -8
- package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +3 -7
- package/tiledeskChatbotPlugs/directives/DirFlowLog.js +22 -10
- package/tiledeskChatbotPlugs/directives/DirForm.js +4 -9
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +19 -6
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +12 -2
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +4 -8
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +12 -8
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +11 -0
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +4 -8
- package/tiledeskChatbotPlugs/directives/DirIntent.js +5 -6
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +14 -3
- package/tiledeskChatbotPlugs/directives/DirMake.js +6 -0
- package/tiledeskChatbotPlugs/directives/DirMessage.js +1 -6
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +5 -7
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +6 -7
- package/tiledeskChatbotPlugs/directives/DirQapla.js +7 -2
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +7 -7
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +1 -6
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +7 -7
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +7 -7
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +7 -7
- package/tiledeskChatbotPlugs/directives/DirReply.js +9 -11
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +8 -8
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +7 -7
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +7 -1
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +7 -0
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +2 -7
- package/tiledeskChatbotPlugs/directives/DirWait.js +6 -0
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +16 -13
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +6 -4
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +7 -0
- package/tiledeskChatbotPlugs/directives/Directives.js +1 -0
- package/utils/TiledeskChatbotUtil.js +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiledesk/tiledesk-tybot-connector",
|
|
3
|
-
"version": "2.0.10-
|
|
3
|
+
"version": "2.0.10-rc20",
|
|
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.1-
|
|
18
|
+
"@tiledesk/tiledesk-multi-worker": "^0.3.1-rc12",
|
|
19
19
|
"accept-language-parser": "^1.5.0",
|
|
20
20
|
"app-root-path": "^3.1.0",
|
|
21
21
|
"axios": "^1.7.7",
|
|
@@ -57,6 +57,7 @@ const { DirReplaceBotV3 } = require('./directives/DirReplaceBotV3');
|
|
|
57
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');
|
|
60
61
|
|
|
61
62
|
const winston = require('../utils/winston');
|
|
62
63
|
const { DirFlowLog } = require('./directives/DirFlowLog');
|
|
@@ -721,6 +722,12 @@ class DirectivesChatbotPlug {
|
|
|
721
722
|
this.process(next_dir);
|
|
722
723
|
})
|
|
723
724
|
}
|
|
725
|
+
else if (directive_name === Directives.ADD_KB_CONTENT) {
|
|
726
|
+
new DirAddKbContent(context).execute(directive, async () => {
|
|
727
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
728
|
+
this.process(next_dir);
|
|
729
|
+
});
|
|
730
|
+
}
|
|
724
731
|
else {
|
|
725
732
|
let next_dir = await this.nextDirective(this.directives);
|
|
726
733
|
this.process(next_dir);
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
const axios = require("axios").default;
|
|
2
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
3
|
+
const { Filler } = require('../Filler');
|
|
4
|
+
let https = require("https");
|
|
5
|
+
const { DirIntent } = require("./DirIntent");
|
|
6
|
+
const { TiledeskChatbotConst } = require("../../engine/TiledeskChatbotConst");
|
|
7
|
+
const { TiledeskChatbotUtil } = require("../../utils/TiledeskChatbotUtil");
|
|
8
|
+
const assert = require("assert");
|
|
9
|
+
require('dotenv').config();
|
|
10
|
+
const winston = require('../../utils/winston');
|
|
11
|
+
const httpUtils = require("../../utils/HttpUtils");
|
|
12
|
+
const integrationService = require("../../services/IntegrationService");
|
|
13
|
+
const { Logger } = require("../../Logger");
|
|
14
|
+
|
|
15
|
+
class DirAddKbContent {
|
|
16
|
+
|
|
17
|
+
constructor(context) {
|
|
18
|
+
if (!context) {
|
|
19
|
+
throw new Error('context object is mandatory');
|
|
20
|
+
}
|
|
21
|
+
this.context = context;
|
|
22
|
+
this.chatbot = context.chatbot;
|
|
23
|
+
this.tdcache = this.context.tdcache;
|
|
24
|
+
this.requestId = this.context.requestId;
|
|
25
|
+
this.projectId = this.context.projectId;
|
|
26
|
+
this.token = this.context.token;
|
|
27
|
+
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
28
|
+
this.log = context.log;
|
|
29
|
+
|
|
30
|
+
this.intentDir = new DirIntent(context);
|
|
31
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
execute(directive, callback) {
|
|
35
|
+
this.logger.info("Execute AskKnowledgeBase action")
|
|
36
|
+
winston.debug("DirAskGPTV2 directive: ", directive);
|
|
37
|
+
let action;
|
|
38
|
+
if (directive.action) {
|
|
39
|
+
action = directive.action;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.logger.error("Incorrect action for ", directive.name, directive)
|
|
43
|
+
winston.debug("DirAskGPTV2 Incorrect directive: ", directive);
|
|
44
|
+
callback();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
this.go(action, (stop) => {
|
|
48
|
+
this.logger.info("Acion AskKnowledgeBase completed");
|
|
49
|
+
callback(stop);
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async go(action, callback) {
|
|
54
|
+
winston.debug("[DirAddKbContent] action:", action);
|
|
55
|
+
if (!this.tdcache) {
|
|
56
|
+
winston.error("[DirAddKbContent] Error: tdcache is mandatory");
|
|
57
|
+
callback();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let publicKey = false;
|
|
62
|
+
let type = action.type;
|
|
63
|
+
let name = action.name;
|
|
64
|
+
let content = action.content;
|
|
65
|
+
let engine;
|
|
66
|
+
|
|
67
|
+
// default values
|
|
68
|
+
let namespace = this.context.projectId;
|
|
69
|
+
|
|
70
|
+
if (action.namespace) {
|
|
71
|
+
namespace = action.namespace;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let requestVariables = null;
|
|
75
|
+
requestVariables =
|
|
76
|
+
await TiledeskChatbot.allParametersStatic(
|
|
77
|
+
this.tdcache, this.requestId
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const filler = new Filler();
|
|
81
|
+
const filled_content = filler.fill(content, requestVariables);
|
|
82
|
+
const filled_name = filler.fill(name, requestVariables);
|
|
83
|
+
|
|
84
|
+
const kb_endpoint = process.env.API_ENDPOINT;
|
|
85
|
+
winston.verbose("[DirAddKbContent] KbEndpoint URL: " + kb_endpoint);
|
|
86
|
+
|
|
87
|
+
let key = await integrationService.getKeyFromIntegrations(this.projectId, 'openai', this.token);
|
|
88
|
+
if (!key) {
|
|
89
|
+
this.logger.debug("[DirAddKbContent] OpenAI key not found in Integration. Using shared OpenAI key");
|
|
90
|
+
winston.verbose("[DirAddKbContent] - Key not found in Integrations. Searching in kb settings...");
|
|
91
|
+
key = await this.getKeyFromKbSettings();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!key) {
|
|
95
|
+
winston.verbose("[DirAddKbContent] - Retrieve public gptkey")
|
|
96
|
+
key = process.env.GPTKEY;
|
|
97
|
+
publicKey = true;
|
|
98
|
+
} else {
|
|
99
|
+
this.logger.debug("[DirAddKbContent] use your own OpenAI key")
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!key) {
|
|
103
|
+
winston.info("[DirAddKbContent] Error: gptkey is mandatory");
|
|
104
|
+
await this.chatbot.addParameter("flowError", "[DirAddKbContent] Error: gptkey is mandatory");
|
|
105
|
+
callback();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (publicKey === true) {
|
|
110
|
+
let keep_going = await this.checkQuoteAvailability();
|
|
111
|
+
if (keep_going === false) {
|
|
112
|
+
this.logger.warn("[DirAddKbContent] Tokens quota exceeded. Skip the action")
|
|
113
|
+
winston.verbose("[DirAddKbContent] - Quota exceeded for tokens. Skip the action")
|
|
114
|
+
await this.chatbot.addParameter("flowError", "[DirAddKbContent] Error: tokens quota exceeded");
|
|
115
|
+
callback(true);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
let ns;
|
|
121
|
+
|
|
122
|
+
if (action.namespaceAsName) {
|
|
123
|
+
// Namespace could be an attribute
|
|
124
|
+
const filled_namespace = filler.fill(action.namespace, requestVariables)
|
|
125
|
+
this.logger.debug("[DirAddKbContent] Searching namespace by name ", filled_namespace);
|
|
126
|
+
ns = await this.getNamespace(filled_namespace, null);
|
|
127
|
+
namespace = ns?.id;
|
|
128
|
+
winston.verbose("[DirAddKbContent] - Retrieved namespace id from name " + namespace);
|
|
129
|
+
} else {
|
|
130
|
+
this.logger.debug("[DirAddKbContent] Searching namespace by id ", namespace);
|
|
131
|
+
ns = await this.getNamespace(null, namespace);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!ns) {
|
|
135
|
+
this.logger.error("[DirAddKbContent] Namespace not found");
|
|
136
|
+
await this.chatbot.addParameter("flowError", "[DirAddKbContent] Error: namespace not found");
|
|
137
|
+
callback();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (ns.engine) {
|
|
142
|
+
engine = ns.engine;
|
|
143
|
+
} else {
|
|
144
|
+
engine = await this.setDefaultEngine()
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (!namespace) {
|
|
148
|
+
this.logger.error("[DirAddKbContent] Namespace is undefined")
|
|
149
|
+
winston.verbose("[DirAddKbContent] - Error: namespace is undefined")
|
|
150
|
+
await this.chatbot.addParameter("flowError", "[DirAddKbContent] Error: namespace is undefined");
|
|
151
|
+
callback(true);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let json = {
|
|
156
|
+
content: filled_content,
|
|
157
|
+
namespace: namespace,
|
|
158
|
+
type: type,
|
|
159
|
+
name: filled_name,
|
|
160
|
+
source: filled_name
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
winston.debug("[DirAddKbContent] json:", json);
|
|
164
|
+
|
|
165
|
+
const HTTPREQUEST = {
|
|
166
|
+
url: kb_endpoint + "/" + this.projectId + "/kb",
|
|
167
|
+
headers: {
|
|
168
|
+
'Content-Type': 'application/json',
|
|
169
|
+
'Authorization': 'JWT ' + this.context.token
|
|
170
|
+
},
|
|
171
|
+
json: json,
|
|
172
|
+
method: "POST"
|
|
173
|
+
}
|
|
174
|
+
winston.debug("[DirAddKbContent] HttpRequest: ", HTTPREQUEST);
|
|
175
|
+
|
|
176
|
+
httpUtils.request(
|
|
177
|
+
HTTPREQUEST, async (err, resbody) => {
|
|
178
|
+
|
|
179
|
+
if (err) {
|
|
180
|
+
this.logger.error("[DirAddKbContent] error: " + JSON.stringify(err?.response));
|
|
181
|
+
winston.error("[DirAddKbContent] error: ", err?.response);
|
|
182
|
+
if (callback) {
|
|
183
|
+
callback();
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
else if (resbody.success === true) {
|
|
188
|
+
winston.debug("[DirAddKbContent] resbody: ", resbody);
|
|
189
|
+
callback();
|
|
190
|
+
return;
|
|
191
|
+
} else {
|
|
192
|
+
callback();
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async getKeyFromKbSettings() {
|
|
200
|
+
return new Promise((resolve) => {
|
|
201
|
+
|
|
202
|
+
const KB_HTTPREQUEST = {
|
|
203
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
|
|
204
|
+
headers: {
|
|
205
|
+
'Content-Type': 'application/json',
|
|
206
|
+
'Authorization': 'JWT ' + this.context.token
|
|
207
|
+
},
|
|
208
|
+
method: "GET"
|
|
209
|
+
}
|
|
210
|
+
winston.debug("DirAskGPTV2 KB HttpRequest", KB_HTTPREQUEST);
|
|
211
|
+
|
|
212
|
+
httpUtils.request(
|
|
213
|
+
KB_HTTPREQUEST, async (err, resbody) => {
|
|
214
|
+
if (err) {
|
|
215
|
+
winston.error("DirAskGPTV2 Get kb settings error ", err?.response?.data);
|
|
216
|
+
resolve(null);
|
|
217
|
+
} else {
|
|
218
|
+
if (!resbody.gptkey) {
|
|
219
|
+
resolve(null);
|
|
220
|
+
} else {
|
|
221
|
+
resolve(resbody.gptkey);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
)
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async checkQuoteAvailability() {
|
|
230
|
+
return new Promise((resolve) => {
|
|
231
|
+
|
|
232
|
+
const HTTPREQUEST = {
|
|
233
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/quotes/tokens",
|
|
234
|
+
headers: {
|
|
235
|
+
'Content-Type': 'application/json',
|
|
236
|
+
'Authorization': 'JWT ' + this.context.token
|
|
237
|
+
},
|
|
238
|
+
method: "GET"
|
|
239
|
+
}
|
|
240
|
+
winston.debug("DirAskGPTV2 check quote availability HttpRequest", HTTPREQUEST);
|
|
241
|
+
|
|
242
|
+
httpUtils.request(
|
|
243
|
+
HTTPREQUEST, async (err, resbody) => {
|
|
244
|
+
if (err) {
|
|
245
|
+
winston.error("DirAskGPTV2 Check quote availability err: ", err);
|
|
246
|
+
resolve(true)
|
|
247
|
+
} else {
|
|
248
|
+
if (resbody.isAvailable === true) {
|
|
249
|
+
resolve(true)
|
|
250
|
+
} else {
|
|
251
|
+
resolve(false)
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
)
|
|
256
|
+
})
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async updateQuote(tokens_usage) {
|
|
260
|
+
return new Promise((resolve, reject) => {
|
|
261
|
+
|
|
262
|
+
const HTTPREQUEST = {
|
|
263
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/quotes/incr/tokens",
|
|
264
|
+
headers: {
|
|
265
|
+
'Content-Type': 'application/json',
|
|
266
|
+
'Authorization': 'JWT ' + this.context.token
|
|
267
|
+
},
|
|
268
|
+
json: tokens_usage,
|
|
269
|
+
method: "POST"
|
|
270
|
+
}
|
|
271
|
+
winston.debug("DirAskGPTV2 update quote HttpRequest ", HTTPREQUEST);
|
|
272
|
+
|
|
273
|
+
httpUtils.request(
|
|
274
|
+
HTTPREQUEST, async (err, resbody) => {
|
|
275
|
+
if (err) {
|
|
276
|
+
winston.error("DirAskGPTV2 Increment tokens quote err: ", err);
|
|
277
|
+
reject(false)
|
|
278
|
+
} else {
|
|
279
|
+
resolve(true);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
)
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
async getNamespace(name, id) {
|
|
287
|
+
return new Promise((resolve) => {
|
|
288
|
+
const HTTPREQUEST = {
|
|
289
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/kb/namespace/all",
|
|
290
|
+
headers: {
|
|
291
|
+
'Content-Type': 'application/json',
|
|
292
|
+
'Authorization': 'JWT ' + this.context.token
|
|
293
|
+
},
|
|
294
|
+
method: "GET"
|
|
295
|
+
}
|
|
296
|
+
winston.debug("DirAskGPTV2 get all namespaces HttpRequest", HTTPREQUEST);
|
|
297
|
+
httpUtils.request(
|
|
298
|
+
HTTPREQUEST, async (err, namespaces) => {
|
|
299
|
+
if (err) {
|
|
300
|
+
winston.error("DirAskGPTV2 get all namespaces err: ", err);
|
|
301
|
+
resolve(null)
|
|
302
|
+
} else {
|
|
303
|
+
winston.debug("DirAskGPTV2 get all namespaces resbody: ", namespaces);
|
|
304
|
+
if (name) {
|
|
305
|
+
let namespace = namespaces.find(n => n.name === name);
|
|
306
|
+
resolve(namespace);
|
|
307
|
+
} else {
|
|
308
|
+
let namespace = namespaces.find(n => n.id === id);
|
|
309
|
+
resolve(namespace);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
)
|
|
315
|
+
})
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
async setDefaultEngine() {
|
|
319
|
+
return new Promise((resolve) => {
|
|
320
|
+
let engine = {
|
|
321
|
+
name: "pinecone",
|
|
322
|
+
type: process.env.PINECONE_TYPE,
|
|
323
|
+
apikey: "",
|
|
324
|
+
vector_size: 1536,
|
|
325
|
+
index_name: process.env.PINECONE_INDEX
|
|
326
|
+
}
|
|
327
|
+
resolve(engine);
|
|
328
|
+
})
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
module.exports = { DirAddKbContent }
|
|
@@ -24,20 +24,14 @@ class DirAddTags {
|
|
|
24
24
|
this.tdcache = this.context.tdcache;
|
|
25
25
|
this.requestId = this.context.requestId;
|
|
26
26
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
27
|
-
|
|
28
|
-
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest
|
|
29
|
-
|
|
30
|
-
this.tdClient = new TiledeskClient({
|
|
31
|
-
projectId: this.context.projectId,
|
|
32
|
-
token: this.context.token,
|
|
33
|
-
APIURL: this.API_ENDPOINT,
|
|
34
|
-
APIKEY: "___"
|
|
35
|
-
});
|
|
27
|
+
|
|
28
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
|
|
29
|
+
this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___" });
|
|
36
30
|
}
|
|
37
31
|
|
|
38
32
|
execute(directive, callback) {
|
|
33
|
+
this.logger.info("[Add Tag] Executing action")
|
|
39
34
|
winston.verbose("Execute AddTags action");
|
|
40
|
-
this.logger.error("Execute AddTags directive")
|
|
41
35
|
let action;
|
|
42
36
|
if (directive.action) {
|
|
43
37
|
action = directive.action;
|
|
@@ -49,7 +43,7 @@ class DirAddTags {
|
|
|
49
43
|
return;
|
|
50
44
|
}
|
|
51
45
|
this.go(action, (stop) => {
|
|
52
|
-
this.logger.info("
|
|
46
|
+
this.logger.info("[Add Tag] Action completed");
|
|
53
47
|
callback(stop);
|
|
54
48
|
})
|
|
55
49
|
}
|
|
@@ -70,7 +64,7 @@ class DirAddTags {
|
|
|
70
64
|
pushToList = action.pushToList
|
|
71
65
|
|
|
72
66
|
if (!action.tags || action.tags === '') {
|
|
73
|
-
this.logger.error("Add
|
|
67
|
+
this.logger.error("[Add Tag] tags attribute is mandatory");
|
|
74
68
|
winston.error("(DirAddTags) Error: tags attribute is mandatory")
|
|
75
69
|
await this.chatbot.addParameter("flowError", "Add tags Error: tags attribute is mandatory");
|
|
76
70
|
callback();
|
|
@@ -91,7 +85,7 @@ class DirAddTags {
|
|
|
91
85
|
if(target === 'request'){
|
|
92
86
|
|
|
93
87
|
let newTags = filled_tags.split(',').filter(tag => tag !== '').map(el => el.trim())
|
|
94
|
-
this.logger.debug("Adding following tags to conversation: ", newTags)
|
|
88
|
+
this.logger.debug("[Add Tag] Adding following tags to conversation: ", newTags)
|
|
95
89
|
|
|
96
90
|
if(action.pushToList){
|
|
97
91
|
newTags.forEach(async (tag) => {
|
|
@@ -105,7 +99,7 @@ class DirAddTags {
|
|
|
105
99
|
|
|
106
100
|
winston.debug('(DirAddTags) UPDATE request with newTags', newTags)
|
|
107
101
|
let updatedRequest = await this.updateRequestWithTags(newTags)
|
|
108
|
-
this.logger.info("Tags added to conversation")
|
|
102
|
+
this.logger.info("[Add Tag] Tags added to conversation")
|
|
109
103
|
if(!updatedRequest){
|
|
110
104
|
callback();
|
|
111
105
|
return;
|
|
@@ -116,7 +110,7 @@ class DirAddTags {
|
|
|
116
110
|
/** use case: LEAD */
|
|
117
111
|
if(target === 'lead'){
|
|
118
112
|
let newTags = filled_tags.split(',').filter(tag => tag !== '').map(el => el.trim())
|
|
119
|
-
this.logger.debug("Adding following tags to lead: ", newTags)
|
|
113
|
+
this.logger.debug("[Add Tag] Adding following tags to lead: ", newTags)
|
|
120
114
|
|
|
121
115
|
let request = await this.tdClient.getRequestById(this.requestId);
|
|
122
116
|
winston.debug('(DirAddTags) request detail: ', request)
|
|
@@ -138,7 +132,7 @@ class DirAddTags {
|
|
|
138
132
|
|
|
139
133
|
winston.debug('(DirAddTags) UPDATE lead with newTags ', newTags)
|
|
140
134
|
let updatedLead = await this.updateLeadWithTags(request.lead._id, newTags)
|
|
141
|
-
this.logger.info("Tags added to lead")
|
|
135
|
+
this.logger.info("[Add Tag] Tags added to lead")
|
|
142
136
|
if(!updatedLead){
|
|
143
137
|
callback();
|
|
144
138
|
return;
|
|
@@ -183,7 +177,7 @@ class DirAddTags {
|
|
|
183
177
|
httpUtils.request(
|
|
184
178
|
HTTPREQUEST, async (err, resbody) => {
|
|
185
179
|
if (err) {
|
|
186
|
-
this.logger.error("Add tags to list error ", err?.response?.data)
|
|
180
|
+
this.logger.error("[Add Tag] Add tags to list error ", err?.response?.data)
|
|
187
181
|
winston.error("(httprequest) DirAddTags add tags to list err: ", err);
|
|
188
182
|
resolve(true)
|
|
189
183
|
} else {
|
|
@@ -218,7 +212,7 @@ class DirAddTags {
|
|
|
218
212
|
httpUtils.request(
|
|
219
213
|
HTTPREQUEST, async (err, resbody) => {
|
|
220
214
|
if (err) {
|
|
221
|
-
this.logger.error("Add tag to conversation error ", err?.response?.data);
|
|
215
|
+
this.logger.error("[Add Tag] Add tag to conversation error ", err?.response?.data);
|
|
222
216
|
winston.error("(httprequest) DirAddTags patch request with new tags err: ", err);
|
|
223
217
|
resolve(true)
|
|
224
218
|
} else {
|
|
@@ -248,7 +242,7 @@ class DirAddTags {
|
|
|
248
242
|
httpUtils.request(
|
|
249
243
|
HTTPREQUEST, async (err, resbody) => {
|
|
250
244
|
if (err) {
|
|
251
|
-
this.logger.error("Add tag to lead error ", err?.response?.data);
|
|
245
|
+
this.logger.error("[Add Tag] Add tag to lead error ", err?.response?.data);
|
|
252
246
|
winston.error("(httprequest) DirAddTags put lead with new tags err: ", err);
|
|
253
247
|
resolve(true)
|
|
254
248
|
} else {
|
|
@@ -26,27 +26,27 @@ class DirAiPrompt {
|
|
|
26
26
|
this.requestId = this.context.requestId;
|
|
27
27
|
this.projectId = this.context.projectId;
|
|
28
28
|
this.token = this.context.token;
|
|
29
|
-
this.intentDir = new DirIntent(context);
|
|
30
29
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
31
|
-
|
|
32
|
-
this.
|
|
30
|
+
|
|
31
|
+
this.intentDir = new DirIntent(context);
|
|
32
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
|
|
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
|
-
this.logger.error("AiPrompt: executing action");
|
|
38
38
|
let action;
|
|
39
39
|
if (directive.action) {
|
|
40
40
|
action = directive.action;
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
|
-
this.logger.error("
|
|
43
|
+
this.logger.error("Incorrect action for ", directive.name, directive)
|
|
44
44
|
winston.debug("DirAiPrompt Incorrect directive: ", directive);
|
|
45
45
|
callback();
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
48
|
this.go(action, (stop) => {
|
|
49
|
-
this.logger.info("
|
|
49
|
+
this.logger.info("[AI Prompt] Action completed");
|
|
50
50
|
callback(stop);
|
|
51
51
|
})
|
|
52
52
|
}
|
|
@@ -70,7 +70,7 @@ class DirAiPrompt {
|
|
|
70
70
|
winston.debug("DirAskGPTV2 falseIntent", falseIntent)
|
|
71
71
|
|
|
72
72
|
await this.checkMandatoryParameters(action).catch( async (missing_param) => {
|
|
73
|
-
this.logger.error(`
|
|
73
|
+
this.logger.error(`[AI Prompt] missing attribute '${missing_param}'`);
|
|
74
74
|
await this.chatbot.addParameter("flowError", "AiPrompt Error: '" + missing_param + "' attribute is undefined");
|
|
75
75
|
if (falseIntent) {
|
|
76
76
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -92,7 +92,7 @@ class DirAiPrompt {
|
|
|
92
92
|
const filled_context = filler.fill(action.context, requestVariables);
|
|
93
93
|
|
|
94
94
|
if (action.history) {
|
|
95
|
-
this.logger.info("
|
|
95
|
+
this.logger.info("[AI Prompt] using chat transcript");
|
|
96
96
|
let transcript_string = await TiledeskChatbot.getParameterStatic(
|
|
97
97
|
this.context.tdcache,
|
|
98
98
|
this.context.requestId,
|
|
@@ -103,7 +103,7 @@ class DirAiPrompt {
|
|
|
103
103
|
transcript = await TiledeskChatbotUtil.transcriptJSON(transcript_string);
|
|
104
104
|
winston.debug("DirAiPrompt transcript: ", transcript)
|
|
105
105
|
} else {
|
|
106
|
-
this.logger.warn("
|
|
106
|
+
this.logger.warn("[AI Prompt] no chat transcript found, skipping history translation");
|
|
107
107
|
winston.verbose("DirAiPrompt transcript_string is undefined. Skip JSON translation for chat history")
|
|
108
108
|
}
|
|
109
109
|
}
|
|
@@ -120,7 +120,7 @@ class DirAiPrompt {
|
|
|
120
120
|
|
|
121
121
|
if (action.llm === 'ollama') {
|
|
122
122
|
ollama_integration = await integrationService.getIntegration(this.projectId, action.llm, this.token).catch( async (err) => {
|
|
123
|
-
this.logger.error("
|
|
123
|
+
this.logger.error("[AI Prompt] Error getting ollama integration.")
|
|
124
124
|
winston.error("DirAiPrompt Error getting ollama integration: ", err);
|
|
125
125
|
await this.chatbot.addParameter("flowError", "Ollama integration not found");
|
|
126
126
|
if (falseIntent) {
|
|
@@ -136,7 +136,7 @@ class DirAiPrompt {
|
|
|
136
136
|
key = await integrationService.getKeyFromIntegrations(this.projectId, action.llm, this.token);
|
|
137
137
|
|
|
138
138
|
if (!key) {
|
|
139
|
-
this.logger.error("
|
|
139
|
+
this.logger.error("[AI Prompt] llm key not found in integrations");
|
|
140
140
|
winston.error("Error: DirAiPrompt llm key not found in integrations");
|
|
141
141
|
await this.chatbot.addParameter("flowError", "AiPrompt Error: missing key for llm " + action.llm);
|
|
142
142
|
if (falseIntent) {
|
|
@@ -199,7 +199,7 @@ class DirAiPrompt {
|
|
|
199
199
|
} else {
|
|
200
200
|
error = JSON.stringify(err.response.data);
|
|
201
201
|
}
|
|
202
|
-
this.logger.error("
|
|
202
|
+
this.logger.error("[AI Prompt] error executing action: ", error);
|
|
203
203
|
if (falseIntent) {
|
|
204
204
|
await this.chatbot.addParameter("flowError", "AiPrompt Error: " + error);
|
|
205
205
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -212,7 +212,7 @@ class DirAiPrompt {
|
|
|
212
212
|
|
|
213
213
|
winston.debug("DirAiPrompt resbody: ", resbody);
|
|
214
214
|
answer = resbody.answer;
|
|
215
|
-
this.logger.info("
|
|
215
|
+
this.logger.info("[AI Prompt] answer: ", answer);
|
|
216
216
|
|
|
217
217
|
await this.#assignAttributes(action, answer);
|
|
218
218
|
|
|
@@ -300,7 +300,7 @@ class DirAiPrompt {
|
|
|
300
300
|
}
|
|
301
301
|
if (result === true) {
|
|
302
302
|
if (trueIntentDirective) {
|
|
303
|
-
this.logger.info("
|
|
303
|
+
this.logger.info("[AI Prompt] executing true condition");
|
|
304
304
|
this.intentDir.execute(trueIntentDirective, () => {
|
|
305
305
|
if (callback) {
|
|
306
306
|
callback();
|
|
@@ -308,7 +308,7 @@ class DirAiPrompt {
|
|
|
308
308
|
})
|
|
309
309
|
}
|
|
310
310
|
else {
|
|
311
|
-
this.logger.info("
|
|
311
|
+
this.logger.info("[AI Prompt] no block connected to true condition");
|
|
312
312
|
winston.debug("DirAiPrompt No trueIntentDirective specified");
|
|
313
313
|
if (callback) {
|
|
314
314
|
callback();
|
|
@@ -317,7 +317,7 @@ class DirAiPrompt {
|
|
|
317
317
|
}
|
|
318
318
|
else {
|
|
319
319
|
if (falseIntentDirective) {
|
|
320
|
-
this.logger.info("
|
|
320
|
+
this.logger.info("[AI Prompt] executing false condition");
|
|
321
321
|
this.intentDir.execute(falseIntentDirective, () => {
|
|
322
322
|
if (callback) {
|
|
323
323
|
callback();
|
|
@@ -325,7 +325,7 @@ class DirAiPrompt {
|
|
|
325
325
|
});
|
|
326
326
|
}
|
|
327
327
|
else {
|
|
328
|
-
this.logger.info("
|
|
328
|
+
this.logger.info("[AI Prompt] no block connected to false condition");
|
|
329
329
|
winston.debug("DirAiPrompt No falseIntentDirective specified");
|
|
330
330
|
if (callback) {
|
|
331
331
|
callback();
|
|
@@ -19,8 +19,9 @@ class DirAskGPT {
|
|
|
19
19
|
this.requestId = this.context.requestId;
|
|
20
20
|
this.projectId = this.context.projectId;
|
|
21
21
|
this.token = this.context.token;
|
|
22
|
-
this.intentDir = new DirIntent(context);
|
|
23
22
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
23
|
+
|
|
24
|
+
this.intentDir = new DirIntent(context);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
execute(directive, callback) {
|