@tiledesk/tiledesk-tybot-connector 2.0.8 → 2.0.9-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.
Files changed (80) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/ExtApi.js +1 -8
  3. package/ExtUtil.js +5 -6
  4. package/Logger.js +30 -13
  5. package/engine/IntentForm.js +0 -1
  6. package/engine/IntentsMachineFactory.js +4 -4
  7. package/engine/MongodbBotsDataSource.js +0 -1
  8. package/engine/MongodbIntentsMachine.js +0 -1
  9. package/engine/TiledeskChatbot.js +11 -16
  10. package/engine/TiledeskIntentsMachine.js +1 -2
  11. package/engine/mock/MockBotsDataSource.js +1 -2
  12. package/index.js +23 -39
  13. package/logs/app1.log +1400 -0
  14. package/package.json +3 -2
  15. package/services/AIService.js +1 -1
  16. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +24 -18
  17. package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +1 -2
  18. package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +1 -3
  19. package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +1 -3
  20. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +7 -9
  21. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfNotOpenHours.js +3 -10
  22. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfOpenHours.js +2 -9
  23. package/tiledeskChatbotPlugs/directives/DirAddTags.js +1 -3
  24. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +0 -1
  25. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +0 -1
  26. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +0 -1
  27. package/tiledeskChatbotPlugs/directives/DirAssign.js +5 -8
  28. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +1 -3
  29. package/tiledeskChatbotPlugs/directives/DirAssistant.js +0 -1
  30. package/tiledeskChatbotPlugs/directives/DirBrevo.js +4 -6
  31. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +0 -1
  32. package/tiledeskChatbotPlugs/directives/DirClose.js +0 -2
  33. package/tiledeskChatbotPlugs/directives/DirCode.js +0 -1
  34. package/tiledeskChatbotPlugs/directives/DirCondition.js +0 -1
  35. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +0 -1
  36. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +1 -3
  37. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +0 -1
  38. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +2 -5
  39. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +0 -1
  40. package/tiledeskChatbotPlugs/directives/DirDepartment.js +1 -3
  41. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +1 -3
  42. package/tiledeskChatbotPlugs/directives/DirForm.js +1 -3
  43. package/tiledeskChatbotPlugs/directives/DirGptTask.js +0 -1
  44. package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +36 -55
  45. package/tiledeskChatbotPlugs/directives/DirHubspot.js +0 -1
  46. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +1 -4
  47. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +1 -4
  48. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +0 -2
  49. package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +8 -12
  50. package/tiledeskChatbotPlugs/directives/DirIntent.js +6 -5
  51. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +0 -1
  52. package/tiledeskChatbotPlugs/directives/DirLockIntent.js +0 -1
  53. package/tiledeskChatbotPlugs/directives/DirMake.js +1 -16
  54. package/tiledeskChatbotPlugs/directives/DirMessage.js +1 -3
  55. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +0 -1
  56. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +1 -4
  57. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +0 -3
  58. package/tiledeskChatbotPlugs/directives/DirQapla.js +0 -1
  59. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +1 -3
  60. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +1 -2
  61. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +1 -3
  62. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +1 -3
  63. package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +1 -3
  64. package/tiledeskChatbotPlugs/directives/DirReply.js +7 -18
  65. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +8 -13
  66. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +1 -3
  67. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +0 -1
  68. package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +0 -1
  69. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +1 -4
  70. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +1 -3
  71. package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +0 -1
  72. package/tiledeskChatbotPlugs/directives/DirWait.js +0 -1
  73. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +0 -1
  74. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +1 -16
  75. package/tiledeskChatbotPlugs/directives/DirWebResponse.js +6 -40
  76. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +0 -1
  77. package/tiledeskChatbotPlugs/directives/Directives.js +1 -0
  78. package/utils/TiledeskChatbotUtil.js +19 -57
  79. package/TdCache copy.js +0 -242
  80. package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +0 -417
