@tiledesk/tiledesk-tybot-connector 2.0.10-rc9 → 2.0.11
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 -332
- package/tiledeskChatbotPlugs/directives/DirFlowLog.js +0 -88
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.11",
|
|
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.2.1-rc2",
|
|
19
19
|
"accept-language-parser": "^1.5.0",
|
|
20
20
|
"app-root-path": "^3.1.0",
|
|
21
21
|
"axios": "^1.7.7",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"liquidjs": "^10.8.4",
|
|
30
30
|
"minimist-string": "^1.0.2",
|
|
31
31
|
"mongoose": "^6.3.5",
|
|
32
|
-
"mqtt": "^5.10.4",
|
|
33
32
|
"multer": "^1.4.5-lts.1",
|
|
34
33
|
"nanoid": "^3.1.25",
|
|
35
34
|
"redis": "^4.7.0",
|
package/services/AIService.js
CHANGED
|
@@ -57,10 +57,8 @@ 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');
|
|
61
60
|
|
|
62
61
|
const winston = require('../utils/winston');
|
|
63
|
-
const { DirFlowLog } = require('./directives/DirFlowLog');
|
|
64
62
|
|
|
65
63
|
class DirectivesChatbotPlug {
|
|
66
64
|
|
|
@@ -75,6 +73,7 @@ class DirectivesChatbotPlug {
|
|
|
75
73
|
this.API_ENDPOINT = config.API_ENDPOINT;
|
|
76
74
|
this.TILEBOT_ENDPOINT = config.TILEBOT_ENDPOINT;
|
|
77
75
|
this.token = config.token;
|
|
76
|
+
this.log = config.log;
|
|
78
77
|
this.HELP_CENTER_API_ENDPOINT = config.HELP_CENTER_API_ENDPOINT;
|
|
79
78
|
this.tdcache = config.cache;
|
|
80
79
|
this.directives = config.directives;
|
|
@@ -143,7 +142,8 @@ class DirectivesChatbotPlug {
|
|
|
143
142
|
projectId: projectId,
|
|
144
143
|
token: token,
|
|
145
144
|
APIURL: API_ENDPOINT,
|
|
146
|
-
APIKEY: "___"
|
|
145
|
+
APIKEY: "___",
|
|
146
|
+
log: this.log
|
|
147
147
|
});
|
|
148
148
|
}
|
|
149
149
|
catch(err) {
|
|
@@ -162,7 +162,8 @@ class DirectivesChatbotPlug {
|
|
|
162
162
|
TILEBOT_ENDPOINT: TILEBOT_ENDPOINT,
|
|
163
163
|
departmentId: depId,
|
|
164
164
|
tdcache: tdcache,
|
|
165
|
-
HELP_CENTER_API_ENDPOINT: this.HELP_CENTER_API_ENDPOINT
|
|
165
|
+
HELP_CENTER_API_ENDPOINT: this.HELP_CENTER_API_ENDPOINT,
|
|
166
|
+
log: this.log
|
|
166
167
|
}
|
|
167
168
|
winston.debug("(DirectivesChatbotPlug) this.context.departmentId: " + this.context.departmentId);
|
|
168
169
|
|
|
@@ -176,7 +177,9 @@ class DirectivesChatbotPlug {
|
|
|
176
177
|
|
|
177
178
|
async nextDirective(directives) {
|
|
178
179
|
winston.debug("(DirectivesChatbotPlug) ....nextDirective() checkStep()");
|
|
179
|
-
const go_on = await TiledeskChatbot.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
|
+
);
|
|
180
183
|
|
|
181
184
|
if (go_on.error) {
|
|
182
185
|
winston.debug("(DirectivesChatbotPlug) go_on == false! nextDirective() Stopped!");
|
|
@@ -219,13 +222,14 @@ class DirectivesChatbotPlug {
|
|
|
219
222
|
directive_name = directive.name.toLowerCase();
|
|
220
223
|
}
|
|
221
224
|
if (directive && directive.action) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
225
|
+
const action_id = directive.action["_tdActionId"];
|
|
226
|
+
const locked_action_id = await this.chatbot.currentLockedAction(this.supportRequest.request_id);
|
|
227
|
+
if ( locked_action_id && (locked_action_id !== action_id) ) {
|
|
228
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
229
|
+
this.process(next_dir);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
229
233
|
}
|
|
230
234
|
if (directive == null || (directive !== null && directive["name"] === undefined)) {
|
|
231
235
|
winston.debug("(DirectivesChatbotPlug) stop process(). directive is (null?): ", directive);
|
|
@@ -697,37 +701,12 @@ class DirectivesChatbotPlug {
|
|
|
697
701
|
}
|
|
698
702
|
});
|
|
699
703
|
}
|
|
700
|
-
else if (directive_name === Directives.WEBHOOK) {
|
|
701
|
-
// console.log(".....DirIntent")
|
|
702
|
-
new DirIntent(context).execute(directive, async (stop) => {
|
|
703
|
-
if (stop) {
|
|
704
|
-
if (context.log) { console.log("Stopping Actions on:", JSON.stringify(directive));}
|
|
705
|
-
this.theend();
|
|
706
|
-
}
|
|
707
|
-
else {
|
|
708
|
-
let next_dir = await this.nextDirective(this.directives);
|
|
709
|
-
this.process(next_dir);
|
|
710
|
-
}
|
|
711
|
-
});
|
|
712
|
-
}
|
|
713
704
|
else if (directive_name === Directives.WEB_RESPONSE) {
|
|
714
705
|
new DirWebResponse(context).execute(directive, async () => {
|
|
715
706
|
let next_dir = await this.nextDirective(this.directives);
|
|
716
707
|
this.process(next_dir);
|
|
717
708
|
});
|
|
718
709
|
}
|
|
719
|
-
else if (directive_name === Directives.FLOW_LOG) {
|
|
720
|
-
new DirFlowLog(context).execute(directive, async () => {
|
|
721
|
-
let next_dir = await this.nextDirective(this.directives);
|
|
722
|
-
this.process(next_dir);
|
|
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
|
-
}
|
|
731
710
|
else {
|
|
732
711
|
let next_dir = await this.nextDirective(this.directives);
|
|
733
712
|
this.process(next_dir);
|
|
@@ -754,7 +733,8 @@ class DirectivesChatbotPlug {
|
|
|
754
733
|
projectId: projectId,
|
|
755
734
|
token: token,
|
|
756
735
|
APIURL: API_ENDPOINT,
|
|
757
|
-
APIKEY: "___"
|
|
736
|
+
APIKEY: "___",
|
|
737
|
+
log: false
|
|
758
738
|
});
|
|
759
739
|
let i = -1;
|
|
760
740
|
winston.debug("(DirectivesChatbotPlug) processing Inline directives: ", directives);
|
|
@@ -3,10 +3,11 @@ const winston = require('../utils/winston');
|
|
|
3
3
|
|
|
4
4
|
class WebhookChatbotPlug {
|
|
5
5
|
|
|
6
|
-
constructor(supportRequest, webhookurl, token) {
|
|
6
|
+
constructor(supportRequest, webhookurl, token, log) {
|
|
7
7
|
this.supportRequest = supportRequest;
|
|
8
8
|
this.webhookurl = webhookurl;
|
|
9
9
|
this.token = token;
|
|
10
|
+
this.log = log;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
exec(pipeline) {
|
|
@@ -100,18 +101,19 @@ class WebhookChatbotPlug {
|
|
|
100
101
|
callback(null, res.data);
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
|
-
}
|
|
104
|
+
}, this.log
|
|
105
|
+
);
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
// ************************************************
|
|
107
109
|
// ****************** HTTP REQUEST ****************
|
|
108
110
|
// ************************************************
|
|
109
111
|
|
|
110
|
-
static myrequest(options, callback) {
|
|
111
|
-
|
|
112
|
+
static myrequest(options, callback, log) {
|
|
113
|
+
if (log) {
|
|
112
114
|
winston.debug("(WebhookChatbotPlug) myrequest API URL:" + options.url);
|
|
113
115
|
winston.debug("(WebhookChatbotPlug) myrequest Options:", options);
|
|
114
|
-
|
|
116
|
+
}
|
|
115
117
|
axios(
|
|
116
118
|
{
|
|
117
119
|
url: options.url,
|
|
@@ -120,11 +122,11 @@ class WebhookChatbotPlug {
|
|
|
120
122
|
headers: options.headers
|
|
121
123
|
})
|
|
122
124
|
.then(function (res) {
|
|
123
|
-
|
|
125
|
+
if (log) {
|
|
124
126
|
winston.debug("(WebhookChatbotPlug) myrequest Response for url:", options.url);
|
|
125
127
|
winston.debug("(WebhookChatbotPlug) myrequest Response headers:\n", res.headers);
|
|
126
128
|
winston.debug("(WebhookChatbotPlug) myrequest Response body:\n", res.data);
|
|
127
|
-
|
|
129
|
+
}
|
|
128
130
|
if (callback) {
|
|
129
131
|
callback(null, res);
|
|
130
132
|
}
|
|
@@ -12,7 +12,8 @@ class DirIfNotOpenHours {
|
|
|
12
12
|
projectId: context.projectId,
|
|
13
13
|
token: context.token,
|
|
14
14
|
APIURL: context.TILEDESK_APIURL,
|
|
15
|
-
APIKEY: "___"
|
|
15
|
+
APIKEY: "___",
|
|
16
|
+
log: context.log
|
|
16
17
|
});
|
|
17
18
|
// this.intentDir = config.intentDir;
|
|
18
19
|
// let context = {
|
|
@@ -21,16 +22,19 @@ class DirIfNotOpenHours {
|
|
|
21
22
|
// requestId: supportRequest,
|
|
22
23
|
// APIURL: API_URL,
|
|
23
24
|
// TILEBOT_ENDPOINT:TILEBOT_ENDPOINT,
|
|
24
|
-
// departmentId: depId
|
|
25
|
+
// departmentId: depId,
|
|
26
|
+
// log: false
|
|
25
27
|
// }
|
|
26
28
|
this.intentDir = new DirIntent(
|
|
27
29
|
{
|
|
28
30
|
API_ENDPOINT: context.TILEDESK_APIURL,
|
|
29
31
|
TILEBOT_ENDPOINT: context.TILEBOT_ENDPOINT,
|
|
30
32
|
supportRequest: context.supportRequest,
|
|
31
|
-
token: context.token
|
|
33
|
+
token: context.token,
|
|
34
|
+
log: context.log
|
|
32
35
|
}
|
|
33
36
|
);
|
|
37
|
+
this.log = context.log;
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
execute(directive, callback) {
|
|
@@ -54,6 +58,7 @@ class DirIfNotOpenHours {
|
|
|
54
58
|
go(action, callback) {
|
|
55
59
|
const intentName = action.body.intentName;
|
|
56
60
|
if (!intentName) {
|
|
61
|
+
if (this.log) {console.log("Invalid intent name for If-open-hours");}
|
|
57
62
|
callback();
|
|
58
63
|
}
|
|
59
64
|
let intentDirective = {
|
|
@@ -64,11 +69,13 @@ class DirIfNotOpenHours {
|
|
|
64
69
|
}
|
|
65
70
|
}
|
|
66
71
|
this.tdclient.openNow((err, result) => {
|
|
72
|
+
if (this.log) {console.log("openNow():", result);}
|
|
67
73
|
if (err) {
|
|
68
74
|
console.error("DirIfNotOpenHours Error:", err);
|
|
69
75
|
callback();
|
|
70
76
|
}
|
|
71
77
|
else if (result && !result.isopen) {
|
|
78
|
+
if (this.log) {console.log("executing the action on 'closed'");}
|
|
72
79
|
this.intentDir.execute(intentDirective, () => {
|
|
73
80
|
callback();
|
|
74
81
|
});
|
|
@@ -12,7 +12,8 @@ class DirIfOpenHours {
|
|
|
12
12
|
projectId: context.projectId,
|
|
13
13
|
token: context.token,
|
|
14
14
|
APIURL: context.TILEDESK_APIURL,
|
|
15
|
-
APIKEY: "___"
|
|
15
|
+
APIKEY: "___",
|
|
16
|
+
log: context.log
|
|
16
17
|
});
|
|
17
18
|
// let context = {
|
|
18
19
|
// projectId: projectId,
|
|
@@ -21,6 +22,7 @@ class DirIfOpenHours {
|
|
|
21
22
|
// APIURL: API_URL,
|
|
22
23
|
// TILEBOT_ENDPOINT:TILEBOT_ENDPOINT,
|
|
23
24
|
// departmentId: depId,
|
|
25
|
+
// log: false
|
|
24
26
|
// }
|
|
25
27
|
this.intentDir = new DirIntent(
|
|
26
28
|
{
|
|
@@ -28,8 +30,10 @@ class DirIfOpenHours {
|
|
|
28
30
|
TILEBOT_ENDPOINT: context.TILEBOT_ENDPOINT,
|
|
29
31
|
supportRequest: context.supportRequest,
|
|
30
32
|
token: context.token,
|
|
33
|
+
log: context.log
|
|
31
34
|
}
|
|
32
|
-
)
|
|
35
|
+
);
|
|
36
|
+
this.log = context.log;
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
execute(directive, callback) {
|
|
@@ -52,6 +56,7 @@ class DirIfOpenHours {
|
|
|
52
56
|
go(action, callback) {
|
|
53
57
|
const intentName = action.body.intentName;
|
|
54
58
|
if (!intentName) {
|
|
59
|
+
if (this.log) {console.log("Invalid intent name for If-open-hours");}
|
|
55
60
|
callback();
|
|
56
61
|
}
|
|
57
62
|
let intentDirective = {
|
|
@@ -62,11 +67,13 @@ class DirIfOpenHours {
|
|
|
62
67
|
}
|
|
63
68
|
}
|
|
64
69
|
this.tdclient.openNow((err, result) => {
|
|
70
|
+
if (this.log) {console.log("openNow():", result);}
|
|
65
71
|
if (err) {
|
|
66
72
|
console.error("DirIfOpenHours Error:", err);
|
|
67
73
|
callback();
|
|
68
74
|
}
|
|
69
75
|
else if (result && result.isopen) {
|
|
76
|
+
if (this.log) {console.log("executing the action on 'open'");}
|
|
70
77
|
this.intentDir.execute(intentDirective, () => {
|
|
71
78
|
callback();
|
|
72
79
|
});
|
|
@@ -8,7 +8,6 @@ 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");
|
|
12
11
|
require('dotenv').config();
|
|
13
12
|
const winston = require('../../utils/winston');
|
|
14
13
|
const httpUtils = require("../../utils/HttpUtils");
|
|
@@ -25,31 +24,28 @@ class DirAddTags {
|
|
|
25
24
|
this.requestId = this.context.requestId;
|
|
26
25
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
27
26
|
this.log = context.log;
|
|
28
|
-
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest.draft });
|
|
29
27
|
|
|
30
28
|
this.tdClient = new TiledeskClient({
|
|
31
29
|
projectId: this.context.projectId,
|
|
32
30
|
token: this.context.token,
|
|
33
31
|
APIURL: this.API_ENDPOINT,
|
|
34
|
-
APIKEY: "___"
|
|
32
|
+
APIKEY: "___",
|
|
33
|
+
log: this.log
|
|
35
34
|
});
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
execute(directive, callback) {
|
|
39
|
-
winston.verbose("Execute AddTags
|
|
40
|
-
this.logger.error("Execute AddTags directive")
|
|
38
|
+
winston.verbose("Execute AddTags directive");
|
|
41
39
|
let action;
|
|
42
40
|
if (directive.action) {
|
|
43
41
|
action = directive.action;
|
|
44
42
|
}
|
|
45
43
|
else {
|
|
46
|
-
|
|
47
|
-
winston.debug("Incorrect directive: ", directive);
|
|
44
|
+
winston.warn("Incorrect directive: ", directive);
|
|
48
45
|
callback();
|
|
49
46
|
return;
|
|
50
47
|
}
|
|
51
48
|
this.go(action, (stop) => {
|
|
52
|
-
this.logger.info("Acion AddTag completed");
|
|
53
49
|
callback(stop);
|
|
54
50
|
})
|
|
55
51
|
}
|
|
@@ -70,7 +66,6 @@ class DirAddTags {
|
|
|
70
66
|
pushToList = action.pushToList
|
|
71
67
|
|
|
72
68
|
if (!action.tags || action.tags === '') {
|
|
73
|
-
this.logger.error("Add tags Error: tags attribute is mandatory");
|
|
74
69
|
winston.error("(DirAddTags) Error: tags attribute is mandatory")
|
|
75
70
|
await this.chatbot.addParameter("flowError", "Add tags Error: tags attribute is mandatory");
|
|
76
71
|
callback();
|
|
@@ -91,7 +86,6 @@ class DirAddTags {
|
|
|
91
86
|
if(target === 'request'){
|
|
92
87
|
|
|
93
88
|
let newTags = filled_tags.split(',').filter(tag => tag !== '').map(el => el.trim())
|
|
94
|
-
this.logger.debug("Adding following tags to conversation: ", newTags)
|
|
95
89
|
|
|
96
90
|
if(action.pushToList){
|
|
97
91
|
newTags.forEach(async (tag) => {
|
|
@@ -105,7 +99,6 @@ 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")
|
|
109
102
|
if(!updatedRequest){
|
|
110
103
|
callback();
|
|
111
104
|
return;
|
|
@@ -116,7 +109,6 @@ class DirAddTags {
|
|
|
116
109
|
/** use case: LEAD */
|
|
117
110
|
if(target === 'lead'){
|
|
118
111
|
let newTags = filled_tags.split(',').filter(tag => tag !== '').map(el => el.trim())
|
|
119
|
-
this.logger.debug("Adding following tags to lead: ", newTags)
|
|
120
112
|
|
|
121
113
|
let request = await this.tdClient.getRequestById(this.requestId);
|
|
122
114
|
winston.debug('(DirAddTags) request detail: ', request)
|
|
@@ -138,7 +130,6 @@ class DirAddTags {
|
|
|
138
130
|
|
|
139
131
|
winston.debug('(DirAddTags) UPDATE lead with newTags ', newTags)
|
|
140
132
|
let updatedLead = await this.updateLeadWithTags(request.lead._id, newTags)
|
|
141
|
-
this.logger.info("Tags added to lead")
|
|
142
133
|
if(!updatedLead){
|
|
143
134
|
callback();
|
|
144
135
|
return;
|
|
@@ -183,7 +174,6 @@ class DirAddTags {
|
|
|
183
174
|
httpUtils.request(
|
|
184
175
|
HTTPREQUEST, async (err, resbody) => {
|
|
185
176
|
if (err) {
|
|
186
|
-
this.logger.error("Add tags to list error ", err?.response?.data)
|
|
187
177
|
winston.error("(httprequest) DirAddTags add tags to list err: ", err);
|
|
188
178
|
resolve(true)
|
|
189
179
|
} else {
|
|
@@ -218,7 +208,6 @@ class DirAddTags {
|
|
|
218
208
|
httpUtils.request(
|
|
219
209
|
HTTPREQUEST, async (err, resbody) => {
|
|
220
210
|
if (err) {
|
|
221
|
-
this.logger.error("Add tag to conversation error ", err?.response?.data);
|
|
222
211
|
winston.error("(httprequest) DirAddTags patch request with new tags err: ", err);
|
|
223
212
|
resolve(true)
|
|
224
213
|
} else {
|
|
@@ -248,7 +237,6 @@ class DirAddTags {
|
|
|
248
237
|
httpUtils.request(
|
|
249
238
|
HTTPREQUEST, async (err, resbody) => {
|
|
250
239
|
if (err) {
|
|
251
|
-
this.logger.error("Add tag to lead error ", err?.response?.data);
|
|
252
240
|
winston.error("(httprequest) DirAddTags put lead with new tags err: ", err);
|
|
253
241
|
resolve(true)
|
|
254
242
|
} else {
|
|
@@ -11,7 +11,6 @@ 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");
|
|
15
14
|
|
|
16
15
|
|
|
17
16
|
class DirAiPrompt {
|
|
@@ -29,24 +28,20 @@ class DirAiPrompt {
|
|
|
29
28
|
this.intentDir = new DirIntent(context);
|
|
30
29
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
31
30
|
this.log = context.log;
|
|
32
|
-
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest.draft });
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
execute(directive, callback) {
|
|
36
34
|
winston.verbose("Execute AiPrompt directive");
|
|
37
|
-
this.logger.error("AiPrompt: executing action");
|
|
38
35
|
let action;
|
|
39
36
|
if (directive.action) {
|
|
40
37
|
action = directive.action;
|
|
41
38
|
}
|
|
42
39
|
else {
|
|
43
|
-
this.logger.error("AiPrompt incorrect action ", directive)
|
|
44
40
|
winston.debug("DirAiPrompt Incorrect directive: ", directive);
|
|
45
41
|
callback();
|
|
46
42
|
return;
|
|
47
43
|
}
|
|
48
44
|
this.go(action, (stop) => {
|
|
49
|
-
this.logger.info("AiPrompt: action completed");
|
|
50
45
|
callback(stop);
|
|
51
46
|
})
|
|
52
47
|
}
|
|
@@ -70,7 +65,6 @@ class DirAiPrompt {
|
|
|
70
65
|
winston.debug("DirAskGPTV2 falseIntent", falseIntent)
|
|
71
66
|
|
|
72
67
|
await this.checkMandatoryParameters(action).catch( async (missing_param) => {
|
|
73
|
-
this.logger.error(`AiPrompt: missing attribute '${missing_param}'`);
|
|
74
68
|
await this.chatbot.addParameter("flowError", "AiPrompt Error: '" + missing_param + "' attribute is undefined");
|
|
75
69
|
if (falseIntent) {
|
|
76
70
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -92,7 +86,6 @@ class DirAiPrompt {
|
|
|
92
86
|
const filled_context = filler.fill(action.context, requestVariables);
|
|
93
87
|
|
|
94
88
|
if (action.history) {
|
|
95
|
-
this.logger.info("AiPrompt: using chat transcript");
|
|
96
89
|
let transcript_string = await TiledeskChatbot.getParameterStatic(
|
|
97
90
|
this.context.tdcache,
|
|
98
91
|
this.context.requestId,
|
|
@@ -103,7 +96,6 @@ class DirAiPrompt {
|
|
|
103
96
|
transcript = await TiledeskChatbotUtil.transcriptJSON(transcript_string);
|
|
104
97
|
winston.debug("DirAiPrompt transcript: ", transcript)
|
|
105
98
|
} else {
|
|
106
|
-
this.logger.warn("AiPrompt: no chat transcript found, skipping history translation");
|
|
107
99
|
winston.verbose("DirAiPrompt transcript_string is undefined. Skip JSON translation for chat history")
|
|
108
100
|
}
|
|
109
101
|
}
|
|
@@ -120,7 +112,6 @@ class DirAiPrompt {
|
|
|
120
112
|
|
|
121
113
|
if (action.llm === 'ollama') {
|
|
122
114
|
ollama_integration = await integrationService.getIntegration(this.projectId, action.llm, this.token).catch( async (err) => {
|
|
123
|
-
this.logger.error("AiPrompt: Error getting ollama integration.")
|
|
124
115
|
winston.error("DirAiPrompt Error getting ollama integration: ", err);
|
|
125
116
|
await this.chatbot.addParameter("flowError", "Ollama integration not found");
|
|
126
117
|
if (falseIntent) {
|
|
@@ -136,7 +127,6 @@ class DirAiPrompt {
|
|
|
136
127
|
key = await integrationService.getKeyFromIntegrations(this.projectId, action.llm, this.token);
|
|
137
128
|
|
|
138
129
|
if (!key) {
|
|
139
|
-
this.logger.error("AiPrompt: llm key not found in integrations");
|
|
140
130
|
winston.error("Error: DirAiPrompt llm key not found in integrations");
|
|
141
131
|
await this.chatbot.addParameter("flowError", "AiPrompt Error: missing key for llm " + action.llm);
|
|
142
132
|
if (falseIntent) {
|
|
@@ -199,7 +189,6 @@ class DirAiPrompt {
|
|
|
199
189
|
} else {
|
|
200
190
|
error = JSON.stringify(err.response.data);
|
|
201
191
|
}
|
|
202
|
-
this.logger.error("AiPrompt: error executing action: ", error);
|
|
203
192
|
if (falseIntent) {
|
|
204
193
|
await this.chatbot.addParameter("flowError", "AiPrompt Error: " + error);
|
|
205
194
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -212,7 +201,6 @@ class DirAiPrompt {
|
|
|
212
201
|
|
|
213
202
|
winston.debug("DirAiPrompt resbody: ", resbody);
|
|
214
203
|
answer = resbody.answer;
|
|
215
|
-
this.logger.info("AiPrompt: answer: ", answer);
|
|
216
204
|
|
|
217
205
|
await this.#assignAttributes(action, answer);
|
|
218
206
|
|
|
@@ -300,7 +288,6 @@ class DirAiPrompt {
|
|
|
300
288
|
}
|
|
301
289
|
if (result === true) {
|
|
302
290
|
if (trueIntentDirective) {
|
|
303
|
-
this.logger.info("AiPrompt: executing true condition");
|
|
304
291
|
this.intentDir.execute(trueIntentDirective, () => {
|
|
305
292
|
if (callback) {
|
|
306
293
|
callback();
|
|
@@ -308,7 +295,6 @@ class DirAiPrompt {
|
|
|
308
295
|
})
|
|
309
296
|
}
|
|
310
297
|
else {
|
|
311
|
-
this.logger.info("AiPrompt: no block connected to true condition");
|
|
312
298
|
winston.debug("DirAiPrompt No trueIntentDirective specified");
|
|
313
299
|
if (callback) {
|
|
314
300
|
callback();
|
|
@@ -317,7 +303,6 @@ class DirAiPrompt {
|
|
|
317
303
|
}
|
|
318
304
|
else {
|
|
319
305
|
if (falseIntentDirective) {
|
|
320
|
-
this.logger.info("AiPrompt: executing false condition");
|
|
321
306
|
this.intentDir.execute(falseIntentDirective, () => {
|
|
322
307
|
if (callback) {
|
|
323
308
|
callback();
|
|
@@ -325,7 +310,6 @@ class DirAiPrompt {
|
|
|
325
310
|
});
|
|
326
311
|
}
|
|
327
312
|
else {
|
|
328
|
-
this.logger.info("AiPrompt: no block connected to false condition");
|
|
329
313
|
winston.debug("DirAiPrompt No falseIntentDirective specified");
|
|
330
314
|
if (callback) {
|
|
331
315
|
callback();
|