@tiledesk/tiledesk-tybot-connector 0.4.2 → 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.
Files changed (87) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/ExtApi.js +3 -13
  3. package/ExtUtil.js +0 -1
  4. package/Logger.js +86 -0
  5. package/TdCache.js +5 -3
  6. package/TiledeskClientTest.js +5 -28
  7. package/TiledeskExpression.js +6 -47
  8. package/index.js +87 -273
  9. package/logs/app.log +12983 -275
  10. package/logs/app1.log +62258 -0
  11. package/logs/app2.log +46280 -0
  12. package/logs/app3.log +28864 -0
  13. package/models/IntentForm.js +30 -44
  14. package/models/IntentsMachineFactory.js +4 -3
  15. package/models/MockBotsDataSource.js +1 -17
  16. package/models/MockTdCache.js +0 -9
  17. package/models/MongodbBotsDataSource.js +29 -53
  18. package/models/MongodbIntentsMachine.js +5 -4
  19. package/models/TiledeskChatbot.js +79 -258
  20. package/models/TiledeskChatbotConst.js +9 -0
  21. package/models/TiledeskChatbotUtil.js +180 -232
  22. package/models/TiledeskIntentsMachine.js +5 -14
  23. package/models/faqKbService.js +0 -1
  24. package/package.json +5 -2
  25. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +66 -139
  26. package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +7 -13
  27. package/tiledeskChatbotPlugs/Filler.js +0 -1
  28. package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +12 -20
  29. package/tiledeskChatbotPlugs/MessagePipeline.js +5 -15
  30. package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +4 -13
  31. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +21 -89
  32. package/tiledeskChatbotPlugs/directives/DirAddTags.js +15 -98
  33. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +3 -3
  34. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +32 -57
  35. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +46 -70
  36. package/tiledeskChatbotPlugs/directives/DirAssign.js +11 -22
  37. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +15 -11
  38. package/tiledeskChatbotPlugs/directives/DirAssistant.js +48 -97
  39. package/tiledeskChatbotPlugs/directives/DirBrevo.js +37 -68
  40. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +8 -18
  41. package/tiledeskChatbotPlugs/directives/DirClose.js +3 -1
  42. package/tiledeskChatbotPlugs/directives/DirCode.js +15 -22
  43. package/tiledeskChatbotPlugs/directives/DirCondition.js +18 -24
  44. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -13
  45. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +7 -19
  46. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +30 -57
  47. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +15 -20
  48. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +7 -7
  49. package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -12
  50. package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +2 -6
  51. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -4
  52. package/tiledeskChatbotPlugs/directives/DirForm.js +15 -22
  53. package/tiledeskChatbotPlugs/directives/DirGptTask.js +38 -65
  54. package/tiledeskChatbotPlugs/directives/DirHubspot.js +27 -58
  55. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
  56. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +22 -40
  57. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -32
  58. package/tiledeskChatbotPlugs/directives/DirIntent.js +16 -33
  59. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +14 -13
  60. package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
  61. package/tiledeskChatbotPlugs/directives/DirMake.js +20 -52
  62. package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
  63. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +10 -20
  64. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +4 -2
  65. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +4 -2
  66. package/tiledeskChatbotPlugs/directives/DirQapla.js +21 -50
  67. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +9 -17
  68. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
  69. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +4 -1
  70. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +10 -21
  71. package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +9 -19
  72. package/tiledeskChatbotPlugs/directives/DirReply.js +32 -35
  73. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +27 -69
  74. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +8 -9
  75. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +13 -12
  76. package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +7 -4
  77. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +22 -75
  78. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
  79. package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
  80. package/tiledeskChatbotPlugs/directives/DirWait.js +4 -5
  81. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +13 -48
  82. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +11 -76
  83. package/tiledeskChatbotPlugs/directives/DirWebResponse.js +34 -7
  84. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +11 -14
  85. package/tiledeskChatbotPlugs/directives/Directives.js +1 -3
  86. package/utils/winston.js +42 -0
  87. package/TdCache copy.js +0 -242
package/CHANGELOG.md CHANGED
@@ -5,6 +5,9 @@
5
5
  available on:
6
6
  ▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
7
7
 
8
+ # v0.5.0-rc1
9
+ - added: ability to get 'none' as bodytype in webresponse
10
+
8
11
  # v0.4.2
9
12
  - bug-fixed: minor log fix
10
13
 
@@ -17,6 +20,19 @@ available on:
17
20
  - changed: refactoring of DIrWebRequestv2
18
21
  - bug-fixed: erro while parsing webrequestv2 body
19
22
 
