@tiledesk/tiledesk-tybot-connector 2.0.10-rc8 → 2.0.10
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 +2 -27
- package/ExtApi.js +8 -1
- package/ExtUtil.js +6 -5
- package/Logger.js +17 -26
- package/TdCache copy.js +242 -0
- package/engine/IntentForm.js +1 -0
- package/engine/IntentsMachineFactory.js +4 -4
- package/engine/MongodbBotsDataSource.js +1 -0
- package/engine/MongodbIntentsMachine.js +1 -0
- package/engine/TiledeskChatbot.js +16 -11
- package/engine/TiledeskIntentsMachine.js +2 -1
- package/engine/mock/MockBotsDataSource.js +2 -1
- package/index.js +25 -22
- package/logs/app.log +43056 -4268
- package/logs/app1.log +41129 -0
- package/logs/app2.log +14567 -45594
- package/logs/app6.log +29039 -0
- package/logs/app7.log +4726 -0
- package/package.json +2 -3
- package/services/AIService.js +1 -1
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +18 -38
- package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +2 -1
- package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +3 -1
- package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +3 -1
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +9 -7
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfNotOpenHours.js +10 -3
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfOpenHours.js +9 -2
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +4 -16
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +0 -16
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +4 -17
- package/tiledeskChatbotPlugs/directives/DirAssign.js +8 -5
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +6 -4
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirClose.js +2 -0
- package/tiledeskChatbotPlugs/directives/DirCode.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirCondition.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +5 -2
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirForm.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +55 -36
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +4 -1
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +4 -1
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +2 -0
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +12 -8
- package/tiledeskChatbotPlugs/directives/DirIntent.js +5 -6
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirMake.js +16 -1
- package/tiledeskChatbotPlugs/directives/DirMessage.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +4 -1
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +3 -0
- package/tiledeskChatbotPlugs/directives/DirQapla.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirReply.js +18 -7
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +13 -8
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +4 -1
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirWait.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +19 -19
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +417 -0
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +40 -6
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +1 -0
- package/tiledeskChatbotPlugs/directives/Directives.js +0 -3
- package/utils/TiledeskChatbotUtil.js +57 -19
- package/tiledeskChatbotPlugs/directives/DirAddKbContent.js +0 -331
- package/tiledeskChatbotPlugs/directives/DirFlowLog.js +0 -88
|
@@ -10,7 +10,6 @@ require('dotenv').config();
|
|
|
10
10
|
const winston = require('../../utils/winston');
|
|
11
11
|
const httpUtils = require("../../utils/HttpUtils");
|
|
12
12
|
const integrationService = require("../../services/IntegrationService");
|
|
13
|
-
const { Logger } = require("../../Logger");
|
|
14
13
|
|
|
15
14
|
class DirAskGPTV2 {
|
|
16
15
|
|
|
@@ -27,24 +26,20 @@ class DirAskGPTV2 {
|
|
|
27
26
|
this.intentDir = new DirIntent(context);
|
|
28
27
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
29
28
|
this.log = context.log;
|
|
30
|
-
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest.draft });
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
execute(directive, callback) {
|
|
34
|
-
this.logger.info("Execute AskKnowledgeBase action")
|
|
35
32
|
winston.debug("DirAskGPTV2 directive: ", directive);
|
|
36
33
|
let action;
|
|
37
34
|
if (directive.action) {
|
|
38
35
|
action = directive.action;
|
|
39
36
|
}
|
|
40
37
|
else {
|
|
41
|
-
this.logger.error("Incorrect action for ", directive.name, directive)
|
|
42
38
|
winston.debug("DirAskGPTV2 Incorrect directive: ", directive);
|
|
43
39
|
callback();
|
|
44
40
|
return;
|
|
45
41
|
}
|
|
46
42
|
this.go(action, (stop) => {
|
|
47
|
-
this.logger.info("Acion AskKnowledgeBase completed");
|
|
48
43
|
callback(stop);
|
|
49
44
|
})
|
|
50
45
|
}
|
|
@@ -86,13 +81,15 @@ class DirAskGPTV2 {
|
|
|
86
81
|
"gpt-4": "You are an helpful assistant for question-answering tasks.\nUse ONLY the pieces of retrieved context delimited by #### to answer the question.\nIf you don't know the answer, just say that you don't know.\nIf and only if none of the retrieved context is useful for your task, add this word to the end <NOANS>\n\n####{context}####",
|
|
87
82
|
"gpt-4-turbo-preview": "You are an helpful assistant for question-answering tasks.\nUse ONLY the pieces of retrieved context delimited by #### to answer the question.\nIf you don't know the answer, just say that you don't know.\nIf and only if none of the retrieved context is useful for your task, add this word to the end <NOANS>\n\n####{context}####",
|
|
88
83
|
"gpt-4o": "You are an helpful assistant for question-answering tasks. Follow these steps carefully:\n1. Answer in the same language of the user question, regardless of the retrieved context language\n2. Use ONLY the pieces of the retrieved context to answer the question.\n3. If the retrieved context does not contain sufficient information to generate an accurate and informative answer, return <NOANS>\n\n==Retrieved context start==\n{context}\n==Retrieved context end==",
|
|
89
|
-
"gpt-4o-mini": "You are an helpful assistant for question-answering tasks. Follow these steps carefully:\n1. Answer in the same language of the user question, regardless of the retrieved context language\n2. Use ONLY the pieces of the retrieved context to answer the question.\n3. If the retrieved context does not contain sufficient information to generate an accurate and informative answer, return <NOANS>\n\n==Retrieved context start==\n{context}\n==Retrieved context end=="
|
|
84
|
+
"gpt-4o-mini": "You are an helpful assistant for question-answering tasks. Follow these steps carefully:\n1. Answer in the same language of the user question, regardless of the retrieved context language\n2. Use ONLY the pieces of the retrieved context to answer the question.\n3. If the retrieved context does not contain sufficient information to generate an accurate and informative answer, return <NOANS>\n\n==Retrieved context start==\n{context}\n==Retrieved context end==",
|
|
85
|
+
"gpt-4.1": "You are an helpful assistant for question-answering tasks. Follow these steps carefully:\n1. Answer in the same language of the user question, regardless of the retrieved context language\n2. Use ONLY the pieces of the retrieved context to answer the question.\n3. If the retrieved context does not contain sufficient information to generate an accurate and informative answer, return <NOANS>\n\n==Retrieved context start==\n{context}\n==Retrieved context end==",
|
|
86
|
+
"gpt-4.1-mini": "You are an helpful assistant for question-answering tasks. Follow these steps carefully:\n1. Answer in the same language of the user question, regardless of the retrieved context language\n2. Use ONLY the pieces of the retrieved context to answer the question.\n3. If the retrieved context does not contain sufficient information to generate an accurate and informative answer, return <NOANS>\n\n==Retrieved context start==\n{context}\n==Retrieved context end==",
|
|
87
|
+
"gpt-4.1-nano": "You are an helpful assistant for question-answering tasks. Follow these steps carefully:\n1. Answer in the same language of the user question, regardless of the retrieved context language\n2. Use ONLY the pieces of the retrieved context to answer the question.\n3. If the retrieved context does not contain sufficient information to generate an accurate and informative answer, return <NOANS>\n\n==Retrieved context start==\n{context}\n==Retrieved context end=="
|
|
90
88
|
}
|
|
91
89
|
|
|
92
90
|
let source = null;
|
|
93
91
|
|
|
94
92
|
if (!action.question || action.question === '') {
|
|
95
|
-
this.logger.error("AskKnowledgeBase question attribute is mandatory");
|
|
96
93
|
winston.error("DirAskGPTV2 Error: question attribute is mandatory. Executing condition false...");
|
|
97
94
|
await this.#assignAttributes(action, answer, source);
|
|
98
95
|
if (falseIntent) {
|
|
@@ -136,7 +133,6 @@ class DirAskGPTV2 {
|
|
|
136
133
|
const filled_context = filler.fill(action.context, requestVariables)
|
|
137
134
|
|
|
138
135
|
if (action.history) {
|
|
139
|
-
this.logger.info("AskKnowledgeBase: use chat transcript")
|
|
140
136
|
let transcript_string = await TiledeskChatbot.getParameterStatic(
|
|
141
137
|
this.context.tdcache,
|
|
142
138
|
this.context.requestId,
|
|
@@ -148,7 +144,6 @@ class DirAskGPTV2 {
|
|
|
148
144
|
transcript = await TiledeskChatbotUtil.transcriptJSON(transcript_string);
|
|
149
145
|
winston.debug("DirAskGPTV2 transcript ", transcript)
|
|
150
146
|
} else {
|
|
151
|
-
this.logger.warn("AskKnowledgeBase: chat transcript is undefined. Skip JSON translation for chat history.");
|
|
152
147
|
winston.verbose("DirAskGPT transcript_string is undefined. Skip JSON translation for chat history")
|
|
153
148
|
}
|
|
154
149
|
}
|
|
@@ -158,7 +153,6 @@ class DirAskGPTV2 {
|
|
|
158
153
|
|
|
159
154
|
let key = await integrationService.getKeyFromIntegrations(this.projectId, 'openai', this.token);
|
|
160
155
|
if (!key) {
|
|
161
|
-
this.logger.debug("AskKnowledgeBase OpenAI key not found in Integration. Using shared OpenAI key");
|
|
162
156
|
winston.verbose("DirAskGPTV2 - Key not found in Integrations. Searching in kb settings...");
|
|
163
157
|
key = await this.getKeyFromKbSettings();
|
|
164
158
|
}
|
|
@@ -167,8 +161,6 @@ class DirAskGPTV2 {
|
|
|
167
161
|
winston.verbose("DirAskGPTV2 - Retrieve public gptkey")
|
|
168
162
|
key = process.env.GPTKEY;
|
|
169
163
|
publicKey = true;
|
|
170
|
-
} else {
|
|
171
|
-
this.logger.debug("AskKnowledgeBase use your own OpenAI key")
|
|
172
164
|
}
|
|
173
165
|
|
|
174
166
|
if (!key) {
|
|
@@ -186,7 +178,6 @@ class DirAskGPTV2 {
|
|
|
186
178
|
if (publicKey === true) {
|
|
187
179
|
let keep_going = await this.checkQuoteAvailability();
|
|
188
180
|
if (keep_going === false) {
|
|
189
|
-
this.logger.warn("AskKnowledgeBase Tokens quota exceeded. Skip the action")
|
|
190
181
|
winston.verbose("DirAskGPTV2 - Quota exceeded for tokens. Skip the action")
|
|
191
182
|
await this.chatbot.addParameter("flowError", "AskGPT Error: tokens quota exceeded");
|
|
192
183
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -200,17 +191,14 @@ class DirAskGPTV2 {
|
|
|
200
191
|
if (action.namespaceAsName) {
|
|
201
192
|
// Namespace could be an attribute
|
|
202
193
|
const filled_namespace = filler.fill(action.namespace, requestVariables)
|
|
203
|
-
this.logger.debug("AskKnowledgeBase Searching namespace by name ", filled_namespace);
|
|
204
194
|
ns = await this.getNamespace(filled_namespace, null);
|
|
205
195
|
namespace = ns?.id;
|
|
206
196
|
winston.verbose("DirAskGPTV2 - Retrieved namespace id from name " + namespace);
|
|
207
197
|
} else {
|
|
208
|
-
this.logger.debug("AskKnowledgeBase Searching namespace by id ", namespace);
|
|
209
198
|
ns = await this.getNamespace(null, namespace);
|
|
210
199
|
}
|
|
211
200
|
|
|
212
201
|
if (!ns) {
|
|
213
|
-
this.logger.error("AskKnowledgeBase Namespace not found")
|
|
214
202
|
await this.#assignAttributes(action, answer);
|
|
215
203
|
await this.chatbot.addParameter("flowError", "AskGPT Error: namespace not found");
|
|
216
204
|
if (falseIntent) {
|
|
@@ -229,7 +217,6 @@ class DirAskGPTV2 {
|
|
|
229
217
|
}
|
|
230
218
|
|
|
231
219
|
if (!namespace) {
|
|
232
|
-
this.logger.error("AskKnowledgeBase Namespace is undefined")
|
|
233
220
|
winston.verbose("DirAskGPTV2 - Error: namespace is undefined")
|
|
234
221
|
if (falseIntent) {
|
|
235
222
|
await this.chatbot.addParameter("flowError", "AskGPT Error: namespace is undefined");
|
|
@@ -11,6 +11,7 @@ class DirAssign {
|
|
|
11
11
|
throw new Error('context object is mandatory.');
|
|
12
12
|
}
|
|
13
13
|
this.context = context;
|
|
14
|
+
this.log = context.log;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
execute(directive, callback) {
|
|
@@ -62,11 +63,13 @@ class DirAssign {
|
|
|
62
63
|
const value = new TiledeskExpression().evaluateExpression(expression, variables);
|
|
63
64
|
winston.debug("(DirAssign) executed expression: " + expression + " value: " + value);
|
|
64
65
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, variableName, value);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
66
|
+
if (this.log) {
|
|
67
|
+
winston.debug("(DirAssign) Assigned: " + variableName + " = " + value);
|
|
68
|
+
const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
|
|
69
|
+
for (const [key, value] of Object.entries(all_parameters)) {
|
|
70
|
+
const value_type = typeof value;
|
|
71
|
+
winston.debug("(DirAssign) request parameter: " + key + " value: " + value + " type: " + value_type)
|
|
72
|
+
}
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
callback();
|
|
@@ -10,6 +10,7 @@ class DirAssignFromFunction {
|
|
|
10
10
|
throw new Error('context object is mandatory.');
|
|
11
11
|
}
|
|
12
12
|
this.context = context;
|
|
13
|
+
this.log = context.log;
|
|
13
14
|
this.tdcache = context.tdcache;
|
|
14
15
|
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
15
16
|
|
|
@@ -17,7 +18,8 @@ class DirAssignFromFunction {
|
|
|
17
18
|
projectId: this.context.projectId,
|
|
18
19
|
token: this.context.token,
|
|
19
20
|
APIURL: this.API_ENDPOINT,
|
|
20
|
-
APIKEY: "___"
|
|
21
|
+
APIKEY: "___",
|
|
22
|
+
log: this.log
|
|
21
23
|
});
|
|
22
24
|
}
|
|
23
25
|
|
|
@@ -20,6 +20,7 @@ class DirBrevo {
|
|
|
20
20
|
this.token = this.context.token;
|
|
21
21
|
this.intentDir = new DirIntent(context);
|
|
22
22
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
23
|
+
this.log = context.log;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
execute(directive, callback) {
|
|
@@ -157,10 +158,11 @@ class DirBrevo {
|
|
|
157
158
|
error = err.response.data.message;
|
|
158
159
|
}
|
|
159
160
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
if (this.log) {
|
|
162
|
+
winston.error("(DirBrevo) DirBrevo err data result:", result); // CONTROLLA IL VALORE
|
|
163
|
+
winston.error("(DirBrevo) DirBrevo err data status:", status);
|
|
164
|
+
winston.error("(DirBrevo) DirBrevo err data error:", error);
|
|
165
|
+
}
|
|
164
166
|
|
|
165
167
|
await this.#assignAttributes(action, status, result, error);
|
|
166
168
|
if (falseIntent) {
|
|
@@ -13,12 +13,14 @@ class DirClose {
|
|
|
13
13
|
this.requestId = context.requestId;
|
|
14
14
|
this.chatbot = context.chatbot;
|
|
15
15
|
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
16
|
+
this.log = context.log;
|
|
16
17
|
|
|
17
18
|
this.tdClient = new TiledeskClient({
|
|
18
19
|
projectId: this.context.projectId,
|
|
19
20
|
token: this.context.token,
|
|
20
21
|
APIURL: this.API_ENDPOINT,
|
|
21
22
|
APIKEY: "___",
|
|
23
|
+
log: this.log
|
|
22
24
|
});
|
|
23
25
|
}
|
|
24
26
|
|
|
@@ -19,12 +19,14 @@ class DirContactUpdate {
|
|
|
19
19
|
this.token = context.token;
|
|
20
20
|
this.tdcache = context.tdcache;
|
|
21
21
|
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
22
|
+
this.log = context.log;
|
|
22
23
|
|
|
23
24
|
this.tdClient = new TiledeskClient({
|
|
24
25
|
projectId: this.context.projectId,
|
|
25
26
|
token: this.context.token,
|
|
26
27
|
APIURL: this.API_ENDPOINT,
|
|
27
|
-
APIKEY: "___"
|
|
28
|
+
APIKEY: "___",
|
|
29
|
+
log: this.log
|
|
28
30
|
});
|
|
29
31
|
}
|
|
30
32
|
|
|
@@ -13,12 +13,14 @@ class DirDeflectToHelpCenter {
|
|
|
13
13
|
}
|
|
14
14
|
this.context = context;
|
|
15
15
|
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
16
|
+
this.log = context.log;
|
|
16
17
|
|
|
17
18
|
this.tdClient = new TiledeskClient({
|
|
18
19
|
projectId: this.context.projectId,
|
|
19
20
|
token: this.context.token,
|
|
20
21
|
APIURL: this.API_ENDPOINT,
|
|
21
|
-
APIKEY: "___"
|
|
22
|
+
APIKEY: "___",
|
|
23
|
+
log: this.log
|
|
22
24
|
});
|
|
23
25
|
}
|
|
24
26
|
|
|
@@ -68,7 +70,8 @@ class DirDeflectToHelpCenter {
|
|
|
68
70
|
if (last_user_text && last_user_text.trim() !== '') {
|
|
69
71
|
const helpcenter = new HelpCenterQuery({
|
|
70
72
|
APIKEY: "__",
|
|
71
|
-
projectId: project_id
|
|
73
|
+
projectId: project_id,
|
|
74
|
+
log: false
|
|
72
75
|
});
|
|
73
76
|
if (this.helpcenter_api_endpoint) {
|
|
74
77
|
helpcenter.APIURL = this.helpcenter_api_endpoint
|
|
@@ -10,12 +10,14 @@ class DirDepartment {
|
|
|
10
10
|
this.context = context;
|
|
11
11
|
this.requestId = context.requestId;
|
|
12
12
|
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
13
|
+
this.log = context.log;
|
|
13
14
|
|
|
14
15
|
this.tdClient = new TiledeskClient({
|
|
15
16
|
projectId: this.context.projectId,
|
|
16
17
|
token: this.context.token,
|
|
17
18
|
APIURL: this.API_ENDPOINT,
|
|
18
|
-
APIKEY: "___"
|
|
19
|
+
APIKEY: "___",
|
|
20
|
+
log: this.log
|
|
19
21
|
});
|
|
20
22
|
}
|
|
21
23
|
|
|
@@ -10,13 +10,15 @@ class DirFireTiledeskEvent {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
this.context = context;
|
|
13
|
+
this.log = context.log;
|
|
13
14
|
|
|
14
15
|
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
15
16
|
this.tdClient = new TiledeskClient({
|
|
16
17
|
projectId: this.context.projectId,
|
|
17
18
|
token: this.context.token,
|
|
18
19
|
APIURL: this.API_ENDPOINT,
|
|
19
|
-
APIKEY: "___"
|
|
20
|
+
APIKEY: "___",
|
|
21
|
+
log: this.log
|
|
20
22
|
});
|
|
21
23
|
}
|
|
22
24
|
|
|
@@ -15,13 +15,15 @@ class DirForm {
|
|
|
15
15
|
this.tdcache = context.tdcache;
|
|
16
16
|
this.requestId = context.requestId;
|
|
17
17
|
this.intentDir = new DirIntent(context);
|
|
18
|
+
this.log = context.log;
|
|
18
19
|
|
|
19
20
|
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
20
21
|
this.tdClient = new TiledeskClient({
|
|
21
22
|
projectId: this.context.projectId,
|
|
22
23
|
token: this.context.token,
|
|
23
24
|
APIURL: this.API_ENDPOINT,
|
|
24
|
-
APIKEY: "___"
|
|
25
|
+
APIKEY: "___",
|
|
26
|
+
log: this.log
|
|
25
27
|
});
|
|
26
28
|
|
|
27
29
|
}
|
|
@@ -3,7 +3,6 @@ const { TiledeskChatbot } = require("../../engine/TiledeskChatbot");
|
|
|
3
3
|
const { Filler } = require("../Filler");
|
|
4
4
|
let https = require("https");
|
|
5
5
|
const { DirIntent } = require("./DirIntent");
|
|
6
|
-
const winston = require('../../utils/winston');
|
|
7
6
|
const httpUtils = require("../../utils/HttpUtils");
|
|
8
7
|
require('dotenv').config();
|
|
9
8
|
|
|
@@ -18,16 +17,17 @@ class DirGptTask {
|
|
|
18
17
|
this.requestId = this.context.requestId;
|
|
19
18
|
this.intentDir = new DirIntent(context);
|
|
20
19
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
20
|
+
this.log = context.log;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
execute(directive, callback) {
|
|
24
|
-
|
|
24
|
+
if (this.log) { console.log("GptTask directive: ", directive); }
|
|
25
25
|
let action;
|
|
26
26
|
if (directive.action) {
|
|
27
27
|
action = directive.action;
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
30
|
-
|
|
30
|
+
console.error("Incorrect directive: ", JSON.stringify(directive));
|
|
31
31
|
callback();
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
@@ -37,9 +37,9 @@ class DirGptTask {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
async go(action, callback) {
|
|
40
|
-
|
|
40
|
+
if (this.log) { console.log("DirGptTask action:", JSON.stringify(action)); }
|
|
41
41
|
if (!this.tdcache) {
|
|
42
|
-
|
|
42
|
+
console.error("Error: DirGptTask tdcache is mandatory");
|
|
43
43
|
callback();
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
@@ -49,16 +49,18 @@ class DirGptTask {
|
|
|
49
49
|
let trueIntentAttributes = action.trueIntentAttributes;
|
|
50
50
|
let falseIntentAttributes = action.falseIntentAttributes;
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
if (this.log) {
|
|
53
|
+
console.log("DirGptTask trueIntent", trueIntent)
|
|
54
|
+
console.log("DirGptTask falseIntent", falseIntent)
|
|
55
|
+
console.log("DirGptTask trueIntentAttributes", trueIntentAttributes)
|
|
56
|
+
console.log("DirGptTask falseIntentAttributes", falseIntentAttributes)
|
|
57
|
+
}
|
|
56
58
|
|
|
57
59
|
// default value
|
|
58
60
|
let answer = "No answer.";
|
|
59
61
|
|
|
60
62
|
if (!action.question || action.question === '') {
|
|
61
|
-
|
|
63
|
+
console.error("Error: DirGptTask question attribute is mandatory. Executing condition false...")
|
|
62
64
|
if (falseIntent) {
|
|
63
65
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
64
66
|
callback(true);
|
|
@@ -80,11 +82,13 @@ class DirGptTask {
|
|
|
80
82
|
let max_tokens = action.max_tokens;
|
|
81
83
|
let temperature = action.temperature;
|
|
82
84
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
if (this.log) {
|
|
86
|
+
console.log("DirGptTask max_tokens: ", max_tokens);
|
|
87
|
+
console.log("DirGptTask temperature: ", temperature);
|
|
88
|
+
}
|
|
85
89
|
|
|
86
90
|
const openai_url = process.env.OPENAI_ENDPOINT + "/chat/completions";
|
|
87
|
-
|
|
91
|
+
if (this.log) { console.log("DirGptTask openai_url ", openai_url); }
|
|
88
92
|
|
|
89
93
|
const INTEGRATIONS_HTTPREQUEST = {
|
|
90
94
|
url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/openai",
|
|
@@ -94,7 +98,7 @@ class DirGptTask {
|
|
|
94
98
|
},
|
|
95
99
|
method: "GET"
|
|
96
100
|
}
|
|
97
|
-
|
|
101
|
+
if (this.log) { console.log("DirGptTask INTEGRATIONS_HTTPREQUEST ", INTEGRATIONS_HTTPREQUEST) }
|
|
98
102
|
|
|
99
103
|
httpUtils.request(
|
|
100
104
|
INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
|
|
@@ -106,7 +110,7 @@ class DirGptTask {
|
|
|
106
110
|
// return;
|
|
107
111
|
}
|
|
108
112
|
} else if (callback) {
|
|
109
|
-
|
|
113
|
+
if (this.log) { console.log("DirGptTask get integration resbody: ", integration); }
|
|
110
114
|
|
|
111
115
|
let key;
|
|
112
116
|
if (integration &&
|
|
@@ -117,7 +121,8 @@ class DirGptTask {
|
|
|
117
121
|
// key not present in integrations - for retro compatibility search in kbsettings
|
|
118
122
|
if (!key) {
|
|
119
123
|
|
|
120
|
-
|
|
124
|
+
// if (this.log) { console.log("DirGptTask - Key not found in Integrations. Searching in kb settings...")}
|
|
125
|
+
if (this.log) { console.log("DirGptTask - Key not found in Integrations. Searching in kb settings..."); }
|
|
121
126
|
|
|
122
127
|
const KB_HTTPREQUEST = {
|
|
123
128
|
url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
|
|
@@ -127,15 +132,16 @@ class DirGptTask {
|
|
|
127
132
|
},
|
|
128
133
|
method: "GET"
|
|
129
134
|
}
|
|
130
|
-
|
|
135
|
+
if (this.log) { console.log("DirGptTask KB_HTTPREQUEST", KB_HTTPREQUEST); }
|
|
131
136
|
|
|
132
137
|
httpUtils.request(
|
|
133
138
|
KB_HTTPREQUEST, async (err, resbody) => {
|
|
134
139
|
if (err) {
|
|
135
140
|
if (callback) {
|
|
136
141
|
console.error("(httprequest) DirGptTask Get KnowledgeBase err:", err.message);
|
|
137
|
-
|
|
138
|
-
|
|
142
|
+
if (this.log) {
|
|
143
|
+
console.error("(httprequest) DirGptTask Get KnowledgeBase full err", err);
|
|
144
|
+
}
|
|
139
145
|
await this.#assignAttributes(action, answer);
|
|
140
146
|
if (falseIntent) {
|
|
141
147
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -146,7 +152,7 @@ class DirGptTask {
|
|
|
146
152
|
return;
|
|
147
153
|
}
|
|
148
154
|
} else if (callback) {
|
|
149
|
-
|
|
155
|
+
if (this.log) { console.log("DirGptTask Get KnowledgeBase settings resbody:", resbody); }
|
|
150
156
|
|
|
151
157
|
if (!resbody.gptkey) {
|
|
152
158
|
await this.#assignAttributes(action, answer);
|
|
@@ -160,7 +166,7 @@ class DirGptTask {
|
|
|
160
166
|
|
|
161
167
|
} else {
|
|
162
168
|
|
|
163
|
-
|
|
169
|
+
if (this.log) { console.log("DirGptTask - Key found in KbSettings") };
|
|
164
170
|
|
|
165
171
|
key = resbody.gptkey;
|
|
166
172
|
|
|
@@ -182,7 +188,7 @@ class DirGptTask {
|
|
|
182
188
|
message.content = action.context;
|
|
183
189
|
json.messages.unshift(message);
|
|
184
190
|
}
|
|
185
|
-
|
|
191
|
+
if (this.log) { console.log("DirGptTask json: ", json) }
|
|
186
192
|
|
|
187
193
|
const HTTPREQUEST = {
|
|
188
194
|
url: openai_url,
|
|
@@ -193,12 +199,14 @@ class DirGptTask {
|
|
|
193
199
|
json: json,
|
|
194
200
|
method: 'POST'
|
|
195
201
|
}
|
|
196
|
-
|
|
202
|
+
if (this.log) { console.log("DirGptTask HTTPREQUEST: ", HTTPREQUEST); }
|
|
197
203
|
httpUtils.request(
|
|
198
204
|
HTTPREQUEST, async (err, resbody) => {
|
|
199
205
|
if (err) {
|
|
200
|
-
|
|
201
|
-
|
|
206
|
+
if (this.log) {
|
|
207
|
+
console.error("(httprequest) DirGptTask openai err:", err);
|
|
208
|
+
console.error("(httprequest) DirGptTask openai err:", err.response.data);
|
|
209
|
+
}
|
|
202
210
|
await this.#assignAttributes(action, answer);
|
|
203
211
|
if (falseIntent) {
|
|
204
212
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -208,7 +216,7 @@ class DirGptTask {
|
|
|
208
216
|
callback();
|
|
209
217
|
return;
|
|
210
218
|
} else {
|
|
211
|
-
|
|
219
|
+
if (this.log) { console.log("DirGptTask resbody: ", JSON.stringify(resbody)); }
|
|
212
220
|
answer = resbody.choices[0].message.content;
|
|
213
221
|
let answer_json = await this.convertToJson(answer);
|
|
214
222
|
await this.#assignAttributes(action, answer_json);
|
|
@@ -228,7 +236,7 @@ class DirGptTask {
|
|
|
228
236
|
)
|
|
229
237
|
} else {
|
|
230
238
|
|
|
231
|
-
|
|
239
|
+
if (this.log) { console.log("DirGptTask - Key found in Integrations") };
|
|
232
240
|
|
|
233
241
|
let json = {
|
|
234
242
|
"model": action.model,
|
|
@@ -248,7 +256,7 @@ class DirGptTask {
|
|
|
248
256
|
message.content = action.context;
|
|
249
257
|
json.messages.unshift(message);
|
|
250
258
|
}
|
|
251
|
-
|
|
259
|
+
if (this.log) { console.log("DirGptTask json: ", json) }
|
|
252
260
|
|
|
253
261
|
const HTTPREQUEST = {
|
|
254
262
|
url: openai_url,
|
|
@@ -259,12 +267,14 @@ class DirGptTask {
|
|
|
259
267
|
json: json,
|
|
260
268
|
method: 'POST'
|
|
261
269
|
}
|
|
262
|
-
|
|
270
|
+
if (this.log) { console.log("DirGptTask HTTPREQUEST: ", HTTPREQUEST); }
|
|
263
271
|
httpUtils.request(
|
|
264
272
|
HTTPREQUEST, async (err, resbody) => {
|
|
265
273
|
if (err) {
|
|
266
|
-
|
|
267
|
-
|
|
274
|
+
if (this.log) {
|
|
275
|
+
console.error("(httprequest) DirGptTask openai err:", err);
|
|
276
|
+
console.error("(httprequest) DirGptTask openai err:", err.response.data);
|
|
277
|
+
}
|
|
268
278
|
await this.#assignAttributes(action, answer);
|
|
269
279
|
if (falseIntent) {
|
|
270
280
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -274,7 +284,7 @@ class DirGptTask {
|
|
|
274
284
|
callback();
|
|
275
285
|
return;
|
|
276
286
|
} else {
|
|
277
|
-
|
|
287
|
+
if (this.log) { console.log("DirGptTask resbody: ", JSON.stringify(resbody)); }
|
|
278
288
|
answer = resbody.choices[0].message.content;
|
|
279
289
|
// check if answer is a json
|
|
280
290
|
let answer_json = await this.convertToJson(answer);
|
|
@@ -328,7 +338,7 @@ class DirGptTask {
|
|
|
328
338
|
})
|
|
329
339
|
}
|
|
330
340
|
else {
|
|
331
|
-
|
|
341
|
+
if (this.log) { console.log("No trueIntentDirective specified"); }
|
|
332
342
|
if (callback) {
|
|
333
343
|
callback();
|
|
334
344
|
}
|
|
@@ -343,7 +353,7 @@ class DirGptTask {
|
|
|
343
353
|
});
|
|
344
354
|
}
|
|
345
355
|
else {
|
|
346
|
-
|
|
356
|
+
if (this.log) { console.log("No falseIntentDirective specified"); }
|
|
347
357
|
if (callback) {
|
|
348
358
|
callback();
|
|
349
359
|
}
|
|
@@ -352,8 +362,10 @@ class DirGptTask {
|
|
|
352
362
|
}
|
|
353
363
|
|
|
354
364
|
async #assignAttributes(action, answer) {
|
|
355
|
-
|
|
356
|
-
|
|
365
|
+
if (this.log) {
|
|
366
|
+
console.log("assignAttributes action:", action)
|
|
367
|
+
console.log("assignAttributes answer:", answer)
|
|
368
|
+
}
|
|
357
369
|
if (this.context.tdcache) {
|
|
358
370
|
if (action.assignReplyTo && answer) {
|
|
359
371
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignReplyTo, answer);
|
|
@@ -361,6 +373,13 @@ class DirGptTask {
|
|
|
361
373
|
// if (action.assignSourceTo && source) {
|
|
362
374
|
// await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignSourceTo, source);
|
|
363
375
|
// }
|
|
376
|
+
// Debug log
|
|
377
|
+
if (this.log) {
|
|
378
|
+
const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
|
|
379
|
+
for (const [key, value] of Object.entries(all_parameters)) {
|
|
380
|
+
if (this.log) { console.log("(gpttask) request parameter:", key, "value:", value, "type:", typeof value) }
|
|
381
|
+
}
|
|
382
|
+
}
|
|
364
383
|
}
|
|
365
384
|
}
|
|
366
385
|
|