@tiledesk/tiledesk-tybot-connector 0.5.0-rc1 → 0.5.0-rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ExtApi.js +3 -13
- package/ExtUtil.js +0 -1
- package/TdCache.js +5 -3
- package/TiledeskClientTest.js +5 -28
- package/TiledeskExpression.js +6 -47
- package/index.js +87 -273
- package/logs/app.log +12983 -275
- package/logs/app1.log +62258 -0
- package/logs/app2.log +46280 -0
- package/logs/app3.log +28864 -0
- package/models/IntentForm.js +30 -44
- package/models/IntentsMachineFactory.js +4 -3
- package/models/MockBotsDataSource.js +1 -17
- package/models/MockTdCache.js +0 -9
- package/models/MongodbBotsDataSource.js +29 -53
- package/models/MongodbIntentsMachine.js +5 -4
- package/models/TiledeskChatbot.js +79 -258
- package/models/TiledeskChatbotConst.js +9 -0
- package/models/TiledeskChatbotUtil.js +79 -230
- package/models/TiledeskIntentsMachine.js +5 -14
- package/models/faqKbService.js +0 -1
- package/package.json +4 -2
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +54 -140
- package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +7 -13
- 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/WebhookChatbotPlug.js +21 -89
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +15 -98
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +3 -3
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +32 -57
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +46 -70
- package/tiledeskChatbotPlugs/directives/DirAssign.js +11 -22
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +15 -11
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +48 -97
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +37 -68
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +8 -18
- package/tiledeskChatbotPlugs/directives/DirClose.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirCode.js +15 -22
- package/tiledeskChatbotPlugs/directives/DirCondition.js +18 -24
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -13
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +7 -19
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +30 -57
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +15 -20
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +7 -7
- 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 +15 -22
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +38 -65
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +27 -58
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +22 -40
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -32
- package/tiledeskChatbotPlugs/directives/DirIntent.js +10 -28
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +14 -13
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
- package/tiledeskChatbotPlugs/directives/DirMake.js +20 -52
- package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +10 -20
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +4 -2
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +4 -2
- package/tiledeskChatbotPlugs/directives/DirQapla.js +21 -50
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +9 -17
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +4 -1
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +10 -21
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +9 -19
- package/tiledeskChatbotPlugs/directives/DirReply.js +18 -34
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +25 -69
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +8 -9
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +13 -12
- package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +7 -4
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +22 -75
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
- package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
- package/tiledeskChatbotPlugs/directives/DirWait.js +4 -5
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +13 -48
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +11 -76
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +11 -14
- package/tiledeskChatbotPlugs/directives/Directives.js +0 -3
- package/utils/winston.js +42 -0
package/ExtApi.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
let axios = require('axios');
|
|
2
2
|
let https = require("https");
|
|
3
|
+
const winston = require('./utils/winston');
|
|
3
4
|
|
|
4
5
|
class ExtApi {
|
|
5
6
|
|
|
@@ -38,7 +39,7 @@ class ExtApi {
|
|
|
38
39
|
sendSupportMessageExt(message, projectId, requestId, token, callback) {
|
|
39
40
|
const jwt_token = this.fixToken(token);
|
|
40
41
|
const url = `${this.TILEBOT_ENDPOINT}/ext/${projectId}/requests/${requestId}/messages`;
|
|
41
|
-
|
|
42
|
+
winston.verbose("(ExtApi) sendSupportMessageExt URL" + url);
|
|
42
43
|
const HTTPREQUEST = {
|
|
43
44
|
url: url,
|
|
44
45
|
headers: {
|
|
@@ -51,9 +52,7 @@ class ExtApi {
|
|
|
51
52
|
this.myrequest(
|
|
52
53
|
HTTPREQUEST,
|
|
53
54
|
function(err, resbody) {
|
|
54
|
-
//console.log("sendSupportMessageExt resbody:", resbody);
|
|
55
55
|
if (err) {
|
|
56
|
-
//console.error("sendSupportMessageExt error:", err)
|
|
57
56
|
if (callback) {
|
|
58
57
|
callback(err);
|
|
59
58
|
}
|
|
@@ -77,7 +76,6 @@ class ExtApi {
|
|
|
77
76
|
*/
|
|
78
77
|
// sendMessageToBot(message, botId, token, callback) {
|
|
79
78
|
// const url = `${this.ENDPOINT}/ext/${botId}`;
|
|
80
|
-
// if (this.log) {console.log("sendMessageToBot URL", url);}
|
|
81
79
|
// const HTTPREQUEST = {
|
|
82
80
|
// url: url,
|
|
83
81
|
// headers: {
|
|
@@ -105,10 +103,6 @@ class ExtApi {
|
|
|
105
103
|
// }
|
|
106
104
|
|
|
107
105
|
myrequest(options, callback, log) {
|
|
108
|
-
if (this.log) {
|
|
109
|
-
console.log("API URL:", options.url);
|
|
110
|
-
console.log("** Options:", JSON.stringify(options));
|
|
111
|
-
}
|
|
112
106
|
let axios_options = {
|
|
113
107
|
url: options.url,
|
|
114
108
|
method: options.method,
|
|
@@ -124,10 +118,6 @@ class ExtApi {
|
|
|
124
118
|
}
|
|
125
119
|
axios(axios_options)
|
|
126
120
|
.then((res) => {
|
|
127
|
-
if (this.log) {
|
|
128
|
-
console.log("Response for url:", options.url);
|
|
129
|
-
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
130
|
-
}
|
|
131
121
|
if (res && res.status == 200 && res.data) {
|
|
132
122
|
if (callback) {
|
|
133
123
|
callback(null, res.data);
|
|
@@ -140,7 +130,7 @@ class ExtApi {
|
|
|
140
130
|
}
|
|
141
131
|
})
|
|
142
132
|
.catch( (error) => {
|
|
143
|
-
|
|
133
|
+
winston.error("(ExtApi) An error occurred:", JSON.stringify(error));
|
|
144
134
|
if (callback) {
|
|
145
135
|
callback(error, null, null);
|
|
146
136
|
}
|
package/ExtUtil.js
CHANGED
|
@@ -23,7 +23,6 @@ class ExtUtil {
|
|
|
23
23
|
messagePipeline.addPlug(new MarkbotChatbotPlug(log));
|
|
24
24
|
messagePipeline.addPlug(new FillParamsChatbotPlug(request, tdcache, log)); // in splits
|
|
25
25
|
const bot_answer = await messagePipeline.exec();
|
|
26
|
-
if (this.log) {console.log("End pipeline ext, bot_answer:", JSON.stringify(bot_answer));}
|
|
27
26
|
return bot_answer;
|
|
28
27
|
}
|
|
29
28
|
|
package/TdCache.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
const redis = require('redis');
|
|
2
|
+
const winston = require('./utils/winston');
|
|
2
3
|
|
|
3
4
|
class TdCache {
|
|
4
5
|
|
|
5
6
|
constructor(config) {
|
|
6
|
-
|
|
7
|
+
winston.debug("(TdCache) config: ", config);
|
|
7
8
|
this.redis_host = config.host;
|
|
8
9
|
this.redis_port = config.port;
|
|
9
10
|
this.redis_password = config.password;
|
|
11
|
+
winston.debug("TdCache redis_host: ", this.redis_host);
|
|
12
|
+
winston.debug("TdCache redis_port: ", this.redis_port);
|
|
13
|
+
winston.debug("TdCache redis_password: ", this.redis_password);
|
|
10
14
|
this.client = null;
|
|
11
15
|
this.subscriberClient = null;
|
|
12
16
|
}
|
|
@@ -61,7 +65,6 @@ class TdCache {
|
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
async set(key, value, options) {
|
|
64
|
-
//console.log("setting key value", key, value)
|
|
65
68
|
if (!options) {
|
|
66
69
|
options = {EX: 86400}
|
|
67
70
|
}
|
|
@@ -115,7 +118,6 @@ class TdCache {
|
|
|
115
118
|
}
|
|
116
119
|
|
|
117
120
|
async hget(dict_key, key) {
|
|
118
|
-
// console.log("hgetting dics", dict_key);
|
|
119
121
|
const value = await this.client.HGET(dict_key, key);
|
|
120
122
|
return value;
|
|
121
123
|
}
|
package/TiledeskClientTest.js
CHANGED
|
@@ -7,6 +7,7 @@ const { request } = require('express');
|
|
|
7
7
|
const { v4: uuidv4 } = require('uuid');
|
|
8
8
|
let https = require("https");
|
|
9
9
|
const { Console } = require('console');
|
|
10
|
+
const winston = require("./utils/winston")
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* This class is a NodeJS stub for Tiledesk's REST APIs
|
|
@@ -34,7 +35,6 @@ class TiledeskClientTest {
|
|
|
34
35
|
* @param {boolean} options.log Optional. If true HTTP requests are logged.
|
|
35
36
|
*/
|
|
36
37
|
constructor(options) {
|
|
37
|
-
// console.log("...options:", options)
|
|
38
38
|
|
|
39
39
|
if (!options) {
|
|
40
40
|
throw new Error('options.APIKEY, options.projectId and options.token are mandatory.');
|
|
@@ -2074,9 +2074,7 @@ class TiledeskClientTest {
|
|
|
2074
2074
|
TiledeskClientTest.myrequest(
|
|
2075
2075
|
HTTPREQUEST,
|
|
2076
2076
|
function(err, resbody) {
|
|
2077
|
-
console.log("myrequest REPL");
|
|
2078
2077
|
if (err) {
|
|
2079
|
-
console.log("ERRRRRRRRRR");
|
|
2080
2078
|
if (callback) {
|
|
2081
2079
|
callback(err);
|
|
2082
2080
|
}
|
|
@@ -2085,7 +2083,6 @@ class TiledeskClientTest {
|
|
|
2085
2083
|
}
|
|
2086
2084
|
}
|
|
2087
2085
|
else {
|
|
2088
|
-
console.log("REEEEEESOL");
|
|
2089
2086
|
resolve(resbody);
|
|
2090
2087
|
if (callback) {
|
|
2091
2088
|
callback(null, resbody);
|
|
@@ -2426,10 +2423,8 @@ class TiledeskClientTest {
|
|
|
2426
2423
|
// ************************************************
|
|
2427
2424
|
|
|
2428
2425
|
static myrequest(options, callback, log) {
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
console.log("** Options:", JSON.stringify(options));
|
|
2432
|
-
}
|
|
2426
|
+
winston.verbose("(TiledeskClientTest) API URL: " + options.url);
|
|
2427
|
+
winston.verbose("(TiledeskClientTest) Options:", options);
|
|
2433
2428
|
let axios_settings = {
|
|
2434
2429
|
url: options.url,
|
|
2435
2430
|
method: options.method,
|
|
@@ -2437,47 +2432,29 @@ class TiledeskClientTest {
|
|
|
2437
2432
|
params: options.params,
|
|
2438
2433
|
headers: options.headers
|
|
2439
2434
|
}
|
|
2440
|
-
// console.log("options.url.startsWith(https:)", options.url.startsWith("https:"))
|
|
2441
|
-
// console.log("this.httpsOptions", this.httpsOptions)
|
|
2442
2435
|
|
|
2443
2436
|
if (options.url.startsWith("https:") && options.httpsOptions) {
|
|
2444
|
-
// console.log("Tiledesk Client v 0.9.x: url.startsWith https: && httpsOptions");
|
|
2445
2437
|
const httpsAgent = new https.Agent(options.httpsOptions);
|
|
2446
2438
|
axios_settings.httpsAgent = httpsAgent;
|
|
2447
2439
|
}
|
|
2448
2440
|
else if (options.url.startsWith("https:") && !options.httpsOptions) {
|
|
2449
2441
|
// HTTPS default is rejectUnauthorized: false
|
|
2450
|
-
// console.log("Tiledesk Client v 0.9.x: url.startsWith https: && NOT httpsOptions");
|
|
2451
2442
|
const httpsAgent = new https.Agent({
|
|
2452
2443
|
rejectUnauthorized: false,
|
|
2453
2444
|
});
|
|
2454
2445
|
axios_settings.httpsAgent = httpsAgent;
|
|
2455
2446
|
}
|
|
2456
2447
|
|
|
2457
|
-
// console.log("Using axios settings:", axios_settings)
|
|
2458
|
-
// axios(
|
|
2459
|
-
// {
|
|
2460
|
-
// url: options.url,
|
|
2461
|
-
// method: options.method,
|
|
2462
|
-
// data: options.json,
|
|
2463
|
-
// params: options.params,
|
|
2464
|
-
// httpsAgent: httpsAgent,
|
|
2465
|
-
// headers: options.headers
|
|
2466
|
-
// })
|
|
2467
2448
|
axios(axios_settings)
|
|
2468
2449
|
.then(function (res) {
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
2472
|
-
//console.log("******** Response for url:", res);
|
|
2473
|
-
// }
|
|
2450
|
+
winston.verbose("(TiledeskClientTest) Response for url:" + options.url);
|
|
2451
|
+
winston.verbose("(TiledeskClientTest) Response headers:\n", res.headers);
|
|
2474
2452
|
if (res && res.status == 200 && res.data) {
|
|
2475
2453
|
if (callback) {
|
|
2476
2454
|
callback(null, res.data);
|
|
2477
2455
|
}
|
|
2478
2456
|
}
|
|
2479
2457
|
else {
|
|
2480
|
-
console.log("PROBLEMIIIII")
|
|
2481
2458
|
if (callback) {
|
|
2482
2459
|
callback(TiledeskClientTest.getErr({message: "Response status not 200"}, options, res), null, null);
|
|
2483
2460
|
}
|
package/TiledeskExpression.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const {VM} = require('vm2');
|
|
2
|
+
const winston = require('./utils/winston');
|
|
2
3
|
|
|
3
4
|
class TiledeskExpression {
|
|
4
5
|
// rules:
|
|
@@ -234,12 +235,8 @@ class TiledeskExpression {
|
|
|
234
235
|
|
|
235
236
|
// public
|
|
236
237
|
evaluateExpression(_expression, variables) {
|
|
237
|
-
// console.log("Original expression:", _expression);
|
|
238
238
|
let expression = String(_expression).replace(/\$/g, "$data.");
|
|
239
|
-
// console.log("Evaluating expression:", expression);
|
|
240
|
-
// console.log("With variables:", JSON.stringify(variables));
|
|
241
239
|
const result = new TiledeskExpression().evaluate(expression, variables);
|
|
242
|
-
// console.log("Expression result:", result);
|
|
243
240
|
return result;
|
|
244
241
|
}
|
|
245
242
|
|
|
@@ -250,8 +247,6 @@ class TiledeskExpression {
|
|
|
250
247
|
}
|
|
251
248
|
|
|
252
249
|
evaluateJavascriptExpression(expression, context) {
|
|
253
|
-
// console.log("(evaluateJavascriptExpression) evaluating:", expression)
|
|
254
|
-
// console.log("context:", context)
|
|
255
250
|
let res = null;
|
|
256
251
|
try {
|
|
257
252
|
const vm = new VM({
|
|
@@ -260,10 +255,9 @@ class TiledeskExpression {
|
|
|
260
255
|
sandbox: context
|
|
261
256
|
});
|
|
262
257
|
res = vm.run(`let $data = this;${expression}`);
|
|
263
|
-
// console.log("res=", res)
|
|
264
258
|
}
|
|
265
259
|
catch (err) {
|
|
266
|
-
|
|
260
|
+
winston.error("(TiledeskExpression) evaluateJavascriptExpression error: " + err.message + " - while evaluating the following expression: '" + expression + "'");
|
|
267
261
|
}
|
|
268
262
|
return res;
|
|
269
263
|
}
|
|
@@ -273,10 +267,8 @@ class TiledeskExpression {
|
|
|
273
267
|
if(!operands) {
|
|
274
268
|
return null;
|
|
275
269
|
}
|
|
276
|
-
// console.log("operands are:", JSON.stringify(operands))
|
|
277
270
|
let expression = operands[0].isVariable ? TiledeskExpression.variableOperand(operands[0].value) : TiledeskExpression.quotedString(operands[0].value);
|
|
278
271
|
expression = operands[0].function ? TiledeskExpression.applyFunctionToOperand(expression, operands[0].function) : expression;
|
|
279
|
-
// console.log("expression is:", expression)
|
|
280
272
|
|
|
281
273
|
if (operands.length === 1) {
|
|
282
274
|
return expression;
|
|
@@ -286,12 +278,7 @@ class TiledeskExpression {
|
|
|
286
278
|
const applyPattern = operator.applyPattern;
|
|
287
279
|
let operand = operands[i + 1].isVariable ? TiledeskExpression.variableOperand(operands[i + 1].value) : TiledeskExpression.quotedString(operands[i + 1].value);
|
|
288
280
|
operand = operands[i + 1].function ? TiledeskExpression.applyFunctionToOperand(operand, operands[i + 1].function) : operand;
|
|
289
|
-
// console.log("1. expression is:", expression)
|
|
290
|
-
// console.log("operand is:", operand)
|
|
291
|
-
|
|
292
281
|
expression = applyPattern.replace("#1", expression).replace("#2", operand);
|
|
293
|
-
// console.log("2. expression is:", expression)
|
|
294
|
-
|
|
295
282
|
}
|
|
296
283
|
return expression;
|
|
297
284
|
}
|
|
@@ -303,8 +290,6 @@ class TiledeskExpression {
|
|
|
303
290
|
const operator = TiledeskExpression.OPERATORS[function_name];
|
|
304
291
|
const applyPattern = operator.applyPattern;
|
|
305
292
|
expression += applyPattern.replace("#1", operand);
|
|
306
|
-
// console.log("operand is:", operand);
|
|
307
|
-
// console.log("expression is:", expression);
|
|
308
293
|
return expression;
|
|
309
294
|
}
|
|
310
295
|
|
|
@@ -325,8 +310,6 @@ class TiledeskExpression {
|
|
|
325
310
|
|
|
326
311
|
// DEPRECATED
|
|
327
312
|
evaluate(expression, context) {
|
|
328
|
-
// console.log("evaluating:", expression)
|
|
329
|
-
// console.log("context:", context)
|
|
330
313
|
let res;
|
|
331
314
|
try {
|
|
332
315
|
const vm = new VM({
|
|
@@ -343,27 +326,19 @@ class TiledeskExpression {
|
|
|
343
326
|
}
|
|
344
327
|
|
|
345
328
|
static JSONConditionToExpression(condition, variables) {
|
|
346
|
-
// console.log("condition:", condition);
|
|
347
|
-
// console.log("condition.operand1:", condition.operand1);
|
|
348
|
-
// console.log("condition.operand2:", condition.operand2);
|
|
349
329
|
const operator_name = condition.operator;
|
|
350
330
|
const operator = TiledeskExpression.OPERATORS[operator_name];
|
|
351
|
-
// console.log("operator:", operator);
|
|
352
331
|
const applyPattern = operator.applyPattern;
|
|
353
|
-
// console.log("applyPattern:", applyPattern);
|
|
354
332
|
let operand1_s;
|
|
355
333
|
let is_valid_operand1 = TiledeskExpression.validateVariableName(condition.operand1);
|
|
356
|
-
// console.log("is_valid_operand1:", condition.operand1, is_valid_operand1);
|
|
357
334
|
if (is_valid_operand1) {
|
|
358
335
|
operand1_s = TiledeskExpression.variableOperand(condition.operand1);
|
|
359
|
-
// console.log("operand1_s:", operand1_s);
|
|
360
336
|
}
|
|
361
337
|
else {
|
|
362
|
-
|
|
338
|
+
winston.error("(TiledeskExpression) Condition evaluation stopped because of invalid operand1 " + condition.operand1);
|
|
363
339
|
return null;
|
|
364
340
|
}
|
|
365
341
|
|
|
366
|
-
// console.log("operand1_s:", operand1_s);
|
|
367
342
|
let operand2_s;
|
|
368
343
|
if (condition.operand2 && condition.operand2.type && condition.operand2.type === "const") {
|
|
369
344
|
operand2_s = TiledeskExpression.stringValueOperand(condition.operand2.value, variables);
|
|
@@ -374,41 +349,32 @@ class TiledeskExpression {
|
|
|
374
349
|
operand2_s = TiledeskExpression.variableOperand(condition.operand2.name);
|
|
375
350
|
}
|
|
376
351
|
else {
|
|
377
|
-
|
|
352
|
+
winston.error("(TiledeskExpression)Condition evaluation stopped because of invalid operand2 " + condition.operand2);
|
|
378
353
|
return null;
|
|
379
354
|
}
|
|
380
355
|
}
|
|
381
356
|
else {
|
|
382
|
-
|
|
357
|
+
winston.error("(TiledeskExpression) Condition evaluation stopped because of: No operand2 on condition ", condition);
|
|
383
358
|
return null;
|
|
384
359
|
}
|
|
385
360
|
|
|
386
|
-
// console.log("operand1_s, operand2_s:",operand1_s, operand2_s);
|
|
387
361
|
const expression = applyPattern.replace("#1", operand1_s).replace("#2", operand2_s);
|
|
388
|
-
// console.log("operand1_s is:", operand1_s);
|
|
389
|
-
// console.log("operand2_s is:", operand2_s);
|
|
390
|
-
// console.log("expression is:", expression);
|
|
391
362
|
return expression;
|
|
392
363
|
}
|
|
393
364
|
|
|
394
365
|
static JSONGroupToExpression(group, variables) {
|
|
395
|
-
// console.log("attributes:", variables);
|
|
396
366
|
let conditions = group.conditions;
|
|
397
367
|
let group_expression = "";
|
|
398
|
-
// console.log("conditions:", conditions)
|
|
399
368
|
for(let i = 0; i < conditions.length; i++) {
|
|
400
369
|
let part = conditions[i];
|
|
401
370
|
if (part.type === "condition") {
|
|
402
371
|
let expression = TiledeskExpression.JSONConditionToExpression(part, variables);
|
|
403
|
-
// console.log("returned expression:", expression);
|
|
404
372
|
if (expression === null) {
|
|
405
|
-
// console.error("Invalid JSON expression", JSON.stringify(part));
|
|
406
373
|
return null;
|
|
407
374
|
}
|
|
408
375
|
group_expression += expression;
|
|
409
376
|
}
|
|
410
377
|
else if (part.type === "operator") {
|
|
411
|
-
// console.log("operator part:", part);
|
|
412
378
|
const operator = TiledeskExpression.OPERATORS[part.operator];
|
|
413
379
|
group_expression += operator.applyPattern;
|
|
414
380
|
}
|
|
@@ -418,13 +384,12 @@ class TiledeskExpression {
|
|
|
418
384
|
|
|
419
385
|
static JSONGroupsToExpression(groups, variables) {
|
|
420
386
|
let full_expression = "";
|
|
421
|
-
// console.log("groups:", groups)
|
|
422
387
|
for(let i = 0; i < groups.length; i++) {
|
|
423
388
|
let g = groups[i];
|
|
424
389
|
if (g.type === "expression") {
|
|
425
390
|
let group_expression = TiledeskExpression.JSONGroupToExpression(g, variables);
|
|
426
391
|
if (group_expression === null) {
|
|
427
|
-
|
|
392
|
+
winston.error("(TiledeskExpression) Invalid JSON Group expression ", g);
|
|
428
393
|
return null;
|
|
429
394
|
}
|
|
430
395
|
full_expression += group_expression;
|
|
@@ -443,11 +408,8 @@ class TiledeskExpression {
|
|
|
443
408
|
}
|
|
444
409
|
|
|
445
410
|
static validateVariableName(variableName) {
|
|
446
|
-
// console.log("variableName", variableName)
|
|
447
|
-
// console.log("type of variableName:", typeof variableName);
|
|
448
411
|
// let matches = variableName.match(/^[a-zA-Z_]*[a-zA-Z_]+[a-zA-Z0-9_]*$/gm);
|
|
449
412
|
let matches = variableName.match(/^[a-zA-Z_]+.*$/gm);
|
|
450
|
-
// console.log("matches:", matches)
|
|
451
413
|
if (matches !== null) {
|
|
452
414
|
return true;
|
|
453
415
|
}
|
|
@@ -466,13 +428,10 @@ class TiledeskExpression {
|
|
|
466
428
|
return TiledeskExpression.quotedString(operand);
|
|
467
429
|
}
|
|
468
430
|
else {
|
|
469
|
-
// console.log("vars!", variables)
|
|
470
431
|
let _operand = operand.trim();
|
|
471
432
|
let operandAsString = TiledeskExpression.quotedString(operand); //"\"" + JSON.stringify(operand) + "\"";
|
|
472
433
|
if (_operand.startsWith("$")) {
|
|
473
|
-
// console.log("_operand with $", _operand);
|
|
474
434
|
let varName = _operand.replace(/\$/g, "");
|
|
475
|
-
// console.log("varName:", varName);
|
|
476
435
|
let value = variables[varName];
|
|
477
436
|
if (value) {
|
|
478
437
|
operandAsString = TiledeskExpression.quotedString(value); //'"' + JSON.stringify(value) + '"';
|