@tiledesk/tiledesk-tybot-connector 2.0.11 → 2.0.12-rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Logger.js +28 -16
- package/logs/app2.log +1882 -0
- package/package.json +3 -2
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +7 -0
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +17 -11
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +18 -2
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +2 -2
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +18 -2
- package/tiledeskChatbotPlugs/directives/DirAssign.js +0 -9
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +1 -8
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +13 -3
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +11 -8
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +10 -1
- package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +5 -0
- package/tiledeskChatbotPlugs/directives/DirClose.js +8 -9
- package/tiledeskChatbotPlugs/directives/DirCode.js +9 -1
- package/tiledeskChatbotPlugs/directives/DirCondition.js +13 -1
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +7 -9
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +11 -2
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +1 -7
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +14 -1
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -9
- package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +2 -8
- package/tiledeskChatbotPlugs/directives/DirFlowLog.js +88 -0
- package/tiledeskChatbotPlugs/directives/DirForm.js +3 -10
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +19 -7
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +12 -3
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +3 -9
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +12 -10
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +11 -1
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +3 -9
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +14 -4
- package/tiledeskChatbotPlugs/directives/DirMake.js +6 -1
- package/tiledeskChatbotPlugs/directives/DirMessage.js +1 -7
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +5 -9
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +6 -9
- package/tiledeskChatbotPlugs/directives/DirQapla.js +7 -3
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +7 -9
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +1 -7
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +7 -9
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +7 -9
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +7 -9
- package/tiledeskChatbotPlugs/directives/DirReply.js +9 -16
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +8 -10
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +7 -9
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +7 -2
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +7 -1
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +2 -8
- package/tiledeskChatbotPlugs/directives/DirWait.js +6 -1
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +20 -5
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +8 -40
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +7 -1
- package/tiledeskChatbotPlugs/directives/Directives.js +1 -0
- package/utils/TiledeskChatbotUtil.js +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
|
|
2
|
+
const { Logger } = require('../../Logger');
|
|
2
3
|
const { TiledeskChatbotUtil } = require('../../utils/TiledeskChatbotUtil');
|
|
3
4
|
|
|
4
5
|
class DirClearTranscript {
|
|
@@ -9,10 +10,14 @@ class DirClearTranscript {
|
|
|
9
10
|
}
|
|
10
11
|
this.context = context;
|
|
11
12
|
this.requestId = context.requestId;
|
|
13
|
+
|
|
14
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
execute(directive, callback) {
|
|
18
|
+
this.logger.info("[Clear Transcript] Executing action");
|
|
15
19
|
TiledeskChatbotUtil.clearConversationTranscript(this.context.chatbot, () => {
|
|
20
|
+
this.logger.info("[Clear Transcript] Action completed");
|
|
16
21
|
callback();
|
|
17
22
|
});
|
|
18
23
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const { TiledeskClient } = require("@tiledesk/tiledesk-client");
|
|
3
3
|
const { TiledeskChatbotConst } = require("../../engine/TiledeskChatbotConst");
|
|
4
4
|
const winston = require('../../utils/winston');
|
|
5
|
+
const { Logger } = require("../../Logger");
|
|
5
6
|
|
|
6
7
|
class DirClose {
|
|
7
8
|
|
|
@@ -13,26 +14,24 @@ class DirClose {
|
|
|
13
14
|
this.requestId = context.requestId;
|
|
14
15
|
this.chatbot = context.chatbot;
|
|
15
16
|
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.tdClient = new TiledeskClient({
|
|
19
|
-
projectId: this.context.projectId,
|
|
20
|
-
token: this.context.token,
|
|
21
|
-
APIURL: this.API_ENDPOINT,
|
|
22
|
-
APIKEY: "___",
|
|
23
|
-
log: this.log
|
|
24
|
-
});
|
|
17
|
+
|
|
18
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
|
|
19
|
+
this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___" });
|
|
25
20
|
}
|
|
26
21
|
|
|
27
22
|
execute(directive, callback) {
|
|
23
|
+
this.logger.info("[Close] Executing action");
|
|
28
24
|
winston.verbose("Execute Close directive");
|
|
29
25
|
this.tdClient.closeRequest(this.requestId, async (err) => {
|
|
30
26
|
if (err) {
|
|
27
|
+
this.logger.error("[Close] Closing request");
|
|
31
28
|
winston.error("(DirClose) Error: ", err);
|
|
32
29
|
}
|
|
33
30
|
else {
|
|
31
|
+
this.logger.verbose("[Close] Request closed");
|
|
34
32
|
await this.chatbot.deleteParameter(TiledeskChatbotConst.USER_INPUT);
|
|
35
33
|
}
|
|
34
|
+
this.logger.info("[Close] Action completed");
|
|
36
35
|
callback();
|
|
37
36
|
});
|
|
38
37
|
}
|
|
@@ -2,6 +2,7 @@ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
|
2
2
|
const { TiledeskExpression } = require('../../TiledeskExpression');
|
|
3
3
|
const { TiledeskRequestVariables } = require('../TiledeskRequestVariables');
|
|
4
4
|
const winston = require('../../utils/winston');
|
|
5
|
+
const { Logger } = require('../../Logger');
|
|
5
6
|
|
|
6
7
|
class DirCode {
|
|
7
8
|
|
|
@@ -10,21 +11,26 @@ class DirCode {
|
|
|
10
11
|
throw new Error('context object is mandatory.');
|
|
11
12
|
}
|
|
12
13
|
this.context = context;
|
|
13
|
-
this.
|
|
14
|
+
this.requestId = this.context.requestId;
|
|
15
|
+
|
|
16
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
execute(directive, callback) {
|
|
20
|
+
this.logger.info("[Code] Executing action");
|
|
17
21
|
winston.verbose("Execute Code directive");
|
|
18
22
|
let action;
|
|
19
23
|
if (directive.action) {
|
|
20
24
|
action = directive.action
|
|
21
25
|
}
|
|
22
26
|
else {
|
|
27
|
+
this.logger.error("Incorrect action for ", directive.name, directive)
|
|
23
28
|
winston.warn("DirCode Incorrect directive: ", directive);
|
|
24
29
|
callback();
|
|
25
30
|
return;
|
|
26
31
|
}
|
|
27
32
|
this.go(action, (stop) => {
|
|
33
|
+
this.logger.info("[Code] Action completed");
|
|
28
34
|
callback(stop);
|
|
29
35
|
});
|
|
30
36
|
|
|
@@ -34,6 +40,7 @@ class DirCode {
|
|
|
34
40
|
winston.debug("(DirCode) Action: ", action);
|
|
35
41
|
const source_code = action.source;
|
|
36
42
|
if (!source_code || source_code.trim() === "") {
|
|
43
|
+
this.logger.warn("[Code] Invalid source_code");
|
|
37
44
|
winston.error("(DirCode) Invalid source_code");
|
|
38
45
|
callback();
|
|
39
46
|
return;
|
|
@@ -74,6 +81,7 @@ class DirCode {
|
|
|
74
81
|
|
|
75
82
|
}
|
|
76
83
|
catch(err) {
|
|
84
|
+
this.logger.error("[Code] An error occurred: ", err);
|
|
77
85
|
winston.error("(DirCode) An error occurred: ", err);
|
|
78
86
|
}
|
|
79
87
|
callback();
|
|
@@ -3,6 +3,7 @@ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
|
3
3
|
const { TiledeskExpression } = require('../../TiledeskExpression');
|
|
4
4
|
const ms = require('minimist-string');
|
|
5
5
|
const winston = require('../../utils/winston');
|
|
6
|
+
const { Logger } = require('../../Logger');
|
|
6
7
|
|
|
7
8
|
class DirCondition {
|
|
8
9
|
|
|
@@ -11,11 +12,14 @@ class DirCondition {
|
|
|
11
12
|
throw new Error('context object is mandatory.');
|
|
12
13
|
}
|
|
13
14
|
this.context = context;
|
|
15
|
+
this.requestId = this.context.requestId;
|
|
16
|
+
|
|
14
17
|
this.intentDir = new DirIntent(context);
|
|
15
|
-
this.
|
|
18
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
execute(directive, callback) {
|
|
22
|
+
this.logger.info("[Condition] Executing action");
|
|
19
23
|
winston.verbose("Execute Condition directive");
|
|
20
24
|
let action;
|
|
21
25
|
if (directive.action) {
|
|
@@ -35,11 +39,13 @@ class DirCondition {
|
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
else {
|
|
42
|
+
this.logger.error("Incorrect action for ", directive.name, directive)
|
|
38
43
|
winston.warn("DirCondition Incorrect directive: ", directive);
|
|
39
44
|
callback();
|
|
40
45
|
return;
|
|
41
46
|
}
|
|
42
47
|
this.go(action, (stop) => {
|
|
48
|
+
this.logger.info("[Condition] Action completed");
|
|
43
49
|
callback(stop);
|
|
44
50
|
});
|
|
45
51
|
|
|
@@ -64,21 +70,25 @@ class DirCondition {
|
|
|
64
70
|
}
|
|
65
71
|
winston.debug("(DirCondition) condition action: ", action);
|
|
66
72
|
if (!trueIntent && !falseIntent) {
|
|
73
|
+
this.logger.error("[Condition] Invalid condition, no intents specified");
|
|
67
74
|
winston.error("(DirCondition) Invalid condition, no intents specified");
|
|
68
75
|
callback();
|
|
69
76
|
return;
|
|
70
77
|
}
|
|
71
78
|
if (scriptCondition === null && jsonCondition === null) {
|
|
79
|
+
this.logger.error("[Condition] Invalid condition, scriptCondition & jsonCondition null");
|
|
72
80
|
winston.error("(DirCondition) Invalid condition, scriptCondition & jsonCondition null");
|
|
73
81
|
callback();
|
|
74
82
|
return;
|
|
75
83
|
}
|
|
76
84
|
if (scriptCondition !== null && scriptCondition.trim === "") {
|
|
85
|
+
this.logger.error("[Condition] Invalid condition, scriptCondition is empty");
|
|
77
86
|
winston.error("(DirCondition) Invalid condition, scriptCondition is empty");
|
|
78
87
|
callback();
|
|
79
88
|
return;
|
|
80
89
|
}
|
|
81
90
|
else if (jsonCondition && jsonCondition.groups === null) {
|
|
91
|
+
this.logger.error("[Condition] Invalid jsonCondition, no groups");
|
|
82
92
|
winston.error("(DirCondition) Invalid jsonCondition, no groups:", jsonCondition);
|
|
83
93
|
callback();
|
|
84
94
|
return;
|
|
@@ -121,6 +131,7 @@ class DirCondition {
|
|
|
121
131
|
});
|
|
122
132
|
}
|
|
123
133
|
else {
|
|
134
|
+
this.logger.debug("[Condition] No trueIntentDirective specified");
|
|
124
135
|
winston.debug("(DirCondition) No trueIntentDirective specified");
|
|
125
136
|
callback();
|
|
126
137
|
return;
|
|
@@ -133,6 +144,7 @@ class DirCondition {
|
|
|
133
144
|
});
|
|
134
145
|
}
|
|
135
146
|
else {
|
|
147
|
+
this.logger.debug("[Condition] No falseIntentDirective specified");
|
|
136
148
|
winston.debug("(DirCondition) No falseIntentDirective specified");
|
|
137
149
|
callback();
|
|
138
150
|
return;
|
|
@@ -5,6 +5,7 @@ let axios = require('axios');
|
|
|
5
5
|
const { TiledeskChatbotConst } = require('../../engine/TiledeskChatbotConst');
|
|
6
6
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
7
7
|
const winston = require('../../utils/winston');
|
|
8
|
+
const { Logger } = require('../../Logger');
|
|
8
9
|
|
|
9
10
|
class DirContactUpdate {
|
|
10
11
|
|
|
@@ -19,18 +20,13 @@ class DirContactUpdate {
|
|
|
19
20
|
this.token = context.token;
|
|
20
21
|
this.tdcache = context.tdcache;
|
|
21
22
|
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.tdClient = new TiledeskClient({
|
|
25
|
-
projectId: this.context.projectId,
|
|
26
|
-
token: this.context.token,
|
|
27
|
-
APIURL: this.API_ENDPOINT,
|
|
28
|
-
APIKEY: "___",
|
|
29
|
-
log: this.log
|
|
30
|
-
});
|
|
23
|
+
|
|
24
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
|
|
25
|
+
this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___" });
|
|
31
26
|
}
|
|
32
27
|
|
|
33
28
|
execute(directive, callback) {
|
|
29
|
+
this.logger.info("[Lead Update] Executing action");
|
|
34
30
|
winston.verbose("Execute ContactUpdate directive")
|
|
35
31
|
let action;
|
|
36
32
|
if (directive.action) {
|
|
@@ -41,11 +37,13 @@ class DirContactUpdate {
|
|
|
41
37
|
action.attributes.fillParams = true;
|
|
42
38
|
}
|
|
43
39
|
else {
|
|
40
|
+
this.logger.error("Incorrect action for ", directive.name, directive)
|
|
44
41
|
winston.warn("DirContactUpdate Incorrect directive: ", directive);
|
|
45
42
|
callback();
|
|
46
43
|
return;
|
|
47
44
|
}
|
|
48
45
|
this.go(action, () => {
|
|
46
|
+
this.logger.info("[Lead Update] Action completed");
|
|
49
47
|
callback();
|
|
50
48
|
});
|
|
51
49
|
}
|
|
@@ -6,6 +6,7 @@ let https = require("https");
|
|
|
6
6
|
require('dotenv').config();
|
|
7
7
|
const winston = require('../../utils/winston');
|
|
8
8
|
const integrationService = require("../../services/IntegrationService");
|
|
9
|
+
const { Logger } = require("../../Logger");
|
|
9
10
|
|
|
10
11
|
class DirCustomerio {
|
|
11
12
|
|
|
@@ -18,23 +19,27 @@ class DirCustomerio {
|
|
|
18
19
|
this.requestId = this.context.requestId;
|
|
19
20
|
this.projectId = this.context.projectId;
|
|
20
21
|
this.token = this.context.token;
|
|
21
|
-
this.intentDir = new DirIntent(context);
|
|
22
22
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
23
|
-
|
|
23
|
+
|
|
24
|
+
this.intentDir = new DirIntent(context);
|
|
25
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
execute(directive, callback) {
|
|
29
|
+
this.logger.info("[Customer.io] Executing action");
|
|
27
30
|
winston.verbose("Execute Customerio directive");
|
|
28
31
|
let action;
|
|
29
32
|
if (directive.action) {
|
|
30
33
|
action = directive.action;
|
|
31
34
|
}
|
|
32
35
|
else {
|
|
36
|
+
this.logger.error("Incorrect action for ", directive.name, directive)
|
|
33
37
|
winston.warn("DirCustomerio Incorrect directive: ", directive);
|
|
34
38
|
callback();
|
|
35
39
|
return;
|
|
36
40
|
}
|
|
37
41
|
this.go(action, (stop) => {
|
|
42
|
+
this.logger.info("[Customer.io] Action completed");
|
|
38
43
|
callback(stop);
|
|
39
44
|
})
|
|
40
45
|
}
|
|
@@ -66,6 +71,7 @@ class DirCustomerio {
|
|
|
66
71
|
winston.debug("(DirCustomerio) bodyParameters: ", bodyParameters);
|
|
67
72
|
|
|
68
73
|
if (!bodyParameters || bodyParameters === '') {
|
|
74
|
+
this.logger.error("[Customer.io] bodyParameters is undefined or null or empty string");
|
|
69
75
|
winston.debug("(DirCustomerio) Error: bodyParameters is undefined or null or empty string");
|
|
70
76
|
callback();
|
|
71
77
|
return;
|
|
@@ -76,6 +82,7 @@ class DirCustomerio {
|
|
|
76
82
|
|
|
77
83
|
let key = await integrationService.getKeyFromIntegrations(this.projectId, 'customerio', this.token);
|
|
78
84
|
if (!key) {
|
|
85
|
+
this.logger.error("[Customer.io] Key not found in Integrations");
|
|
79
86
|
winston.debug("(DirCustomerio) - Key not found in Integrations.");
|
|
80
87
|
let status = 422;
|
|
81
88
|
let error = 'Missing customerio access token';
|
|
@@ -117,6 +124,7 @@ class DirCustomerio {
|
|
|
117
124
|
CUSTOMERIO_HTTPREQUEST, async (err, resbody) => {
|
|
118
125
|
if (err) {
|
|
119
126
|
if (callback) {
|
|
127
|
+
this.logger.error("[Customer.io] Error response: ", err.response);
|
|
120
128
|
winston.debug("(DirCustomerio) err response:", err.response)
|
|
121
129
|
winston.debug("(DirCustomerio) err data:", err.response.data)
|
|
122
130
|
|
|
@@ -151,6 +159,7 @@ class DirCustomerio {
|
|
|
151
159
|
|
|
152
160
|
let status = 204;
|
|
153
161
|
let error = null;
|
|
162
|
+
this.logger.error("[Customer.io] Response status: ", status);
|
|
154
163
|
await this.#assignAttributes(action, status, error);
|
|
155
164
|
if (trueIntent) {
|
|
156
165
|
await this.#executeCondition(true, trueIntent, null, falseIntent, null);
|
|
@@ -15,13 +15,7 @@ class DirDeflectToHelpCenter {
|
|
|
15
15
|
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
16
16
|
this.log = context.log;
|
|
17
17
|
|
|
18
|
-
this.tdClient = new TiledeskClient({
|
|
19
|
-
projectId: this.context.projectId,
|
|
20
|
-
token: this.context.token,
|
|
21
|
-
APIURL: this.API_ENDPOINT,
|
|
22
|
-
APIKEY: "___",
|
|
23
|
-
log: this.log
|
|
24
|
-
});
|
|
18
|
+
this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___", log: this.log });
|
|
25
19
|
}
|
|
26
20
|
|
|
27
21
|
async execute(directive, callback) {
|
|
@@ -3,6 +3,7 @@ const ms = require('minimist-string');
|
|
|
3
3
|
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
4
4
|
const { Filler } = require('../Filler');
|
|
5
5
|
const winston = require('../../utils/winston');
|
|
6
|
+
const { Logger } = require('../../Logger');
|
|
6
7
|
|
|
7
8
|
class DirDeleteVariable {
|
|
8
9
|
|
|
@@ -11,10 +12,13 @@ class DirDeleteVariable {
|
|
|
11
12
|
throw new Error('context object is mandatory.');
|
|
12
13
|
}
|
|
13
14
|
this.context = context;
|
|
14
|
-
this.
|
|
15
|
+
this.requestId = this.context.requestId;
|
|
16
|
+
|
|
17
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
async execute(directive, callback) {
|
|
21
|
+
this.logger.info("[Delete Attribute] Executing action");
|
|
18
22
|
winston.verbose("Execute DeleteVariable directive");
|
|
19
23
|
let action;
|
|
20
24
|
if (directive.action) {
|
|
@@ -25,7 +29,14 @@ class DirDeleteVariable {
|
|
|
25
29
|
variableName: directive.parameter
|
|
26
30
|
}
|
|
27
31
|
}
|
|
32
|
+
else {
|
|
33
|
+
this.logger.error("Incorrect action for ", directive.name, directive)
|
|
34
|
+
winston.warn("(DirDeleteVariable) Incorrect directive: ", directive);
|
|
35
|
+
callback();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
28
38
|
this.go(action, () => {
|
|
39
|
+
this.logger.info("[Delete Attribute] Action completed");
|
|
29
40
|
callback();
|
|
30
41
|
});
|
|
31
42
|
}
|
|
@@ -35,6 +46,7 @@ class DirDeleteVariable {
|
|
|
35
46
|
|
|
36
47
|
let variableName = action.variableName;
|
|
37
48
|
if (!variableName) {
|
|
49
|
+
this.logger.warn("[Delete Attribute] Missing 'variableName'. Skip")
|
|
38
50
|
winston.error("(DirDeleteVariable) deleting variable. Missing 'variableName' error. Skipping");
|
|
39
51
|
if (callback) {
|
|
40
52
|
callback();
|
|
@@ -60,6 +72,7 @@ class DirDeleteVariable {
|
|
|
60
72
|
}
|
|
61
73
|
}
|
|
62
74
|
catch(err) {
|
|
75
|
+
this.logger.error("[Delete Attribute] Error deleting attribute");
|
|
63
76
|
winston.error("(DirDeleteVariable) error: ", err);
|
|
64
77
|
if (completion) {
|
|
65
78
|
completion();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { TiledeskClient } = require("@tiledesk/tiledesk-client");
|
|
2
2
|
const winston = require('../../utils/winston');
|
|
3
|
+
const { Logger } = require("../../Logger");
|
|
3
4
|
|
|
4
5
|
class DirDepartment {
|
|
5
6
|
|
|
@@ -11,17 +12,13 @@ class DirDepartment {
|
|
|
11
12
|
this.requestId = context.requestId;
|
|
12
13
|
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
13
14
|
this.log = context.log;
|
|
14
|
-
|
|
15
|
-
this.
|
|
16
|
-
|
|
17
|
-
token: this.context.token,
|
|
18
|
-
APIURL: this.API_ENDPOINT,
|
|
19
|
-
APIKEY: "___",
|
|
20
|
-
log: this.log
|
|
21
|
-
});
|
|
15
|
+
|
|
16
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
|
|
17
|
+
this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___" });
|
|
22
18
|
}
|
|
23
19
|
|
|
24
20
|
execute(directive, callback) {
|
|
21
|
+
this.logger.info("[Change Department] Executing action");
|
|
25
22
|
winston.verbose("Execute Department directive");
|
|
26
23
|
let action;
|
|
27
24
|
if (directive.action) {
|
|
@@ -37,6 +34,7 @@ class DirDepartment {
|
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
36
|
this.go(action, () => {
|
|
37
|
+
this.logger.info("[Change Department] Action executed");
|
|
40
38
|
callback();
|
|
41
39
|
});
|
|
42
40
|
|
|
@@ -66,6 +64,7 @@ class DirDepartment {
|
|
|
66
64
|
const depName = action.depName;
|
|
67
65
|
this.moveToDepartment(this.requestId, depName, (deps) => {
|
|
68
66
|
if (!deps) {
|
|
67
|
+
this.logger.warn("[Change Department] Department not found");
|
|
69
68
|
winston.warn("(DirDepartment) Dep not found");
|
|
70
69
|
callback();
|
|
71
70
|
return
|
|
@@ -94,14 +93,19 @@ class DirDepartment {
|
|
|
94
93
|
this.requestId,
|
|
95
94
|
message, (err) => {
|
|
96
95
|
if (err) {
|
|
96
|
+
this.logger.error("[Change Department] Unable to trigger bot");
|
|
97
97
|
winston.error("(DirDepartment) Error sending hidden message: " + err.message)
|
|
98
|
+
} else {
|
|
99
|
+
this.logger.verbose("[Change Department] Bot triggered");
|
|
100
|
+
winston.debug("(DirDepartment) Hidden message sent.");
|
|
101
|
+
|
|
98
102
|
}
|
|
99
|
-
winston.debug("(DirDepartment) Hidden message sent.");
|
|
100
103
|
callback();
|
|
101
104
|
});
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
107
|
else {
|
|
108
|
+
this.logger.verbose("[Change Department] No triggering bot");
|
|
105
109
|
winston.debug("(DirDepartment) No action.triggerBot");
|
|
106
110
|
callback();
|
|
107
111
|
}
|
|
@@ -11,15 +11,9 @@ class DirFireTiledeskEvent {
|
|
|
11
11
|
|
|
12
12
|
this.context = context;
|
|
13
13
|
this.log = context.log;
|
|
14
|
-
|
|
15
14
|
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
token: this.context.token,
|
|
19
|
-
APIURL: this.API_ENDPOINT,
|
|
20
|
-
APIKEY: "___",
|
|
21
|
-
log: this.log
|
|
22
|
-
});
|
|
15
|
+
|
|
16
|
+
this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___", log: this.log });
|
|
23
17
|
}
|
|
24
18
|
|
|
25
19
|
execute(directive, callback) {
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
const { Logger } = require('../../Logger');
|
|
4
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
5
|
+
const { Filler } = require('../Filler');
|
|
6
|
+
const winston = require('../../utils/winston');
|
|
7
|
+
|
|
8
|
+
let levels = ['error', 'warn', 'info', 'debug'];
|
|
9
|
+
|
|
10
|
+
class DirFlowLog {
|
|
11
|
+
|
|
12
|
+
constructor(context) {
|
|
13
|
+
if (!context) {
|
|
14
|
+
throw new Error('context object is mandatory.');
|
|
15
|
+
}
|
|
16
|
+
this.context = context;
|
|
17
|
+
this.chatbot = context.chatbot;
|
|
18
|
+
this.tdcache = context.tdcache;
|
|
19
|
+
this.requestId = context.requestId;
|
|
20
|
+
this.log = context.log;
|
|
21
|
+
|
|
22
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest.draft });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
execute(directive, callback) {
|
|
26
|
+
winston.verbose("Execute FlowLog directive");
|
|
27
|
+
let action;
|
|
28
|
+
if (directive.action) {
|
|
29
|
+
action = directive.action;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
winston.warn("DirGptTask Incorrect directive: ", directive);
|
|
33
|
+
callback();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
this.go(action, () => {
|
|
38
|
+
callback();
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async go(action, callback) {
|
|
43
|
+
winston.debug("(DirFlowLog) Action: ", action);
|
|
44
|
+
|
|
45
|
+
let level = action.level || 'info';
|
|
46
|
+
if (!levels.includes(level)) {
|
|
47
|
+
winston.warn("Invalid log level " + level);
|
|
48
|
+
this.logger.error("Invalid log level: " + level);
|
|
49
|
+
callback();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!action.log) {
|
|
53
|
+
winston.debug("Log text is empty");
|
|
54
|
+
callback();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let requestVariables = null;
|
|
58
|
+
requestVariables =
|
|
59
|
+
await TiledeskChatbot.allParametersStatic(
|
|
60
|
+
this.tdcache, this.requestId
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const filler = new Filler();
|
|
64
|
+
const filled_log = filler.fill(action.log, requestVariables);
|
|
65
|
+
winston.debug("(DirFlowLog) fille log: ", filled_log);
|
|
66
|
+
|
|
67
|
+
if (level === 'error') {
|
|
68
|
+
winston.info("Adding log '" + filled_log + "' with level " + level);
|
|
69
|
+
this.logger.error(filled_log);
|
|
70
|
+
}
|
|
71
|
+
else if (level === 'warn') {
|
|
72
|
+
winston.info("Adding log '" + filled_log + "' with level " + level);
|
|
73
|
+
this.logger.warn(filled_log);
|
|
74
|
+
}
|
|
75
|
+
else if (level === 'info') {
|
|
76
|
+
winston.info("Adding log '" + filled_log + "' with level " + level);
|
|
77
|
+
this.logger.info(filled_log);
|
|
78
|
+
}
|
|
79
|
+
else if (level === 'debug') {
|
|
80
|
+
winston.info("Adding log '" + filled_log + "' with level " + level);
|
|
81
|
+
this.logger.debug(filled_log);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
callback();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = { DirFlowLog };
|
|
@@ -14,18 +14,11 @@ class DirForm {
|
|
|
14
14
|
this.chatbot = context.chatbot;
|
|
15
15
|
this.tdcache = context.tdcache;
|
|
16
16
|
this.requestId = context.requestId;
|
|
17
|
-
this.intentDir = new DirIntent(context);
|
|
18
17
|
this.log = context.log;
|
|
19
|
-
|
|
20
18
|
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
APIURL: this.API_ENDPOINT,
|
|
25
|
-
APIKEY: "___",
|
|
26
|
-
log: this.log
|
|
27
|
-
});
|
|
28
|
-
|
|
19
|
+
|
|
20
|
+
this.intentDir = new DirIntent(context);
|
|
21
|
+
this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___", log: this.log });
|
|
29
22
|
}
|
|
30
23
|
|
|
31
24
|
execute(directive, callback) {
|
|
@@ -9,6 +9,7 @@ require('dotenv').config();
|
|
|
9
9
|
const winston = require('../../utils/winston');
|
|
10
10
|
const httpUtils = require("../../utils/HttpUtils");
|
|
11
11
|
const integrationService = require("../../services/IntegrationService");
|
|
12
|
+
const { Logger } = require("../../Logger");
|
|
12
13
|
|
|
13
14
|
class DirGptTask {
|
|
14
15
|
|
|
@@ -22,23 +23,27 @@ class DirGptTask {
|
|
|
22
23
|
this.requestId = this.context.requestId;
|
|
23
24
|
this.projectId = this.context.projectId;
|
|
24
25
|
this.token = this.context.token;
|
|
25
|
-
this.intentDir = new DirIntent(context);
|
|
26
26
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
27
|
-
|
|
27
|
+
|
|
28
|
+
this.intentDir = new DirIntent(context);
|
|
29
|
+
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
execute(directive, callback) {
|
|
33
|
+
this.logger.info("[ChatGPT Task] Executing action");
|
|
31
34
|
winston.verbose("Execute GptTask directive");
|
|
32
35
|
let action;
|
|
33
36
|
if (directive.action) {
|
|
34
37
|
action = directive.action;
|
|
35
38
|
}
|
|
36
39
|
else {
|
|
40
|
+
this.logger.error("Incorrect action for ", directive.name, directive)
|
|
37
41
|
winston.warn("DirGptTask Incorrect directive: ", directive);
|
|
38
42
|
callback();
|
|
39
43
|
return;
|
|
40
44
|
}
|
|
41
45
|
this.go(action, (stop) => {
|
|
46
|
+
this.logger.info("[ChatGPT Task] Action completed");
|
|
42
47
|
callback(stop);
|
|
43
48
|
})
|
|
44
49
|
}
|
|
@@ -68,6 +73,7 @@ class DirGptTask {
|
|
|
68
73
|
let model = "gpt-3.5-turbo";
|
|
69
74
|
|
|
70
75
|
if (!action.question || action.question === '') {
|
|
76
|
+
this.logger.warn("[ChatGPT Task] question attribute is mandatory");
|
|
71
77
|
winston.debug("(DirGptTask) Error: question attribute is mandatory. Executing condition false...")
|
|
72
78
|
if (falseIntent) {
|
|
73
79
|
await this.chatbot.addParameter("flowError", "GPT Error: question attribute is undefined");
|
|
@@ -104,13 +110,13 @@ class DirGptTask {
|
|
|
104
110
|
this.context.tdcache,
|
|
105
111
|
this.context.requestId,
|
|
106
112
|
TiledeskChatbotConst.REQ_TRANSCRIPT_KEY);
|
|
107
|
-
winston.debug("(DirGptTask)
|
|
113
|
+
winston.debug("(DirGptTask) transcript string: " + transcript_string)
|
|
108
114
|
|
|
109
115
|
if (transcript_string) {
|
|
110
116
|
transcript = await TiledeskChatbotUtil.transcriptJSON(transcript_string);
|
|
111
|
-
winston.debug("(DirGptTask)
|
|
117
|
+
winston.debug("(DirGptTask) transcript: ", transcript)
|
|
112
118
|
} else {
|
|
113
|
-
winston.debug("(DirGptTask)
|
|
119
|
+
winston.debug("(DirGptTask) transcript_string is undefined. Skip JSON translation for chat history");
|
|
114
120
|
}
|
|
115
121
|
}
|
|
116
122
|
|
|
@@ -119,17 +125,20 @@ class DirGptTask {
|
|
|
119
125
|
|
|
120
126
|
let key = await integrationService.getKeyFromIntegrations(this.projectId, 'openai', this.token);
|
|
121
127
|
if (!key) {
|
|
128
|
+
this.logger.debug("[ChatGPT Task] Key not found in Integrations.");
|
|
122
129
|
winston.debug("(DirGptTask) - Key not found in Integrations. Searching in kb settings...");
|
|
123
130
|
key = await this.getKeyFromKbSettings();
|
|
124
131
|
}
|
|
125
132
|
|
|
126
133
|
if (!key) {
|
|
127
|
-
|
|
134
|
+
this.logger.debug("[ChatGPT Task] Retrieve shared gptkey.");
|
|
135
|
+
winston.debug("(DirGptTask) - Retrieve public gptkey")
|
|
128
136
|
key = process.env.GPTKEY;
|
|
129
137
|
publicKey = true;
|
|
130
138
|
}
|
|
131
139
|
|
|
132
140
|
if (!key) {
|
|
141
|
+
this.logger.error("[ChatGPT Task] OpenAI key is mandatory");
|
|
133
142
|
winston.error("(DirGptTask) gptkey is mandatory");
|
|
134
143
|
await this.#assignAttributes(action, answer);
|
|
135
144
|
if (falseIntent) {
|
|
@@ -145,7 +154,7 @@ class DirGptTask {
|
|
|
145
154
|
if (publicKey === true) {
|
|
146
155
|
let keep_going = await this.checkQuoteAvailability();
|
|
147
156
|
if (keep_going === false) {
|
|
148
|
-
|
|
157
|
+
this.logger.warn("[ChatGPT Task] OpenAI tokens quota exceeded");
|
|
149
158
|
await this.chatbot.addParameter("flowError", "GPT Error: tokens quota exceeded");
|
|
150
159
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
151
160
|
callback();
|
|
@@ -202,6 +211,7 @@ class DirGptTask {
|
|
|
202
211
|
if (err) {
|
|
203
212
|
winston.debug("(DirGptTask) openai err: ", err);
|
|
204
213
|
winston.debug("(DirGptTask) openai err: " + err.response?.data?.error?.message);
|
|
214
|
+
this.logger.error("[ChatGPT Task] Completions error: ", err.response?.data?.error?.message);
|
|
205
215
|
await this.#assignAttributes(action, answer);
|
|
206
216
|
if (falseIntent) {
|
|
207
217
|
await this.chatbot.addParameter("flowError", "GPT Error: " + err.response?.data?.error?.message);
|
|
@@ -219,6 +229,8 @@ class DirGptTask {
|
|
|
219
229
|
answer = await this.convertToJson(answer);
|
|
220
230
|
}
|
|
221
231
|
|
|
232
|
+
this.logger.debug("[ChatGPT Task] Completions answer: ", answer);
|
|
233
|
+
|
|
222
234
|
await this.#assignAttributes(action, answer);
|
|
223
235
|
|
|
224
236
|
if (publicKey === true) {
|