@tiledesk/tiledesk-tybot-connector 2.0.9 → 2.0.10-rc2
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 +27 -2
- package/ExtApi.js +1 -8
- package/ExtUtil.js +5 -6
- package/Logger.js +27 -17
- package/engine/IntentForm.js +0 -1
- package/engine/IntentsMachineFactory.js +4 -4
- package/engine/MongodbBotsDataSource.js +0 -1
- package/engine/MongodbIntentsMachine.js +0 -1
- package/engine/TiledeskChatbot.js +11 -16
- package/engine/TiledeskIntentsMachine.js +1 -2
- package/engine/mock/MockBotsDataSource.js +1 -2
- package/index.js +22 -25
- package/logs/app.log +11066 -20247
- package/logs/app2.log +46280 -0
- package/logs/app3.log +31686 -0
- package/logs/app4.log +46163 -0
- package/logs/app5.log +39983 -0
- package/logs/app6.log +5964 -0
- package/package.json +3 -2
- package/services/AIService.js +1 -1
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +31 -18
- package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +1 -2
- package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +1 -3
- package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +1 -3
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +7 -9
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfNotOpenHours.js +3 -10
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfOpenHours.js +2 -9
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +16 -4
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +16 -0
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +16 -0
- package/tiledeskChatbotPlugs/directives/DirAssign.js +5 -8
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +4 -6
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirClose.js +0 -2
- package/tiledeskChatbotPlugs/directives/DirCode.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirCondition.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +2 -5
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirFlowLog.js +76 -0
- package/tiledeskChatbotPlugs/directives/DirForm.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +36 -55
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +1 -4
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +1 -4
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +0 -2
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +8 -12
- package/tiledeskChatbotPlugs/directives/DirIntent.js +6 -5
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirMake.js +1 -16
- package/tiledeskChatbotPlugs/directives/DirMessage.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +1 -4
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +0 -3
- package/tiledeskChatbotPlugs/directives/DirQapla.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +1 -2
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirReply.js +7 -18
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +8 -13
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +1 -4
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirWait.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +14 -15
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +6 -40
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +0 -1
- package/tiledeskChatbotPlugs/directives/Directives.js +2 -0
- package/utils/TiledeskChatbotUtil.js +19 -57
- package/TdCache copy.js +0 -242
- package/logs/app1.log +0 -16071
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +0 -417
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiledesk/tiledesk-tybot-connector",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.10-rc2",
|
|
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.
|
|
18
|
+
"@tiledesk/tiledesk-multi-worker": "^0.3.1-rc11",
|
|
19
19
|
"accept-language-parser": "^1.5.0",
|
|
20
20
|
"app-root-path": "^3.1.0",
|
|
21
21
|
"axios": "^1.7.7",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"liquidjs": "^10.8.4",
|
|
30
30
|
"minimist-string": "^1.0.2",
|
|
31
31
|
"mongoose": "^6.3.5",
|
|
32
|
+
"mqtt": "^5.10.4",
|
|
32
33
|
"multer": "^1.4.5-lts.1",
|
|
33
34
|
"nanoid": "^3.1.25",
|
|
34
35
|
"redis": "^4.7.0",
|
package/services/AIService.js
CHANGED
|
@@ -59,6 +59,7 @@ const { DirWebResponse } = require('./directives/DirWebResponse');
|
|
|
59
59
|
const { DirConnectBlock } = require('./directives/DirConnectBlock');
|
|
60
60
|
|
|
61
61
|
const winston = require('../utils/winston');
|
|
62
|
+
const { DirFlowLog } = require('./directives/DirFlowLog');
|
|
62
63
|
|
|
63
64
|
class DirectivesChatbotPlug {
|
|
64
65
|
|
|
@@ -73,7 +74,6 @@ class DirectivesChatbotPlug {
|
|
|
73
74
|
this.API_ENDPOINT = config.API_ENDPOINT;
|
|
74
75
|
this.TILEBOT_ENDPOINT = config.TILEBOT_ENDPOINT;
|
|
75
76
|
this.token = config.token;
|
|
76
|
-
this.log = config.log;
|
|
77
77
|
this.HELP_CENTER_API_ENDPOINT = config.HELP_CENTER_API_ENDPOINT;
|
|
78
78
|
this.tdcache = config.cache;
|
|
79
79
|
this.directives = config.directives;
|
|
@@ -142,8 +142,7 @@ class DirectivesChatbotPlug {
|
|
|
142
142
|
projectId: projectId,
|
|
143
143
|
token: token,
|
|
144
144
|
APIURL: API_ENDPOINT,
|
|
145
|
-
APIKEY: "___"
|
|
146
|
-
log: this.log
|
|
145
|
+
APIKEY: "___"
|
|
147
146
|
});
|
|
148
147
|
}
|
|
149
148
|
catch(err) {
|
|
@@ -162,8 +161,7 @@ class DirectivesChatbotPlug {
|
|
|
162
161
|
TILEBOT_ENDPOINT: TILEBOT_ENDPOINT,
|
|
163
162
|
departmentId: depId,
|
|
164
163
|
tdcache: tdcache,
|
|
165
|
-
HELP_CENTER_API_ENDPOINT: this.HELP_CENTER_API_ENDPOINT
|
|
166
|
-
log: this.log
|
|
164
|
+
HELP_CENTER_API_ENDPOINT: this.HELP_CENTER_API_ENDPOINT
|
|
167
165
|
}
|
|
168
166
|
winston.debug("(DirectivesChatbotPlug) this.context.departmentId: " + this.context.departmentId);
|
|
169
167
|
|
|
@@ -177,9 +175,7 @@ class DirectivesChatbotPlug {
|
|
|
177
175
|
|
|
178
176
|
async nextDirective(directives) {
|
|
179
177
|
winston.debug("(DirectivesChatbotPlug) ....nextDirective() checkStep()");
|
|
180
|
-
const go_on = await TiledeskChatbot.checkStep(
|
|
181
|
-
this.context.tdcache, this.context.requestId, this.chatbot?.MAX_STEPS, this.chatbot?.MAX_EXECUTION_TIME, this.log
|
|
182
|
-
);
|
|
178
|
+
const go_on = await TiledeskChatbot.checkStep(this.context.tdcache, this.context.requestId, this.chatbot?.MAX_STEPS, this.chatbot?.MAX_EXECUTION_TIME);
|
|
183
179
|
|
|
184
180
|
if (go_on.error) {
|
|
185
181
|
winston.debug("(DirectivesChatbotPlug) go_on == false! nextDirective() Stopped!");
|
|
@@ -222,14 +218,13 @@ class DirectivesChatbotPlug {
|
|
|
222
218
|
directive_name = directive.name.toLowerCase();
|
|
223
219
|
}
|
|
224
220
|
if (directive && directive.action) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
221
|
+
const action_id = directive.action["_tdActionId"];
|
|
222
|
+
const locked_action_id = await this.chatbot.currentLockedAction(this.supportRequest.request_id);
|
|
223
|
+
if ( locked_action_id && (locked_action_id !== action_id) ) {
|
|
224
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
225
|
+
this.process(next_dir);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
233
228
|
}
|
|
234
229
|
if (directive == null || (directive !== null && directive["name"] === undefined)) {
|
|
235
230
|
winston.debug("(DirectivesChatbotPlug) stop process(). directive is (null?): ", directive);
|
|
@@ -701,12 +696,31 @@ class DirectivesChatbotPlug {
|
|
|
701
696
|
}
|
|
702
697
|
});
|
|
703
698
|
}
|
|
699
|
+
else if (directive_name === Directives.WEBHOOK) {
|
|
700
|
+
// console.log(".....DirIntent")
|
|
701
|
+
new DirIntent(context).execute(directive, async (stop) => {
|
|
702
|
+
if (stop) {
|
|
703
|
+
if (context.log) { console.log("Stopping Actions on:", JSON.stringify(directive));}
|
|
704
|
+
this.theend();
|
|
705
|
+
}
|
|
706
|
+
else {
|
|
707
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
708
|
+
this.process(next_dir);
|
|
709
|
+
}
|
|
710
|
+
});
|
|
711
|
+
}
|
|
704
712
|
else if (directive_name === Directives.WEB_RESPONSE) {
|
|
705
713
|
new DirWebResponse(context).execute(directive, async () => {
|
|
706
714
|
let next_dir = await this.nextDirective(this.directives);
|
|
707
715
|
this.process(next_dir);
|
|
708
716
|
});
|
|
709
717
|
}
|
|
718
|
+
else if (directive_name === Directives.FLOW_LOG) {
|
|
719
|
+
new DirFlowLog(context).execute(directive, async () => {
|
|
720
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
721
|
+
this.process(next_dir);
|
|
722
|
+
})
|
|
723
|
+
}
|
|
710
724
|
else {
|
|
711
725
|
let next_dir = await this.nextDirective(this.directives);
|
|
712
726
|
this.process(next_dir);
|
|
@@ -733,8 +747,7 @@ class DirectivesChatbotPlug {
|
|
|
733
747
|
projectId: projectId,
|
|
734
748
|
token: token,
|
|
735
749
|
APIURL: API_ENDPOINT,
|
|
736
|
-
APIKEY: "___"
|
|
737
|
-
log: false
|
|
750
|
+
APIKEY: "___"
|
|
738
751
|
});
|
|
739
752
|
let i = -1;
|
|
740
753
|
winston.debug("(DirectivesChatbotPlug) processing Inline directives: ", directives);
|
|
@@ -3,11 +3,10 @@ const winston = require('../utils/winston');
|
|
|
3
3
|
|
|
4
4
|
class WebhookChatbotPlug {
|
|
5
5
|
|
|
6
|
-
constructor(supportRequest, webhookurl, token
|
|
6
|
+
constructor(supportRequest, webhookurl, token) {
|
|
7
7
|
this.supportRequest = supportRequest;
|
|
8
8
|
this.webhookurl = webhookurl;
|
|
9
9
|
this.token = token;
|
|
10
|
-
this.log = log;
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
exec(pipeline) {
|
|
@@ -101,19 +100,18 @@ class WebhookChatbotPlug {
|
|
|
101
100
|
callback(null, res.data);
|
|
102
101
|
}
|
|
103
102
|
}
|
|
104
|
-
}
|
|
105
|
-
);
|
|
103
|
+
});
|
|
106
104
|
}
|
|
107
105
|
|
|
108
106
|
// ************************************************
|
|
109
107
|
// ****************** HTTP REQUEST ****************
|
|
110
108
|
// ************************************************
|
|
111
109
|
|
|
112
|
-
static myrequest(options, callback
|
|
113
|
-
|
|
110
|
+
static myrequest(options, callback) {
|
|
111
|
+
|
|
114
112
|
winston.debug("(WebhookChatbotPlug) myrequest API URL:" + options.url);
|
|
115
113
|
winston.debug("(WebhookChatbotPlug) myrequest Options:", options);
|
|
116
|
-
|
|
114
|
+
|
|
117
115
|
axios(
|
|
118
116
|
{
|
|
119
117
|
url: options.url,
|
|
@@ -122,11 +120,11 @@ class WebhookChatbotPlug {
|
|
|
122
120
|
headers: options.headers
|
|
123
121
|
})
|
|
124
122
|
.then(function (res) {
|
|
125
|
-
|
|
123
|
+
|
|
126
124
|
winston.debug("(WebhookChatbotPlug) myrequest Response for url:", options.url);
|
|
127
125
|
winston.debug("(WebhookChatbotPlug) myrequest Response headers:\n", res.headers);
|
|
128
126
|
winston.debug("(WebhookChatbotPlug) myrequest Response body:\n", res.data);
|
|
129
|
-
|
|
127
|
+
|
|
130
128
|
if (callback) {
|
|
131
129
|
callback(null, res);
|
|
132
130
|
}
|
|
@@ -12,8 +12,7 @@ class DirIfNotOpenHours {
|
|
|
12
12
|
projectId: context.projectId,
|
|
13
13
|
token: context.token,
|
|
14
14
|
APIURL: context.TILEDESK_APIURL,
|
|
15
|
-
APIKEY: "___"
|
|
16
|
-
log: context.log
|
|
15
|
+
APIKEY: "___"
|
|
17
16
|
});
|
|
18
17
|
// this.intentDir = config.intentDir;
|
|
19
18
|
// let context = {
|
|
@@ -22,19 +21,16 @@ class DirIfNotOpenHours {
|
|
|
22
21
|
// requestId: supportRequest,
|
|
23
22
|
// APIURL: API_URL,
|
|
24
23
|
// TILEBOT_ENDPOINT:TILEBOT_ENDPOINT,
|
|
25
|
-
// departmentId: depId
|
|
26
|
-
// log: false
|
|
24
|
+
// departmentId: depId
|
|
27
25
|
// }
|
|
28
26
|
this.intentDir = new DirIntent(
|
|
29
27
|
{
|
|
30
28
|
API_ENDPOINT: context.TILEDESK_APIURL,
|
|
31
29
|
TILEBOT_ENDPOINT: context.TILEBOT_ENDPOINT,
|
|
32
30
|
supportRequest: context.supportRequest,
|
|
33
|
-
token: context.token
|
|
34
|
-
log: context.log
|
|
31
|
+
token: context.token
|
|
35
32
|
}
|
|
36
33
|
);
|
|
37
|
-
this.log = context.log;
|
|
38
34
|
}
|
|
39
35
|
|
|
40
36
|
execute(directive, callback) {
|
|
@@ -58,7 +54,6 @@ class DirIfNotOpenHours {
|
|
|
58
54
|
go(action, callback) {
|
|
59
55
|
const intentName = action.body.intentName;
|
|
60
56
|
if (!intentName) {
|
|
61
|
-
if (this.log) {console.log("Invalid intent name for If-open-hours");}
|
|
62
57
|
callback();
|
|
63
58
|
}
|
|
64
59
|
let intentDirective = {
|
|
@@ -69,13 +64,11 @@ class DirIfNotOpenHours {
|
|
|
69
64
|
}
|
|
70
65
|
}
|
|
71
66
|
this.tdclient.openNow((err, result) => {
|
|
72
|
-
if (this.log) {console.log("openNow():", result);}
|
|
73
67
|
if (err) {
|
|
74
68
|
console.error("DirIfNotOpenHours Error:", err);
|
|
75
69
|
callback();
|
|
76
70
|
}
|
|
77
71
|
else if (result && !result.isopen) {
|
|
78
|
-
if (this.log) {console.log("executing the action on 'closed'");}
|
|
79
72
|
this.intentDir.execute(intentDirective, () => {
|
|
80
73
|
callback();
|
|
81
74
|
});
|
|
@@ -12,8 +12,7 @@ class DirIfOpenHours {
|
|
|
12
12
|
projectId: context.projectId,
|
|
13
13
|
token: context.token,
|
|
14
14
|
APIURL: context.TILEDESK_APIURL,
|
|
15
|
-
APIKEY: "___"
|
|
16
|
-
log: context.log
|
|
15
|
+
APIKEY: "___"
|
|
17
16
|
});
|
|
18
17
|
// let context = {
|
|
19
18
|
// projectId: projectId,
|
|
@@ -22,7 +21,6 @@ class DirIfOpenHours {
|
|
|
22
21
|
// APIURL: API_URL,
|
|
23
22
|
// TILEBOT_ENDPOINT:TILEBOT_ENDPOINT,
|
|
24
23
|
// departmentId: depId,
|
|
25
|
-
// log: false
|
|
26
24
|
// }
|
|
27
25
|
this.intentDir = new DirIntent(
|
|
28
26
|
{
|
|
@@ -30,10 +28,8 @@ class DirIfOpenHours {
|
|
|
30
28
|
TILEBOT_ENDPOINT: context.TILEBOT_ENDPOINT,
|
|
31
29
|
supportRequest: context.supportRequest,
|
|
32
30
|
token: context.token,
|
|
33
|
-
log: context.log
|
|
34
31
|
}
|
|
35
|
-
)
|
|
36
|
-
this.log = context.log;
|
|
32
|
+
)
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
execute(directive, callback) {
|
|
@@ -56,7 +52,6 @@ class DirIfOpenHours {
|
|
|
56
52
|
go(action, callback) {
|
|
57
53
|
const intentName = action.body.intentName;
|
|
58
54
|
if (!intentName) {
|
|
59
|
-
if (this.log) {console.log("Invalid intent name for If-open-hours");}
|
|
60
55
|
callback();
|
|
61
56
|
}
|
|
62
57
|
let intentDirective = {
|
|
@@ -67,13 +62,11 @@ class DirIfOpenHours {
|
|
|
67
62
|
}
|
|
68
63
|
}
|
|
69
64
|
this.tdclient.openNow((err, result) => {
|
|
70
|
-
if (this.log) {console.log("openNow():", result);}
|
|
71
65
|
if (err) {
|
|
72
66
|
console.error("DirIfOpenHours Error:", err);
|
|
73
67
|
callback();
|
|
74
68
|
}
|
|
75
69
|
else if (result && result.isopen) {
|
|
76
|
-
if (this.log) {console.log("executing the action on 'open'");}
|
|
77
70
|
this.intentDir.execute(intentDirective, () => {
|
|
78
71
|
callback();
|
|
79
72
|
});
|
|
@@ -8,6 +8,7 @@ const { TiledeskChatbotUtil } = require("../../utils/TiledeskChatbotUtil");
|
|
|
8
8
|
const req = require("express/lib/request");
|
|
9
9
|
const { update } = require("../../models/faq");
|
|
10
10
|
const { TiledeskClient } = require("@tiledesk/tiledesk-client");
|
|
11
|
+
const { Logger } = require("../../Logger");
|
|
11
12
|
require('dotenv').config();
|
|
12
13
|
const winston = require('../../utils/winston');
|
|
13
14
|
const httpUtils = require("../../utils/HttpUtils");
|
|
@@ -24,28 +25,31 @@ class DirAddTags {
|
|
|
24
25
|
this.requestId = this.context.requestId;
|
|
25
26
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
26
27
|
this.log = context.log;
|
|
28
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest.draft });
|
|
27
29
|
|
|
28
30
|
this.tdClient = new TiledeskClient({
|
|
29
31
|
projectId: this.context.projectId,
|
|
30
32
|
token: this.context.token,
|
|
31
33
|
APIURL: this.API_ENDPOINT,
|
|
32
|
-
APIKEY: "___"
|
|
33
|
-
log: this.log
|
|
34
|
+
APIKEY: "___"
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
execute(directive, callback) {
|
|
38
|
-
winston.verbose("Execute AddTags
|
|
39
|
+
winston.verbose("Execute AddTags action");
|
|
40
|
+
this.logger.error("Execute AddTags directive")
|
|
39
41
|
let action;
|
|
40
42
|
if (directive.action) {
|
|
41
43
|
action = directive.action;
|
|
42
44
|
}
|
|
43
45
|
else {
|
|
44
|
-
|
|
46
|
+
this.logger.error("Incorrect action for ", directive.name, directive)
|
|
47
|
+
winston.debug("Incorrect directive: ", directive);
|
|
45
48
|
callback();
|
|
46
49
|
return;
|
|
47
50
|
}
|
|
48
51
|
this.go(action, (stop) => {
|
|
52
|
+
this.logger.info("Acion AddTag completed");
|
|
49
53
|
callback(stop);
|
|
50
54
|
})
|
|
51
55
|
}
|
|
@@ -66,6 +70,7 @@ class DirAddTags {
|
|
|
66
70
|
pushToList = action.pushToList
|
|
67
71
|
|
|
68
72
|
if (!action.tags || action.tags === '') {
|
|
73
|
+
this.logger.error("Add tags Error: tags attribute is mandatory");
|
|
69
74
|
winston.error("(DirAddTags) Error: tags attribute is mandatory")
|
|
70
75
|
await this.chatbot.addParameter("flowError", "Add tags Error: tags attribute is mandatory");
|
|
71
76
|
callback();
|
|
@@ -86,6 +91,7 @@ class DirAddTags {
|
|
|
86
91
|
if(target === 'request'){
|
|
87
92
|
|
|
88
93
|
let newTags = filled_tags.split(',').filter(tag => tag !== '').map(el => el.trim())
|
|
94
|
+
this.logger.debug("Adding following tags to conversation: ", newTags)
|
|
89
95
|
|
|
90
96
|
if(action.pushToList){
|
|
91
97
|
newTags.forEach(async (tag) => {
|
|
@@ -99,6 +105,7 @@ class DirAddTags {
|
|
|
99
105
|
|
|
100
106
|
winston.debug('(DirAddTags) UPDATE request with newTags', newTags)
|
|
101
107
|
let updatedRequest = await this.updateRequestWithTags(newTags)
|
|
108
|
+
this.logger.info("Tags added to conversation")
|
|
102
109
|
if(!updatedRequest){
|
|
103
110
|
callback();
|
|
104
111
|
return;
|
|
@@ -109,6 +116,7 @@ class DirAddTags {
|
|
|
109
116
|
/** use case: LEAD */
|
|
110
117
|
if(target === 'lead'){
|
|
111
118
|
let newTags = filled_tags.split(',').filter(tag => tag !== '').map(el => el.trim())
|
|
119
|
+
this.logger.debug("Adding following tags to lead: ", newTags)
|
|
112
120
|
|
|
113
121
|
let request = await this.tdClient.getRequestById(this.requestId);
|
|
114
122
|
winston.debug('(DirAddTags) request detail: ', request)
|
|
@@ -130,6 +138,7 @@ class DirAddTags {
|
|
|
130
138
|
|
|
131
139
|
winston.debug('(DirAddTags) UPDATE lead with newTags ', newTags)
|
|
132
140
|
let updatedLead = await this.updateLeadWithTags(request.lead._id, newTags)
|
|
141
|
+
this.logger.info("Tags added to lead")
|
|
133
142
|
if(!updatedLead){
|
|
134
143
|
callback();
|
|
135
144
|
return;
|
|
@@ -174,6 +183,7 @@ class DirAddTags {
|
|
|
174
183
|
httpUtils.request(
|
|
175
184
|
HTTPREQUEST, async (err, resbody) => {
|
|
176
185
|
if (err) {
|
|
186
|
+
this.logger.error("Add tags to list error ", err?.response?.data)
|
|
177
187
|
winston.error("(httprequest) DirAddTags add tags to list err: ", err);
|
|
178
188
|
resolve(true)
|
|
179
189
|
} else {
|
|
@@ -208,6 +218,7 @@ class DirAddTags {
|
|
|
208
218
|
httpUtils.request(
|
|
209
219
|
HTTPREQUEST, async (err, resbody) => {
|
|
210
220
|
if (err) {
|
|
221
|
+
this.logger.error("Add tag to conversation error ", err?.response?.data);
|
|
211
222
|
winston.error("(httprequest) DirAddTags patch request with new tags err: ", err);
|
|
212
223
|
resolve(true)
|
|
213
224
|
} else {
|
|
@@ -237,6 +248,7 @@ class DirAddTags {
|
|
|
237
248
|
httpUtils.request(
|
|
238
249
|
HTTPREQUEST, async (err, resbody) => {
|
|
239
250
|
if (err) {
|
|
251
|
+
this.logger.error("Add tag to lead error ", err?.response?.data);
|
|
240
252
|
winston.error("(httprequest) DirAddTags put lead with new tags err: ", err);
|
|
241
253
|
resolve(true)
|
|
242
254
|
} else {
|
|
@@ -11,6 +11,7 @@ const Utils = require("../../utils/HttpUtils");
|
|
|
11
11
|
const utils = require("../../utils/HttpUtils");
|
|
12
12
|
const httpUtils = require("../../utils/HttpUtils");
|
|
13
13
|
const integrationService = require("../../services/IntegrationService");
|
|
14
|
+
const { Logger } = require("../../Logger");
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
class DirAiPrompt {
|
|
@@ -28,20 +29,24 @@ class DirAiPrompt {
|
|
|
28
29
|
this.intentDir = new DirIntent(context);
|
|
29
30
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
30
31
|
this.log = context.log;
|
|
32
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest.draft });
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
execute(directive, callback) {
|
|
34
36
|
winston.verbose("Execute AiPrompt directive");
|
|
37
|
+
this.logger.error("AiPrompt: executing action");
|
|
35
38
|
let action;
|
|
36
39
|
if (directive.action) {
|
|
37
40
|
action = directive.action;
|
|
38
41
|
}
|
|
39
42
|
else {
|
|
43
|
+
this.logger.error("AiPrompt incorrect action ", directive)
|
|
40
44
|
winston.debug("DirAiPrompt Incorrect directive: ", directive);
|
|
41
45
|
callback();
|
|
42
46
|
return;
|
|
43
47
|
}
|
|
44
48
|
this.go(action, (stop) => {
|
|
49
|
+
this.logger.info("AiPrompt: action completed");
|
|
45
50
|
callback(stop);
|
|
46
51
|
})
|
|
47
52
|
}
|
|
@@ -65,6 +70,7 @@ class DirAiPrompt {
|
|
|
65
70
|
winston.debug("DirAskGPTV2 falseIntent", falseIntent)
|
|
66
71
|
|
|
67
72
|
await this.checkMandatoryParameters(action).catch( async (missing_param) => {
|
|
73
|
+
this.logger.error(`AiPrompt: missing attribute '${missing_param}'`);
|
|
68
74
|
await this.chatbot.addParameter("flowError", "AiPrompt Error: '" + missing_param + "' attribute is undefined");
|
|
69
75
|
if (falseIntent) {
|
|
70
76
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -86,6 +92,7 @@ class DirAiPrompt {
|
|
|
86
92
|
const filled_context = filler.fill(action.context, requestVariables);
|
|
87
93
|
|
|
88
94
|
if (action.history) {
|
|
95
|
+
this.logger.info("AiPrompt: using chat transcript");
|
|
89
96
|
let transcript_string = await TiledeskChatbot.getParameterStatic(
|
|
90
97
|
this.context.tdcache,
|
|
91
98
|
this.context.requestId,
|
|
@@ -96,6 +103,7 @@ class DirAiPrompt {
|
|
|
96
103
|
transcript = await TiledeskChatbotUtil.transcriptJSON(transcript_string);
|
|
97
104
|
winston.debug("DirAiPrompt transcript: ", transcript)
|
|
98
105
|
} else {
|
|
106
|
+
this.logger.warn("AiPrompt: no chat transcript found, skipping history translation");
|
|
99
107
|
winston.verbose("DirAiPrompt transcript_string is undefined. Skip JSON translation for chat history")
|
|
100
108
|
}
|
|
101
109
|
}
|
|
@@ -112,6 +120,7 @@ class DirAiPrompt {
|
|
|
112
120
|
|
|
113
121
|
if (action.llm === 'ollama') {
|
|
114
122
|
ollama_integration = await integrationService.getIntegration(this.projectId, action.llm, this.token).catch( async (err) => {
|
|
123
|
+
this.logger.error("AiPrompt: Error getting ollama integration.")
|
|
115
124
|
winston.error("DirAiPrompt Error getting ollama integration: ", err);
|
|
116
125
|
await this.chatbot.addParameter("flowError", "Ollama integration not found");
|
|
117
126
|
if (falseIntent) {
|
|
@@ -127,6 +136,7 @@ class DirAiPrompt {
|
|
|
127
136
|
key = await integrationService.getKeyFromIntegrations(this.projectId, action.llm, this.token);
|
|
128
137
|
|
|
129
138
|
if (!key) {
|
|
139
|
+
this.logger.error("AiPrompt: llm key not found in integrations");
|
|
130
140
|
winston.error("Error: DirAiPrompt llm key not found in integrations");
|
|
131
141
|
await this.chatbot.addParameter("flowError", "AiPrompt Error: missing key for llm " + action.llm);
|
|
132
142
|
if (falseIntent) {
|
|
@@ -189,6 +199,7 @@ class DirAiPrompt {
|
|
|
189
199
|
} else {
|
|
190
200
|
error = JSON.stringify(err.response.data);
|
|
191
201
|
}
|
|
202
|
+
this.logger.error("AiPrompt: error executing action: ", error);
|
|
192
203
|
if (falseIntent) {
|
|
193
204
|
await this.chatbot.addParameter("flowError", "AiPrompt Error: " + error);
|
|
194
205
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -201,6 +212,7 @@ class DirAiPrompt {
|
|
|
201
212
|
|
|
202
213
|
winston.debug("DirAiPrompt resbody: ", resbody);
|
|
203
214
|
answer = resbody.answer;
|
|
215
|
+
this.logger.info("AiPrompt: answer: ", answer);
|
|
204
216
|
|
|
205
217
|
await this.#assignAttributes(action, answer);
|
|
206
218
|
|
|
@@ -288,6 +300,7 @@ class DirAiPrompt {
|
|
|
288
300
|
}
|
|
289
301
|
if (result === true) {
|
|
290
302
|
if (trueIntentDirective) {
|
|
303
|
+
this.logger.info("AiPrompt: executing true condition");
|
|
291
304
|
this.intentDir.execute(trueIntentDirective, () => {
|
|
292
305
|
if (callback) {
|
|
293
306
|
callback();
|
|
@@ -295,6 +308,7 @@ class DirAiPrompt {
|
|
|
295
308
|
})
|
|
296
309
|
}
|
|
297
310
|
else {
|
|
311
|
+
this.logger.info("AiPrompt: no block connected to true condition");
|
|
298
312
|
winston.debug("DirAiPrompt No trueIntentDirective specified");
|
|
299
313
|
if (callback) {
|
|
300
314
|
callback();
|
|
@@ -303,6 +317,7 @@ class DirAiPrompt {
|
|
|
303
317
|
}
|
|
304
318
|
else {
|
|
305
319
|
if (falseIntentDirective) {
|
|
320
|
+
this.logger.info("AiPrompt: executing false condition");
|
|
306
321
|
this.intentDir.execute(falseIntentDirective, () => {
|
|
307
322
|
if (callback) {
|
|
308
323
|
callback();
|
|
@@ -310,6 +325,7 @@ class DirAiPrompt {
|
|
|
310
325
|
});
|
|
311
326
|
}
|
|
312
327
|
else {
|
|
328
|
+
this.logger.info("AiPrompt: no block connected to false condition");
|
|
313
329
|
winston.debug("DirAiPrompt No falseIntentDirective specified");
|
|
314
330
|
if (callback) {
|
|
315
331
|
callback();
|
|
@@ -10,6 +10,7 @@ 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");
|
|
13
14
|
|
|
14
15
|
class DirAskGPTV2 {
|
|
15
16
|
|
|
@@ -26,20 +27,24 @@ class DirAskGPTV2 {
|
|
|
26
27
|
this.intentDir = new DirIntent(context);
|
|
27
28
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
28
29
|
this.log = context.log;
|
|
30
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest.draft });
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
execute(directive, callback) {
|
|
34
|
+
this.logger.error("Execute AskKnowledgeBase action")
|
|
32
35
|
winston.debug("DirAskGPTV2 directive: ", directive);
|
|
33
36
|
let action;
|
|
34
37
|
if (directive.action) {
|
|
35
38
|
action = directive.action;
|
|
36
39
|
}
|
|
37
40
|
else {
|
|
41
|
+
this.logger.error("Incorrect action for ", directive.name, directive)
|
|
38
42
|
winston.debug("DirAskGPTV2 Incorrect directive: ", directive);
|
|
39
43
|
callback();
|
|
40
44
|
return;
|
|
41
45
|
}
|
|
42
46
|
this.go(action, (stop) => {
|
|
47
|
+
this.logger.info("Acion AskKnowledgeBase completed");
|
|
43
48
|
callback(stop);
|
|
44
49
|
})
|
|
45
50
|
}
|
|
@@ -87,6 +92,7 @@ class DirAskGPTV2 {
|
|
|
87
92
|
let source = null;
|
|
88
93
|
|
|
89
94
|
if (!action.question || action.question === '') {
|
|
95
|
+
this.logger.error("AskKnowledgeBase question attribute is mandatory");
|
|
90
96
|
winston.error("DirAskGPTV2 Error: question attribute is mandatory. Executing condition false...");
|
|
91
97
|
await this.#assignAttributes(action, answer, source);
|
|
92
98
|
if (falseIntent) {
|
|
@@ -130,6 +136,7 @@ class DirAskGPTV2 {
|
|
|
130
136
|
const filled_context = filler.fill(action.context, requestVariables)
|
|
131
137
|
|
|
132
138
|
if (action.history) {
|
|
139
|
+
this.logger.info("AskKnowledgeBase: use chat transcript")
|
|
133
140
|
let transcript_string = await TiledeskChatbot.getParameterStatic(
|
|
134
141
|
this.context.tdcache,
|
|
135
142
|
this.context.requestId,
|
|
@@ -141,6 +148,7 @@ class DirAskGPTV2 {
|
|
|
141
148
|
transcript = await TiledeskChatbotUtil.transcriptJSON(transcript_string);
|
|
142
149
|
winston.debug("DirAskGPTV2 transcript ", transcript)
|
|
143
150
|
} else {
|
|
151
|
+
this.logger.warn("AskKnowledgeBase: chat transcript is undefined. Skip JSON translation for chat history.");
|
|
144
152
|
winston.verbose("DirAskGPT transcript_string is undefined. Skip JSON translation for chat history")
|
|
145
153
|
}
|
|
146
154
|
}
|
|
@@ -150,6 +158,7 @@ class DirAskGPTV2 {
|
|
|
150
158
|
|
|
151
159
|
let key = await integrationService.getKeyFromIntegrations(this.projectId, 'openai', this.token);
|
|
152
160
|
if (!key) {
|
|
161
|
+
this.logger.debug("AskKnowledgeBase OpenAI key not found in Integration. Using shared OpenAI key");
|
|
153
162
|
winston.verbose("DirAskGPTV2 - Key not found in Integrations. Searching in kb settings...");
|
|
154
163
|
key = await this.getKeyFromKbSettings();
|
|
155
164
|
}
|
|
@@ -158,6 +167,8 @@ class DirAskGPTV2 {
|
|
|
158
167
|
winston.verbose("DirAskGPTV2 - Retrieve public gptkey")
|
|
159
168
|
key = process.env.GPTKEY;
|
|
160
169
|
publicKey = true;
|
|
170
|
+
} else {
|
|
171
|
+
this.logger.debug("AskKnowledgeBase use your own OpenAI key")
|
|
161
172
|
}
|
|
162
173
|
|
|
163
174
|
if (!key) {
|
|
@@ -175,6 +186,7 @@ class DirAskGPTV2 {
|
|
|
175
186
|
if (publicKey === true) {
|
|
176
187
|
let keep_going = await this.checkQuoteAvailability();
|
|
177
188
|
if (keep_going === false) {
|
|
189
|
+
this.logger.warn("AskKnowledgeBase Tokens quota exceeded. Skip the action")
|
|
178
190
|
winston.verbose("DirAskGPTV2 - Quota exceeded for tokens. Skip the action")
|
|
179
191
|
await this.chatbot.addParameter("flowError", "AskGPT Error: tokens quota exceeded");
|
|
180
192
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -188,14 +200,17 @@ class DirAskGPTV2 {
|
|
|
188
200
|
if (action.namespaceAsName) {
|
|
189
201
|
// Namespace could be an attribute
|
|
190
202
|
const filled_namespace = filler.fill(action.namespace, requestVariables)
|
|
203
|
+
this.logger.debug("AskKnowledgeBase Searching namespace by name ", filled_namespace);
|
|
191
204
|
ns = await this.getNamespace(filled_namespace, null);
|
|
192
205
|
namespace = ns?.id;
|
|
193
206
|
winston.verbose("DirAskGPTV2 - Retrieved namespace id from name " + namespace);
|
|
194
207
|
} else {
|
|
208
|
+
this.logger.debug("AskKnowledgeBase Searching namespace by id ", namespace);
|
|
195
209
|
ns = await this.getNamespace(null, namespace);
|
|
196
210
|
}
|
|
197
211
|
|
|
198
212
|
if (!ns) {
|
|
213
|
+
this.logger.error("AskKnowledgeBase Namespace not found")
|
|
199
214
|
await this.#assignAttributes(action, answer);
|
|
200
215
|
await this.chatbot.addParameter("flowError", "AskGPT Error: namespace not found");
|
|
201
216
|
if (falseIntent) {
|
|
@@ -214,6 +229,7 @@ class DirAskGPTV2 {
|
|
|
214
229
|
}
|
|
215
230
|
|
|
216
231
|
if (!namespace) {
|
|
232
|
+
this.logger.error("AskKnowledgeBase Namespace is undefined")
|
|
217
233
|
winston.verbose("DirAskGPTV2 - Error: namespace is undefined")
|
|
218
234
|
if (falseIntent) {
|
|
219
235
|
await this.chatbot.addParameter("flowError", "AskGPT Error: namespace is undefined");
|