@tiledesk/tiledesk-tybot-connector 0.5.0 → 2.0.0
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/ExtApi.js +4 -83
- package/ExtUtil.js +0 -1
- package/Logger.js +105 -0
- package/TdCache.js +5 -3
- package/TiledeskClientTest.js +5 -28
- package/TiledeskExpression.js +6 -47
- package/{models → engine}/IntentForm.js +30 -44
- package/{models → engine}/IntentsMachineFactory.js +5 -4
- package/{models → engine}/MongodbBotsDataSource.js +31 -55
- package/{models → engine}/MongodbIntentsMachine.js +6 -5
- package/{models → engine}/TiledeskChatbot.js +82 -259
- package/{models → engine}/TiledeskChatbotConst.js +9 -0
- package/{models → engine}/TiledeskIntentsMachine.js +5 -15
- package/{models → engine/mock}/MockBotsDataSource.js +3 -19
- package/{models → engine/mock}/MockTdCache.js +0 -9
- package/index.js +103 -380
- package/logs/app.log +12723 -277
- package/logs/app1.log +62258 -0
- package/logs/app2.log +46280 -0
- package/logs/app3.log +31686 -0
- package/logs/app4.log +46163 -0
- package/logs/app5.log +33173 -0
- package/models/faq.js +2 -5
- package/package.json +5 -2
- package/{TiledeskServices → services}/AIService.js +4 -3
- package/{models/faqKbService.js → services/FaqKbService.js} +1 -2
- package/{models/faqService.js → services/FaqService.js} +4 -3
- package/services/IntegrationService.js +43 -0
- package/services/TilebotService.js +47 -0
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +49 -135
- package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +8 -14
- package/tiledeskChatbotPlugs/Filler.js +0 -1
- package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +12 -20
- package/tiledeskChatbotPlugs/MessagePipeline.js +5 -15
- package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +4 -13
- package/tiledeskChatbotPlugs/TiledeskRequestVariables.js +1 -1
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +21 -89
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirSetAttribute.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +23 -140
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +42 -128
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +37 -127
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +52 -145
- package/tiledeskChatbotPlugs/directives/DirAssign.js +12 -23
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +16 -12
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +56 -198
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +41 -101
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +9 -19
- package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirClose.js +4 -2
- package/tiledeskChatbotPlugs/directives/DirCode.js +16 -23
- package/tiledeskChatbotPlugs/directives/DirCondition.js +19 -25
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -82
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +10 -22
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +34 -89
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +17 -22
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +8 -8
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -12
- package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +2 -6
- package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -4
- package/tiledeskChatbotPlugs/directives/DirForm.js +17 -24
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +49 -139
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +8 -53
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +31 -91
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +24 -78
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -68
- package/tiledeskChatbotPlugs/directives/DirIntent.js +6 -100
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +15 -14
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
- package/tiledeskChatbotPlugs/directives/DirMake.js +21 -53
- package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +8 -87
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +6 -4
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +6 -4
- package/tiledeskChatbotPlugs/directives/DirQapla.js +26 -120
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +11 -19
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +5 -2
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +12 -58
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +11 -57
- package/tiledeskChatbotPlugs/directives/DirReply.js +36 -30
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +30 -72
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +9 -10
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +15 -40
- package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +8 -5
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +25 -113
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
- package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
- package/tiledeskChatbotPlugs/directives/DirWait.js +5 -6
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +14 -49
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +22 -77
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +11 -14
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +13 -42
- package/tiledeskChatbotPlugs/directives/Directives.js +0 -3
- package/utils/HttpUtils.js +128 -0
- package/{models → utils}/TiledeskChatbotUtil.js +164 -234
- package/utils/winston.js +42 -0
- package/TiledeskServices/utils.js +0 -99
- /package/{models → engine/mock}/MockIntentsMachine.js +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
let axios = require('axios');
|
|
2
2
|
let https = require("https");
|
|
3
3
|
const { Filler } = require('../Filler');
|
|
4
|
-
const { TiledeskChatbot } = require('../../
|
|
4
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
5
5
|
const { TiledeskJSONEval } = require('../../TiledeskJSONEval');
|
|
6
|
+
const winston = require('../../utils/winston');
|
|
6
7
|
|
|
7
8
|
class DirWebRequest {
|
|
8
9
|
constructor(context) {
|
|
@@ -16,12 +17,13 @@ class DirWebRequest {
|
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
execute(directive, callback) {
|
|
20
|
+
winston.verbose("Execute WebRequest directive");
|
|
19
21
|
let action;
|
|
20
22
|
if (directive.action) {
|
|
21
23
|
action = directive.action;
|
|
22
24
|
}
|
|
23
25
|
else {
|
|
24
|
-
|
|
26
|
+
winston.warn("DirWebRequest Incorrect directive: ", directive);
|
|
25
27
|
callback();
|
|
26
28
|
return;
|
|
27
29
|
}
|
|
@@ -31,7 +33,7 @@ class DirWebRequest {
|
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
async go(action, callback) {
|
|
34
|
-
|
|
36
|
+
winston.debug("(DirWebRequest) Action: ", action);
|
|
35
37
|
let requestVariables = null;
|
|
36
38
|
if (this.tdcache) {
|
|
37
39
|
requestVariables =
|
|
@@ -46,7 +48,6 @@ class DirWebRequest {
|
|
|
46
48
|
if (action.headersString) {
|
|
47
49
|
let headersDict = action.headersString
|
|
48
50
|
for (const [key, value] of Object.entries(headersDict)) {
|
|
49
|
-
if (this.log) {console.log("header:", key, "value:", value)}
|
|
50
51
|
let filled_value = filler.fill(value, requestVariables);
|
|
51
52
|
headers[key] = filled_value;
|
|
52
53
|
}
|
|
@@ -58,30 +59,29 @@ class DirWebRequest {
|
|
|
58
59
|
json = JSON.parse(jsonBody);
|
|
59
60
|
}
|
|
60
61
|
catch(err) {
|
|
61
|
-
|
|
62
|
+
winston.debug("(DirWebRequest) Error parsing webRequest jsonBody: ", jsonBody);
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
|
|
66
|
+
winston.verbose("(DirWebRequest) webRequest URL " + url);
|
|
66
67
|
const HTTPREQUEST = {
|
|
67
68
|
url: url,
|
|
68
69
|
headers: headers,
|
|
69
70
|
json: json,
|
|
70
71
|
method: action.method
|
|
71
72
|
};
|
|
72
|
-
|
|
73
|
+
winston.debug("(DirWebRequest) HttpRequest ", HTTPREQUEST);
|
|
73
74
|
this.myrequest(
|
|
74
75
|
HTTPREQUEST, async (err, resbody) => {
|
|
75
|
-
|
|
76
|
+
winston.debug("(DirWebRequest) resbody: ", resbody);
|
|
76
77
|
if (err) {
|
|
77
|
-
|
|
78
|
+
winston.error("(DirWebRequest) error:", err);
|
|
78
79
|
if (callback) {
|
|
79
80
|
callback();
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
else if (callback) {
|
|
83
84
|
if (action.assignTo && this.context.tdcache && resbody) { // DEPRECATED
|
|
84
|
-
if (this.log) {console.log("(webRequest) this.requestId:", this.context.requestId);}
|
|
85
85
|
let attributes =
|
|
86
86
|
await TiledeskChatbot.allParametersStatic(
|
|
87
87
|
this.context.tdcache, this.context.requestId);
|
|
@@ -89,18 +89,8 @@ class DirWebRequest {
|
|
|
89
89
|
let attributeValue;
|
|
90
90
|
const filler = new Filler();
|
|
91
91
|
attributeValue = filler.fill(resbody, attributes);
|
|
92
|
-
if (this.log) {console.log("(webRequest) Attributes:", JSON.stringify(attributes));}
|
|
93
92
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignTo, attributeValue);
|
|
94
|
-
if (this.log) {
|
|
95
|
-
console.log("(webRequest) Assigned:", action.assignTo, "=", attributeValue);
|
|
96
|
-
const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
|
|
97
|
-
for (const [key, value] of Object.entries(all_parameters)) {
|
|
98
|
-
const value_type = typeof value;
|
|
99
|
-
if (this.log) {console.log("(webRequest) request parameter:", key, "value:", value, "type:", value_type)}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
93
|
} else if (action.assignments && this.context.tdcache && resbody) {
|
|
103
|
-
if (this.log) {console.log("(webRequest) action.assignments for request:", this.context.requestId);}
|
|
104
94
|
let json_body;
|
|
105
95
|
if (typeof resbody === "string") {
|
|
106
96
|
json_body = {
|
|
@@ -110,35 +100,21 @@ class DirWebRequest {
|
|
|
110
100
|
else {
|
|
111
101
|
json_body = resbody
|
|
112
102
|
}
|
|
113
|
-
|
|
114
|
-
let attributes =
|
|
115
|
-
await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
|
|
116
|
-
if (this.log) {console.log("(webRequest) action.assignments attributes:", attributes);}
|
|
103
|
+
let attributes = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
|
|
117
104
|
const assignments = action.assignments;
|
|
118
|
-
if (this.log) {console.log("(webRequest) assignments:", assignments);}
|
|
119
105
|
for (const [attr_name, attr_eval_expression] of Object.entries(assignments)) {
|
|
120
|
-
if (this.log) {console.log("", attr_name, attr_eval_expression);}
|
|
121
106
|
let attributeValue;
|
|
122
107
|
try {
|
|
123
108
|
attributeValue = TiledeskJSONEval.eval(json_body, attr_eval_expression);
|
|
124
|
-
if (this.log) {console.log("(webRequest) Assigning to:", attr_name, "value:", attributeValue);}
|
|
125
109
|
}
|
|
126
110
|
catch(err) {
|
|
127
|
-
|
|
111
|
+
winston.error("(DirWebRequest) Error:", err);
|
|
128
112
|
}
|
|
129
113
|
try {
|
|
130
114
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, attr_name, attributeValue);
|
|
131
115
|
}
|
|
132
116
|
catch(err) {
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
if (this.log) {
|
|
137
|
-
console.log("(webRequest) All attributes:");
|
|
138
|
-
const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
|
|
139
|
-
for (const [key, value] of Object.entries(all_parameters)) {
|
|
140
|
-
const value_type = typeof value;
|
|
141
|
-
if (this.log) {console.log("(webRequest) request attribute:", key, "value:", value, "type:", value_type)}
|
|
117
|
+
winston.error("(DirWebRequest) Error: ", err);
|
|
142
118
|
}
|
|
143
119
|
}
|
|
144
120
|
}
|
|
@@ -149,10 +125,6 @@ class DirWebRequest {
|
|
|
149
125
|
}
|
|
150
126
|
|
|
151
127
|
myrequest(options, callback) {
|
|
152
|
-
if (this.log) {
|
|
153
|
-
console.log("API URL:", options.url);
|
|
154
|
-
console.log("** Options:", JSON.stringify(options));
|
|
155
|
-
}
|
|
156
128
|
let axios_options = {
|
|
157
129
|
url: options.url,
|
|
158
130
|
method: options.method,
|
|
@@ -162,9 +134,6 @@ class DirWebRequest {
|
|
|
162
134
|
if (options.json !== null) {
|
|
163
135
|
axios_options.data = options.json
|
|
164
136
|
}
|
|
165
|
-
if (this.log) {
|
|
166
|
-
console.log("axios_options:", JSON.stringify(axios_options));
|
|
167
|
-
}
|
|
168
137
|
if (options.url.startsWith("https:")) {
|
|
169
138
|
const httpsAgent = new https.Agent({
|
|
170
139
|
rejectUnauthorized: false,
|
|
@@ -173,10 +142,6 @@ class DirWebRequest {
|
|
|
173
142
|
}
|
|
174
143
|
axios(axios_options)
|
|
175
144
|
.then((res) => {
|
|
176
|
-
if (this.log) {
|
|
177
|
-
console.log("Response for url:", options.url);
|
|
178
|
-
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
179
|
-
}
|
|
180
145
|
if (res && res.status == 200 && res.data) {
|
|
181
146
|
if (callback) {
|
|
182
147
|
callback(null, res.data);
|
|
@@ -189,7 +154,7 @@ class DirWebRequest {
|
|
|
189
154
|
}
|
|
190
155
|
})
|
|
191
156
|
.catch( (error) => {
|
|
192
|
-
|
|
157
|
+
winston.error("(DirWebRequest) Axios error: ", error.response.data);
|
|
193
158
|
if (callback) {
|
|
194
159
|
callback(error, null);
|
|
195
160
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
let axios = require('axios');
|
|
2
2
|
let https = require("https");
|
|
3
3
|
const { Filler } = require('../Filler');
|
|
4
|
-
const { TiledeskChatbot } = require('../../
|
|
4
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
5
5
|
const { DirIntent } = require('./DirIntent');
|
|
6
|
+
const winston = require('../../utils/winston');
|
|
6
7
|
|
|
7
8
|
class DirWebRequestV2 {
|
|
8
9
|
|
|
@@ -19,12 +20,13 @@ class DirWebRequestV2 {
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
execute(directive, callback) {
|
|
23
|
+
winston.verbose("Execute WebRequestV2 directive");
|
|
22
24
|
let action;
|
|
23
25
|
if (directive.action) {
|
|
24
26
|
action = directive.action;
|
|
25
27
|
}
|
|
26
28
|
else {
|
|
27
|
-
|
|
29
|
+
winston.warn("DirWebRequestV2 Incorrect directive: ", directive);
|
|
28
30
|
callback();
|
|
29
31
|
return;
|
|
30
32
|
}
|
|
@@ -36,9 +38,9 @@ class DirWebRequestV2 {
|
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
async go(action, callback) {
|
|
39
|
-
|
|
41
|
+
winston.debug("DirWebRequestV2 action:", action);
|
|
40
42
|
if (!this.tdcache) {
|
|
41
|
-
|
|
43
|
+
winston.error("Error: DirWebRequestV2 tdcache is mandatory");
|
|
42
44
|
callback();
|
|
43
45
|
return;
|
|
44
46
|
}
|
|
@@ -48,12 +50,10 @@ class DirWebRequestV2 {
|
|
|
48
50
|
let trueIntentAttributes = action.trueIntentAttributes;
|
|
49
51
|
let falseIntentAttributes = action.falseIntentAttributes;
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
console.log("DirWebRequest falseIntentAttributes", falseIntentAttributes)
|
|
56
|
-
}
|
|
53
|
+
winston.debug("DirWebRequestV2 trueIntent " + trueIntent)
|
|
54
|
+
winston.debug("DirWebRequestV2 falseIntent " + falseIntent)
|
|
55
|
+
winston.debug("DirWebRequestV2 trueIntentAttributes " + trueIntentAttributes)
|
|
56
|
+
winston.debug("DirWebRequestV2 falseIntentAttributes " + falseIntentAttributes)
|
|
57
57
|
|
|
58
58
|
let requestAttributes = null;
|
|
59
59
|
requestAttributes =
|
|
@@ -88,7 +88,7 @@ class DirWebRequestV2 {
|
|
|
88
88
|
|
|
89
89
|
let timeout = this.#webrequest_timeout(action, 20000, 1, 300000);
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
winston.debug("DirWebRequestV2 webRequest URL " + url);
|
|
92
92
|
|
|
93
93
|
const HTTPREQUEST = {
|
|
94
94
|
url: url,
|
|
@@ -97,22 +97,19 @@ class DirWebRequestV2 {
|
|
|
97
97
|
method: action.method,
|
|
98
98
|
timeout: timeout
|
|
99
99
|
};
|
|
100
|
-
|
|
100
|
+
winston.debug("DirWebRequestV2 HttpRequest: ", HTTPREQUEST);
|
|
101
101
|
|
|
102
102
|
this.#myrequest(
|
|
103
103
|
HTTPREQUEST, async (err, res) => {
|
|
104
|
-
|
|
105
|
-
console.log("webRequest error:", err);
|
|
106
|
-
}
|
|
107
|
-
if (this.log) { console.log("DirWebRequest res:", res); }
|
|
104
|
+
|
|
108
105
|
let resbody = res.data;
|
|
109
106
|
let status = res.status;
|
|
110
107
|
let error = res.error;
|
|
111
108
|
await this.#assignAttributes(action, resbody, status, error)
|
|
112
|
-
|
|
109
|
+
winston.debug("DirWebRequestV2 resbody:", resbody);
|
|
113
110
|
|
|
114
111
|
if (err) {
|
|
115
|
-
|
|
112
|
+
winston.log("webRequest error: ", err);
|
|
116
113
|
if (callback) {
|
|
117
114
|
if (falseIntent) {
|
|
118
115
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -177,7 +174,7 @@ class DirWebRequestV2 {
|
|
|
177
174
|
resolve(json);
|
|
178
175
|
}
|
|
179
176
|
catch (err) {
|
|
180
|
-
|
|
177
|
+
winston.error("DirWebRequestV2 Error parsing webRequest jsonBody: " + JSON.stringify(jsonBody) + "\nError: " + JSON.stringify(err));
|
|
181
178
|
reject("Error parsing jsonBody");
|
|
182
179
|
}
|
|
183
180
|
}
|
|
@@ -210,7 +207,7 @@ class DirWebRequestV2 {
|
|
|
210
207
|
}
|
|
211
208
|
resolve(json);
|
|
212
209
|
} catch (err) {
|
|
213
|
-
|
|
210
|
+
winston.error("DirWebRequestV2 Error parsing webRequest formData: " + JSON.stringify(formData) + "\nError: " + JSON.stringify(err));
|
|
214
211
|
reject("Error parsing formData");
|
|
215
212
|
}
|
|
216
213
|
}
|
|
@@ -238,7 +235,7 @@ class DirWebRequestV2 {
|
|
|
238
235
|
});
|
|
239
236
|
}
|
|
240
237
|
else {
|
|
241
|
-
|
|
238
|
+
winston.debug("DirWebRequestV2 No trueIntentDirective specified");
|
|
242
239
|
if (callback) {
|
|
243
240
|
callback();
|
|
244
241
|
}
|
|
@@ -253,7 +250,7 @@ class DirWebRequestV2 {
|
|
|
253
250
|
});
|
|
254
251
|
}
|
|
255
252
|
else {
|
|
256
|
-
|
|
253
|
+
winston.debug("DirWebRequestV2 No falseIntentDirective specified");
|
|
257
254
|
if (callback) {
|
|
258
255
|
callback();
|
|
259
256
|
}
|
|
@@ -262,53 +259,22 @@ class DirWebRequestV2 {
|
|
|
262
259
|
}
|
|
263
260
|
|
|
264
261
|
async #assignAttributes(action, resbody, status, error) {
|
|
265
|
-
|
|
266
|
-
console.log("assignAttributes resbody:", resbody)
|
|
267
|
-
console.log("assignAttributes error:", error)
|
|
268
|
-
console.log("assignAttributes status:", status)
|
|
269
|
-
console.log("assignAttributes action:", action)
|
|
270
|
-
}
|
|
262
|
+
|
|
271
263
|
if (this.context.tdcache) {
|
|
272
264
|
if (action.assignResultTo && resbody) {
|
|
273
|
-
if (this.log) { console.log("assign assignResultTo:", resbody); }
|
|
274
265
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignResultTo, resbody);
|
|
275
266
|
}
|
|
276
267
|
if (action.assignErrorTo && error) {
|
|
277
|
-
if (this.log) { console.log("assign assignResultTo:", error); }
|
|
278
268
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignErrorTo, error);
|
|
279
269
|
}
|
|
280
270
|
if (action.assignStatusTo && status) {
|
|
281
|
-
if (this.log) { console.log("assign assignStatusTo:", status); }
|
|
282
271
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignStatusTo, status);
|
|
283
272
|
}
|
|
284
|
-
// Debug log
|
|
285
|
-
if (this.log) {
|
|
286
|
-
const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
|
|
287
|
-
for (const [key, value] of Object.entries(all_parameters)) {
|
|
288
|
-
if (this.log) { console.log("(webRequest) request parameter:", key, "value:", value, "type:", typeof value) }
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
273
|
}
|
|
292
274
|
}
|
|
293
275
|
|
|
294
276
|
#myrequest(options, callback) {
|
|
295
277
|
try {
|
|
296
|
-
if (this.log) {
|
|
297
|
-
console.log("API URL:", options.url);
|
|
298
|
-
//console.log("** Options:", JSON.stringify(options));
|
|
299
|
-
// Stringify "options". FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - START
|
|
300
|
-
let cache = [];
|
|
301
|
-
let str_Options = JSON.stringify(options, function (key, value) { // try to use a separate function
|
|
302
|
-
if (typeof value === 'object' && value != null) {
|
|
303
|
-
if (cache.indexOf(value) !== -1) {
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
cache.push(value);
|
|
307
|
-
}
|
|
308
|
-
return value;
|
|
309
|
-
});
|
|
310
|
-
console.log("** Options:", str_Options);
|
|
311
|
-
}
|
|
312
278
|
let axios_options = {
|
|
313
279
|
url: options.url,
|
|
314
280
|
method: options.method,
|
|
@@ -322,9 +288,6 @@ class DirWebRequestV2 {
|
|
|
322
288
|
if (options.json !== null) {
|
|
323
289
|
axios_options.data = options.json
|
|
324
290
|
}
|
|
325
|
-
// if (this.log) {
|
|
326
|
-
// console.log("axios_options:", JSON.stringify(axios_options));
|
|
327
|
-
// }
|
|
328
291
|
if (options.url.startsWith("https:")) {
|
|
329
292
|
const httpsAgent = new https.Agent({
|
|
330
293
|
rejectUnauthorized: false,
|
|
@@ -334,20 +297,12 @@ class DirWebRequestV2 {
|
|
|
334
297
|
|
|
335
298
|
axios(axios_options)
|
|
336
299
|
.then((res) => {
|
|
337
|
-
if (this.log) {
|
|
338
|
-
console.log("Success Response:", res);
|
|
339
|
-
console.log("Response for url:", options.url);
|
|
340
|
-
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
341
|
-
}
|
|
342
300
|
if (callback) {
|
|
343
301
|
callback(null, res);
|
|
344
302
|
}
|
|
345
303
|
})
|
|
346
304
|
.catch((err) => {
|
|
347
305
|
if (this.log) {
|
|
348
|
-
if (err.response) {
|
|
349
|
-
console.log("Error Response data:", err.response.data);
|
|
350
|
-
}
|
|
351
306
|
// FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - START
|
|
352
307
|
let cache = [];
|
|
353
308
|
let error_log = JSON.stringify(err, function (key, value) { // try to use a separate function
|
|
@@ -359,9 +314,8 @@ class DirWebRequestV2 {
|
|
|
359
314
|
}
|
|
360
315
|
return value;
|
|
361
316
|
});
|
|
362
|
-
|
|
317
|
+
winston.error("(DirWebRequestv2) An error occurred: ", error_log);
|
|
363
318
|
// FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END
|
|
364
|
-
// console.error("An error occurred:", JSON.stringify(err));
|
|
365
319
|
}
|
|
366
320
|
if (callback) {
|
|
367
321
|
let status = 1000;
|
|
@@ -398,7 +352,7 @@ class DirWebRequestV2 {
|
|
|
398
352
|
});
|
|
399
353
|
}
|
|
400
354
|
catch (error) {
|
|
401
|
-
|
|
355
|
+
winston.error("DirWebRequestV2 Error:", error);
|
|
402
356
|
}
|
|
403
357
|
}
|
|
404
358
|
|
|
@@ -407,20 +361,11 @@ class DirWebRequestV2 {
|
|
|
407
361
|
if (!action.settings) {
|
|
408
362
|
return timeout;
|
|
409
363
|
}
|
|
410
|
-
// console.log("default timeout:", timeout);
|
|
411
|
-
// console.log("action.settings:", action.settings);
|
|
412
|
-
// console.log("action.settings.timeout:", action.settings.timeout);
|
|
413
|
-
// console.log("typeof action.settings.timeout:", typeof action.settings.timeout);
|
|
414
|
-
// console.log("action.settings.timeout > min", action.settings.timeout > min)
|
|
415
|
-
// console.log("action.settings.timeout < max", action.settings.timeout < max)
|
|
416
|
-
|
|
417
364
|
if (action.settings.timeout) {
|
|
418
365
|
if ((typeof action.settings.timeout === "number") && action.settings.timeout > min && action.settings.timeout < max) {
|
|
419
366
|
timeout = Math.round(action.settings.timeout)
|
|
420
|
-
// console.log("new timeout:", timeout);
|
|
421
367
|
}
|
|
422
368
|
}
|
|
423
|
-
// console.log("returning timeout:", timeout);
|
|
424
369
|
return timeout
|
|
425
370
|
}
|
|
426
371
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
let axios = require('axios');
|
|
2
2
|
let https = require("https");
|
|
3
3
|
const { Filler } = require('../Filler');
|
|
4
|
-
const { TiledeskChatbot } = require('../../
|
|
4
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
5
5
|
const { DirIntent } = require('./DirIntent');
|
|
6
6
|
|
|
7
7
|
class DirWebRequestV2 {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { Filler } = require('../Filler');
|
|
2
|
-
const { TiledeskChatbot } = require('../../
|
|
3
|
-
const { TiledeskChatbotUtil } = require('../../
|
|
2
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
3
|
+
const { TiledeskChatbotUtil } = require('../../utils/TiledeskChatbotUtil');
|
|
4
4
|
let axios = require('axios');
|
|
5
5
|
|
|
6
6
|
class DirWebResponse {
|
|
@@ -18,12 +18,13 @@ class DirWebResponse {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
execute(directive, callback) {
|
|
21
|
+
winston.debug("Execute WebResponse directive: ", directive);
|
|
21
22
|
let action;
|
|
22
23
|
if (directive.action) {
|
|
23
24
|
action = directive.action;
|
|
24
25
|
}
|
|
25
26
|
else {
|
|
26
|
-
|
|
27
|
+
winston.debug("DirWebResponse Incorrect directive: ", directive);
|
|
27
28
|
callback();
|
|
28
29
|
return;
|
|
29
30
|
}
|
|
@@ -34,22 +35,20 @@ class DirWebResponse {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
async go(action, callback) {
|
|
37
|
-
|
|
38
|
-
console.log("(DirWebResponse) action:", action);
|
|
39
|
-
}
|
|
38
|
+
winston.debug("DirWebResponse action: ", action);
|
|
40
39
|
|
|
41
40
|
let requestAttributes = null;
|
|
41
|
+
let status = null;
|
|
42
42
|
if (this.tdcache) {
|
|
43
43
|
requestAttributes =
|
|
44
44
|
await TiledeskChatbot.allParametersStatic(this.tdcache, this.requestId);
|
|
45
45
|
const filler = new Filler();
|
|
46
46
|
|
|
47
47
|
try {
|
|
48
|
-
|
|
49
|
-
status = filler.fill(status, requestAttributes);
|
|
48
|
+
status = filler.fill(action.status, requestAttributes);
|
|
50
49
|
}
|
|
51
50
|
catch(e) {
|
|
52
|
-
|
|
51
|
+
winston.error("DirWebResponse Error: ", e)
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
}
|
|
@@ -64,12 +63,10 @@ class DirWebResponse {
|
|
|
64
63
|
|
|
65
64
|
try {
|
|
66
65
|
this.tdcache.publish(topic, JSON.stringify(webResponse));
|
|
67
|
-
|
|
68
|
-
console.log("(DirWebResponse) Published webresponse to topic:", topic);
|
|
69
|
-
}
|
|
66
|
+
winston.verbose("DirWebResponse Published webresponse to topic: " + topic);
|
|
70
67
|
}
|
|
71
68
|
catch(e) {
|
|
72
|
-
|
|
69
|
+
winston.error("DirWebResponse Error: ", e)
|
|
73
70
|
}
|
|
74
71
|
|
|
75
72
|
callback();
|
|
@@ -87,7 +84,7 @@ class DirWebResponse {
|
|
|
87
84
|
resolve(json);
|
|
88
85
|
}
|
|
89
86
|
catch (err) {
|
|
90
|
-
|
|
87
|
+
winston.error("Error parsing webRequest jsonBody: " + JSON.stringify(jsonBody) + "\nError: " + JSON.stringify(err));
|
|
91
88
|
reject("Error parsing jsonBody");
|
|
92
89
|
}
|
|
93
90
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const axios = require("axios").default;
|
|
2
|
-
const { TiledeskChatbot } = require('../../
|
|
2
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
3
|
+
const httpUtils = require("../../utils/HttpUtils");
|
|
4
|
+
const winston = require('../../utils/winston');
|
|
3
5
|
|
|
4
6
|
let whatsapp_api_url;
|
|
5
7
|
|
|
@@ -15,13 +17,13 @@ class DirWhatsappByAttribute {
|
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
execute(directive, callback) {
|
|
18
|
-
|
|
20
|
+
winston.verbose("Execute WhatsappByAttribute directive");
|
|
19
21
|
let action;
|
|
20
22
|
if (directive.action) {
|
|
21
23
|
action = directive.action;
|
|
22
24
|
}
|
|
23
25
|
else {
|
|
24
|
-
|
|
26
|
+
winston.warn("DirWhatsappByAttribute Incorrect directive: ", directive);
|
|
25
27
|
callback();
|
|
26
28
|
return;
|
|
27
29
|
}
|
|
@@ -31,10 +33,7 @@ class DirWhatsappByAttribute {
|
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
async go(action, callback) {
|
|
34
|
-
|
|
35
|
-
if (this.log) {
|
|
36
|
-
console.log("whatsapp by attributes action: ", JSON.stringify(action))
|
|
37
|
-
}
|
|
36
|
+
winston.debug("(DirWhatsappByAttribute) Action: ", action);
|
|
38
37
|
|
|
39
38
|
const whatsapp_api_url_pre = process.env.WHATSAPP_ENDPOINT;
|
|
40
39
|
|
|
@@ -43,20 +42,20 @@ class DirWhatsappByAttribute {
|
|
|
43
42
|
} else {
|
|
44
43
|
whatsapp_api_url = this.API_ENDPOINT + "/modules/whatsapp/api"
|
|
45
44
|
}
|
|
46
|
-
|
|
45
|
+
winston.debug("(DirWhatsappByAttribute) whatsapp_api_url: " + whatsapp_api_url);
|
|
47
46
|
|
|
48
47
|
if (!action.attributeName) {
|
|
49
|
-
|
|
48
|
+
winston.error("(DirWhatsappByAttribute) attributeName is mandatory")
|
|
50
49
|
callback();
|
|
51
50
|
return;
|
|
52
51
|
}
|
|
53
|
-
|
|
52
|
+
winston.debug("(DirWhatsappByAttribute) attributeName: " + action.attributeName )
|
|
54
53
|
|
|
55
54
|
const attribute_value = await TiledeskChatbot.getParameterStatic(this.context.tdcache, this.context.requestId, action.attributeName)
|
|
56
|
-
|
|
55
|
+
winston.debug("(DirWhatsappByAttribute) attribute_value:", attribute_value);
|
|
57
56
|
|
|
58
57
|
if (attribute_value == null) {
|
|
59
|
-
|
|
58
|
+
winston.error("(DirWhatsappByAttribute) attribute_value is undefined");
|
|
60
59
|
callback();
|
|
61
60
|
return;
|
|
62
61
|
}
|
|
@@ -73,7 +72,7 @@ class DirWhatsappByAttribute {
|
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
return new Promise((resolve, reject) => {
|
|
76
|
-
|
|
75
|
+
httpUtils.request(
|
|
77
76
|
HTTPREQUEST,
|
|
78
77
|
function (err, resbody) {
|
|
79
78
|
if (err) {
|
|
@@ -86,41 +85,13 @@ class DirWhatsappByAttribute {
|
|
|
86
85
|
if (callback) {
|
|
87
86
|
callback(null, resbody);
|
|
88
87
|
}
|
|
89
|
-
|
|
88
|
+
winston.debug("(DirWhatsappByAttribute) broadcast sent: ", resbody);
|
|
90
89
|
resolve(resbody);
|
|
91
90
|
}
|
|
92
91
|
}, true);
|
|
93
92
|
})
|
|
94
93
|
|
|
95
94
|
}
|
|
96
|
-
|
|
97
|
-
// HTTP REQUEST
|
|
98
|
-
static async myrequest(options, callback, log) {
|
|
99
|
-
console.log("my request execution")
|
|
100
|
-
return await axios({
|
|
101
|
-
url: options.url,
|
|
102
|
-
method: options.method,
|
|
103
|
-
data: options.json,
|
|
104
|
-
params: options.params,
|
|
105
|
-
headers: options.headers
|
|
106
|
-
}).then((res) => {
|
|
107
|
-
if (res && res.status == 200 && res.data) {
|
|
108
|
-
if (callback) {
|
|
109
|
-
callback(null, res.data);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
if (callback) {
|
|
114
|
-
callback(TiledeskClient.getErr({ message: "Response status not 200" }, options, res), null, null);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}).catch((err) => {
|
|
118
|
-
console.error("(tybot request) An error occured: ", err);
|
|
119
|
-
if (callback) {
|
|
120
|
-
callback(err, null, null);
|
|
121
|
-
}
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
95
|
}
|
|
125
96
|
|
|
126
97
|
module.exports = { DirWhatsappByAttribute }
|
|
@@ -74,13 +74,10 @@ class Directives {
|
|
|
74
74
|
// static CONDITION = "condition"; // DEPRECATED
|
|
75
75
|
|
|
76
76
|
static actionToDirective(action) {
|
|
77
|
-
// console.log("actionToDirective:", action);
|
|
78
77
|
let directive = {
|
|
79
78
|
name: action["_tdActionType"],
|
|
80
79
|
action: action
|
|
81
80
|
}
|
|
82
|
-
// delete directive.action["_tdActionType"];
|
|
83
|
-
// console.log("Directive out:", directive);
|
|
84
81
|
return directive;
|
|
85
82
|
}
|
|
86
83
|
}
|