23
+ # v0.3.5-rc4
24
+ - added: webhook action (same as intent one)
25
+
26
+ # v0.3.5-rc3
27
+ - bug-fixed: jsonBody parse error in web-request-v2
28
+
29
+ # v0.3.5-rc2
30
+ - bug-fixed: cannot set status of undefined reading res.status in DirAssistant
31
+
32
+ # v0.3.5-rc1
33
+ - changed: refactoring web-request-v2
34
+ - bug-fixed: jsonBody parse error in web-request-v2
35
+
20
36
  # v0.3.4
21
37
  -bug-fixed: slit is undefined in TiledeskChatbotUtils
22
38
 
@@ -26,6 +42,18 @@ available on:
26
42
  # v0.3.2
27
43
  - bug-fixed: minor improvement
28
44
 
45
+ # v0.2.153-rc9
46
+ - changed: updated tiledesk-multi-worker to 0.2.1-rc2
47
+
48
+ # v0.2.153-rc8
49
+ - added: fixToken function in TiledeskService utils class
50
+
51
+ # v0.2.153-rc4
52
+ - log added
53
+
54
+ # v0.2.153-rc3
55
+ - added: specchToText function to transcript audio file
56
+
29
57
  # v0.2.153-rc1
30
58
  - changed: context for gpt-40 and gpt-40-mini
31
59
 
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
- if (this.log) {console.log("sendSupportMessageExt URL", url);}
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
- console.error("(ExtApi) An error occurred:", JSON.stringify(error));
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/Logger.js ADDED
@@ -0,0 +1,86 @@
1
+ let { Publisher } = require("@tiledesk/tiledesk-multi-worker");
2
+
3
+ const AMQP_MANAGER_URL = process.env.AMQP_MANAGER_URL;
4
+ let publisher = new Publisher(AMQP_MANAGER_URL, {
5
+ debug: false,
6
+ queueName: "logs_queue",
7
+ exchange: "tiledesk-multi",
8
+ topic: "logs",
9
+ })
10
+
11
+ class Logger {
12
+
13
+ constructor(config) {
14
+
15
+ if (!config) {
16
+ throw new Error('config is mandatory');
17
+ }
18
+
19
+ if (!config.request_id) {
20
+ console.error('config.request_id is mandatory');
21
+ //throw new Error('config.request_id is mandatory');
22
+ }
23
+
24
+ this.request_id = config.request_id;
25
+ this.dev = false;
26
+ if (config.dev && config.dev === true) {
27
+ this.dev = true;
28
+ }
29
+
30
+ if (!AMQP_MANAGER_URL) {
31
+ console.error('AMQP_MANAGER_URL is undefined. Logger not available...');
32
+ return;
33
+ //throw new Error("Error starting logger: AMQP_MANAGER_URL is undefined.")
34
+ }
35
+
36
+ }
37
+
38
+ error(...args) {
39
+ let log = this.formatLog(args);
40
+ return this.base('error', log);
41
+ }
42
+
43
+ warn(...args) {
44
+ let log = this.formatLog(args);
45
+ return this.base('warn', log);
46
+ }
47
+
48
+ info(...args) {
49
+ let log = this.formatLog(args);
50
+ return this.base('info', log);
51
+ }
52
+
53
+ debug(...args) {
54
+ let log = this.formatLog(args);
55
+ return this.base('debug', log);
56
+ }
57
+
58
+ base(level, text) {
59
+ if (!this.request_id || !publisher) {
60
+ console.log("Return because request or publisher is undefined", this.request_id, publisher);
61
+ return;
62
+ }
63
+
64
+ let data = {
65
+ request_id: this.request_id,
66
+ text: text,
67
+ level: level,
68
+ timestamp: new Date(),
69
+ dev: this.dev
70
+ }
71
+
72
+ publisher.publish(data, (err, ok) => {
73
+ if (err) console.warn("publish log fail: ", err);
74
+ return;
75
+ })
76
+ }
77
+
78
+ formatLog(args) {
79
+ return args
80
+ .map(arg => (typeof arg === "object" ? JSON.stringify(arg, null, 2) : arg ))
81
+ .join(" ")
82
+ }
83
+
84
+ }
85
+
86
+ module.exports = { Logger }
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
  }
@@ -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
- if (log) {
2430
- console.log("** API URL:", options.url);
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
- // if (log) {
2470
- console.log("Response for url:", options.url);
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
  }
@@ -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
- // console.error("(evaluateJavascriptExpression) TiledeskExpression.evaluate() error:", err.message, "- while evaluating the following expression: '" + expression + "'");
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
- console.error("Condition evaluation stopped because of invalid operand1", condition.operand1);
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
- console.error("Condition evaluation stopped because of invalid operand2", condition.operand2);
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
- console.error("Condition evaluation stopped because of: No operand2", JSON.stringify(condition));
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
- console.error("Invalid JSON Group expression", JSON.stringify(g));
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) + '"';