package/TdCache copy.js DELETED
@@ -1,242 +0,0 @@
1
- const redis = require('redis');
2
-
3
- class TdCache {
4
-
5
- constructor(config) {
6
- this.redis_host = config.host;
7
- this.redis_port = config.port;
8
- this.redis_password = config.password;
9
- this.client = null;
10
- }
11
-
12
- async connect(callback) {
13
- // client = redis.createClient();
14
- return new Promise( async (resolve, reject) => {
15
- this.client = redis.createClient(
16
- {
17
- host: this.redis_host,
18
- port: this.redis_port,
19
- password: this.redis_password
20
- });
21
- this.client.on('error', err => {
22
- reject(err);
23
- if (callback) {
24
- callback(err);
25
- }
26
- });
27
- // this.client.on('connect', function() {
28
- // console.log('Redis Connected!');
29
- // });
30
- this.client.on('ready',function() {
31
- console.log("connected")
32
- resolve();
33
- if (callback) {
34
- callback();
35
- }
36
- //console.log("Redis is ready.");
37
- });
38
- });
39
- }
40
-
41
- async set(key, value, options) {
42
- //console.log("setting key value", key, value)
43
- if (!options) {
44
- options = {EX: 86400}
45
- }
46
- return new Promise( async (resolve, reject) => {
47
- if (options && options.EX) {
48
- //console.log("expires:", options.EX)
49
- try {
50
- await this.client.set(
51
- key,
52
- value,
53
- 'EX', options.EX);
54
- }
55
- catch(error) {
56
- reject(error)
57
- }
58
- }
59
- else {
60
- try {
61
- //console.log("setting here...key", key, value)
62
- await this.client.set(
63
- key,
64
- value);
65
- }
66
- catch(error) {
67
- console.error("Error", error);
68
- reject(error)
69
- }
70
- }
71
- if (options && options.callback) {
72
- options.callback();
73
- }
74
- //console.log("resolving...", key);
75
- return resolve();
76
- });
77
- }
78
-
79
- async incr(key) {
80
- // console.log("incr key:", key)
81
- return new Promise( async (resolve, reject) => {
82
- try {
83
- // console.log("incr here...key", key)
84
- await this.client.incr(key);
85
- }
86
- catch(error) {
87
- console.error("Error on incr:", error);
88
- reject(error)
89
- }
90
- return resolve();
91
- });
92
- }
93
-
94
- async hset(dict_key, key, value, options) {
95
- //console.log("hsetting dict_key key value", dict_key, key, value)
96
- return new Promise( async (resolve, reject) => {
97
- if (options && options.EX) {
98
- //console.log("expires:", options.EX)
99
- try {
100
- await this.client.hset(
101
- dict_key,
102
- key,
103
- value,
104
- 'EX', options.EX);
105
- }
106
- catch(error) {
107
- reject(error)
108
- }
109
- }
110
- else {
111
- try {
112
- //console.log("setting here...key", key, value)
113
- await this.client.hset(
114
- dict_key,
115
- key,
116
- value);
117
- }
118
- catch(error) {
119
- console.error("Error", error);
120
- reject(error)
121
- }
122
- }
123
- if (options && options.callback) {
124
- options.callback();
125
- }
126
- return resolve();
127
- });
128
- }
129
-
130
- async hdel(dict_key, key, options) {
131
- //console.log("hsetting dict_key key value", dict_key, key, value)
132
- return new Promise( async (resolve, reject) => {
133
- if (options && options.EX) {
134
- //console.log("expires:", options.EX)
135
- try {
136
- await this.client.hdel(
137
- dict_key,
138
- key,
139
- 'EX', options.EX);
140
- }
141
- catch(error) {
142
- reject(error)
143
- }
144
- }
145
- else {
146
- try {
147
- //console.log("setting here...key", key, value)
148
- await this.client.hdel(
149
- dict_key,
150
- key);
151
- }
152
- catch(error) {
153
- console.error("Error", error);
154
- reject(error);
155
- }
156
- }
157
- if (options && options.callback) {
158
- options.callback();
159
- }
160
- return resolve();
161
- });
162
- }
163
-
164
- async setJSON(key, value, options) {
165
- const _string = JSON.stringify(value);
166
- return await this.set(key, _string, options);
167
- }
168
-
169
- async get(key, callback) {
170
- //console.log("getting key", key)
171
- return new Promise( async (resolve, reject) => {
172
- this.client.get(key, (err, value) => {
173
- if (err) {
174
- reject(err);
175
- }
176
- else {
177
- if (callback) {
178
- callback(value);
179
- }
180
- return resolve(value);
181
- }
182
- });
183
- });
184
- }
185
-
186
- async hgetall(dict_key, callback) {
187
- //console.log("hgetting dics", dict_key);
188
- return new Promise( async (resolve, reject) => {
189
- this.client.hgetall(dict_key, (err, value) => {
190
- if (err) {
191
- reject(err);
192
- if (callback) {
193
- callback(err, null);
194
- }
195
- }
196
- else {
197
- if (callback) {
198
- callback(null, value);
199
- }
200
- resolve(value);
201
- }
202
- });
203
- });
204
- }
205
-
206
- async hget(dict_key, key, callback) {
207
- //console.log("hgetting dics", dict_key);
208
- return new Promise( async (resolve, reject) => {
209
- this.client.hget(dict_key, key, (err, value) => {
210
- if (err) {
211
- reject(err);
212
- if (callback) {
213
- callback(err, null);
214
- }
215
- }
216
- else {
217
- if (callback) {
218
- callback(null, value);
219
- }
220
- resolve(value);
221
- }
222
- });
223
- });
224
- }
225
-
226
- async getJSON(key, callback) {
227
- const value = await this.get(key);
228
- return JSON.parse(value);
229
- }
230
-
231
- async del(key, callback) {
232
- return new Promise( async (resolve, reject) => {
233
- await this.client.del(key);
234
- if (callback) {
235
- callback();
236
- }
237
- return resolve();
238
- })
239
- }
240
- }
241
-
242
- module.exports = { TdCache };
@@ -1,417 +0,0 @@
1
- let axios = require('axios');
2
- let https = require("https");
3
- const { Filler } = require('../Filler');
4
- const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
5
- const { DirIntent } = require('./DirIntent');
6
-
7
- class DirWebRequestV2 {
8
- constructor(context) {
9
- if (!context) {
10
- throw new Error('context object is mandatory.');
11
- }
12
- this.context = context;
13
- this.tdcache = context.tdcache;
14
- this.requestId = context.requestId;
15
- this.chatbot = context.chatbot;
16
- this.intentDir = new DirIntent(context);
17
- this.log = context.log;
18
- }
19
-
20
- execute(directive, callback) {
21
- let action;
22
- if (directive.action) {
23
- action = directive.action;
24
- }
25
- else {
26
- console.error("Incorrect directive:", JSON.stringify(directive));
27
- callback();
28
- return;
29
- }
30
- this.go(action, (stop) => {
31
- if (this.log) {console.log("(webrequestv2, stop?", stop); }
32
- callback(stop);
33
- });
34
- }
35
-
36
- async go(action, callback) {
37
- if (this.log) {console.log("webRequest action:", JSON.stringify(action));}
38
-
39
- // Condition branches
40
- let trueIntent = action.trueIntent;
41
- let falseIntent = action.falseIntent;
42
- const trueIntentAttributes = action.trueIntentAttributes;
43
- const falseIntentAttributes = action.falseIntentAttributes;
44
- let stopOnConditionMet = action.stopOnConditionMet;
45
- if (trueIntent && trueIntent.trim() === "") {
46
- trueIntent = null;
47
- }
48
- if (falseIntent && falseIntent.trim() === "") {
49
- falseIntent = null;
50
- }
51
-
52
- let requestAttributes = null;
53
- if (this.tdcache) {
54
- requestAttributes =
55
- await TiledeskChatbot.allParametersStatic(
56
- this.tdcache, this.requestId
57
- );
58
- }
59
- const filler = new Filler();
60
- const url = filler.fill(action.url, requestAttributes);
61
-
62
- let headers = {};
63
- if (action.headersString) {
64
- let headersDict = action.headersString
65
- for (const [key, value] of Object.entries(headersDict)) {
66
- if (this.log) {console.log("header:", key, "value:", value)}
67
- let filled_value = filler.fill(value, requestAttributes);
68
- headers[key] = filled_value;
69
- }
70
- }
71
-
72
- let json = null;
73
- try {
74
- if (action.jsonBody && action.bodyType == "json") {
75
- if (this.log) {console.log("action.body is:", action.jsonBody);}
76
- let jsonBody = filler.fill(action.jsonBody, requestAttributes);
77
- try {
78
- json = JSON.parse(jsonBody);
79
- if (this.log) {console.log("json is:", json);}
80
- }
81
- catch(err) {
82
- console.error("Error parsing webRequest jsonBody:", jsonBody);
83
- if (callback) {
84
- if (falseIntent) {
85
- await this.chatbot.addParameter("flowError", "Error parsing jsonBody");
86
- this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes, () => {
87
- console.log('herrrrr 11111' )
88
- callback(true); // stop the flow
89
- return;
90
- });
91
- }
92
- else {
93
- console.log('herrrrr 2222' )
94
- callback(false); // continue the flow
95
- return;
96
- }
97
- }
98
- }
99
- }
100
- else if (action.formData && action.bodyType == "form-data") {
101
- let formData = filler.fill(action.formData, requestAttributes);
102
- if (this.log) {console.log("action.body is form-data:", formData);}
103
- // // fill
104
- if (formData && formData.length > 0) {
105
- for (let i = 0; i < formData.length; i++) {
106
- let field = formData[i];
107
- if (field.value) {
108
- field.value = filler.fill(field.value, requestAttributes);
109
- if (this.log) {console.log("field filled:", field.value);}
110
- }
111
- }
112
- }
113
- json = {};
114
- for (let i = 0; i < formData.length; i++) {
115
- let field = formData[i];
116
- if (field.enabled && field.value && field.type === "URL") {
117
- if (this.log) {console.log("Getting file:", field.value);}
118
- let response = await axios.get(field.value,
119
- {
120
- responseType: 'stream'
121
- }
122
- );
123
- let stream = response.data;
124
- // if (this.log) {console.log("Stream data:", stream);}
125
- json[field.name] = stream;
126
- // process.exit(0);
127
- }
128
- else if (field.enabled && field.value && field.type === "Text") {
129
- json[field.name] = field.value;
130
- }
131
- }
132
- if (this.log) {console.log("final json:", json);}
133
- }
134
- else {
135
- if (this.log) {console.log("no action upload parts");}
136
- }
137
-
138
- }
139
- catch(error) {
140
- console.error("Error", error);
141
- if (callback) {
142
- if (falseIntent) {
143
- await this.chatbot.addParameter("flowError", "Error: " + error);
144
- this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes, () => {
145
- callback(true); // stop the flow
146
- return;
147
- });
148
- }
149
- else {
150
- callback(false); // continue the flow
151
- return;
152
- }
153
- }
154
- }
155
-
156
-
157
-
158
- let timeout = this.#webrequest_timeout(action, 20000, 1, 300000);
159
-
160
- if (this.log) {console.log("webRequest URL", url);}
161
-
162
- const HTTPREQUEST = {
163
- url: url,
164
- headers: headers,
165
- json: json,
166
- method: action.method,
167
- timeout: timeout
168
- };
169
-
170
- if (this.log) {console.log("webRequest HTTPREQUEST", HTTPREQUEST);}
171
- this.#myrequest(
172
- HTTPREQUEST, async (err, res) => {
173
- if (this.log && err) {
174
- console.log("webRequest error:", err);
175
- }
176
- if (this.log) {console.log("got res:", res);}
177
- let resbody = res.data;
178
- let status = res.status;
179
- let error = res.error;
180
- await this.#assignAttributes(action, resbody, status, error)
181
- if (this.log) {console.log("webRequest resbody:", resbody);}
182
- if (err) {
183
- if (this.log) {console.error("webRequest error:", err);}
184
- if (callback) {
185
- if (falseIntent) {
186
- this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes, () => {
187
- callback(true); // stop the flow
188
- });
189
- }
190
- else {
191
- callback(false); // continue the flow
192
- }
193
- }
194
- }
195
- else if(res.status >= 200 && res.status <= 299) {
196
- if (trueIntent) {
197
- await this.#executeCondition(true, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes, () => {
198
- callback(true); // stop the flow
199
- });
200
- }
201
- else {
202
- callback(false); // continue the flow
203
- }
204
- }
205
- else {
206
- if (falseIntent) {
207
- this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes, () => {
208
- callback(true); // stop the flow
209
- });
210
- }
211
- else {
212
- callback(false); // continue the flow
213
- }
214
- }
215
- }
216
- );
217
- }
218
-
219
- async #executeCondition(result, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes, callback) {
220
- let trueIntentDirective = null;
221
- if (trueIntent) {
222
- trueIntentDirective = DirIntent.intentDirectiveFor(trueIntent, trueIntentAttributes);
223
- }
224
- let falseIntentDirective = null;
225
- if (falseIntent) {
226
- falseIntentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
227
- }
228
- if (result === true) {
229
- if (trueIntentDirective) {
230
- this.intentDir.execute(trueIntentDirective, () => {
231
- callback();
232
- });
233
- }
234
- else {
235
- if (this.log) {console.log("No trueIntentDirective specified");}
236
- callback();
237
- }
238
- }
239
- else {
240
- if (falseIntentDirective) {
241
- this.intentDir.execute(falseIntentDirective, () => {
242
- callback();
243
- });
244
- }
245
- else {
246
- if (this.log) {console.log("No falseIntentDirective specified");}
247
- callback();
248
- }
249
- }
250
- }
251
-
252
- async #assignAttributes(action, resbody, status, error) {
253
- if (this.log) {
254
- console.log("assignAttributes resbody:", resbody)
255
- console.log("assignAttributes error:", error)
256
- console.log("assignAttributes status:", status)
257
- console.log("assignAttributes action:", action)
258
- }
259
- if (this.context.tdcache) {
260
- if (action.assignResultTo && resbody) {
261
- if (this.log) {console.log("assign assignResultTo:", resbody);}
262
- await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignResultTo, resbody);
263
- }
264
- if (action.assignErrorTo && error) {
265
- if (this.log) {console.log("assign assignResultTo:", error);}
266
- await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignErrorTo, error);
267
- }
268
- if (action.assignStatusTo && status) {
269
- if (this.log) {console.log("assign assignStatusTo:", status);}
270
- await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignStatusTo, status);
271
- }
272
- // Debug log
273
- if (this.log) {
274
- const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
275
- for (const [key, value] of Object.entries(all_parameters)) {
276
- if (this.log) {console.log("(webRequest) request parameter:", key, "value:", value, "type:", typeof value)}
277
- }
278
- }
279
- }
280
- }
281
-
282
- #myrequest(options, callback) {
283
- try {
284
- if (this.log) {
285
- console.log("API URL:", options.url);
286
- //console.log("** Options:", JSON.stringify(options));
287
- // Stringify "options". FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - START
288
- let cache = [];
289
- let str_Options = JSON.stringify(options, function(key, value) { // try to use a separate function
290
- if (typeof value === 'object' && value != null) {
291
- if (cache.indexOf(value) !== -1) {
292
- return;
293
- }
294
- cache.push(value);
295
- }
296
- return value;
297
- });
298
- console.log("** Options:", str_Options);
299
- }
300
- let axios_options = {
301
- url: options.url,
302
- method: options.method,
303
- params: options.params,
304
- headers: options.headers,
305
- timeout: options.timeout,
306
- maxContentLength: 10000000, // max 10mb response size
307
- maxBodyLength: 10000000 // max 10mb request body size
308
- }
309
-
310
- if (options.json !== null) {
311
- axios_options.data = options.json
312
- }
313
- // if (this.log) {
314
- // console.log("axios_options:", JSON.stringify(axios_options));
315
- // }
316
- if (options.url.startsWith("https:")) {
317
- const httpsAgent = new https.Agent({
318
- rejectUnauthorized: false,
319
- });
320
- axios_options.httpsAgent = httpsAgent;
321
- }
322
-
323
- axios(axios_options)
324
- .then((res) => {
325
- if (this.log) {
326
- console.log("Success Response:", res);
327
- console.log("Response for url:", options.url);
328
- console.log("Response headers:\n", JSON.stringify(res.headers));
329
- }
330
- if (callback) {
331
- callback(null, res);
332
- }
333
- })
334
- .catch( (err) => {
335
- if (this.log) {
336
- if (err.response) {
337
- console.log("Error Response data:", err.response.data);
338
- }
339
- // FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - START
340
- let cache = [];
341
- let error_log = JSON.stringify(err, function(key, value) { // try to use a separate function
342
- if (typeof value === 'object' && value != null) {
343
- if (cache.indexOf(value) !== -1) {
344
- return;
345
- }
346
- cache.push(value);
347
- }
348
- return value;
349
- });
350
- console.error("An error occurred: ", error_log);
351
- // FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END
352
- // console.error("An error occurred:", JSON.stringify(err));
353
- }
354
- if (callback) {
355
- let status = 1000;
356
- let cache = [];
357
- let str_error = JSON.stringify(err, function(key, value) { // try to use a separate function
358
- if (typeof value === 'object' && value != null) {
359
- if (cache.indexOf(value) !== -1) {
360
- return;
361
- }
362
- cache.push(value);
363
- }
364
- return value;
365
- });
366
- let error = JSON.parse(str_error) // "status" disappears without this trick
367
- let errorMessage = JSON.stringify(error);
368
- if (error.status) {
369
- status = error.status;
370
- }
371
- if (error.message) {
372
- errorMessage = error.message;
373
- }
374
- let data = null;
375
- if (err.response) {
376
- data = err.response.data;
377
- }
378
- callback(
379
- null, {
380
- status: status,
381
- data: data,
382
- error: errorMessage
383
- }
384
- );
385
- }
386
- });
387
- }
388
- catch(error) {
389
- console.error("Error:", error);
390
- }
391
- }
392
-
393
- #webrequest_timeout(action, default_timeout, min, max) {
394
- let timeout = default_timeout;
395
- if (!action.settings) {
396
- return timeout;
397
- }
398
- // console.log("default timeout:", timeout);
399
- // console.log("action.settings:", action.settings);
400
- // console.log("action.settings.timeout:", action.settings.timeout);
401
- // console.log("typeof action.settings.timeout:", typeof action.settings.timeout);
402
- // console.log("action.settings.timeout > min", action.settings.timeout > min)
403
- // console.log("action.settings.timeout < max", action.settings.timeout < max)
404
-
405
- if (action.settings.timeout) {
406
- if ((typeof action.settings.timeout === "number") && action.settings.timeout > min && action.settings.timeout < max) {
407
- timeout = Math.round(action.settings.timeout)
408
- // console.log("new timeout:", timeout);
409
- }
410
- }
411
- // console.log("returning timeout:", timeout);
412
- return timeout
413
- }
414
-
415
- }
416
-
417
- module.exports = { DirWebRequestV2 };