@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.
Files changed (100) hide show
  1. package/ExtApi.js +4 -83
  2. package/ExtUtil.js +0 -1
  3. package/Logger.js +105 -0
  4. package/TdCache.js +5 -3
  5. package/TiledeskClientTest.js +5 -28
  6. package/TiledeskExpression.js +6 -47
  7. package/{models → engine}/IntentForm.js +30 -44
  8. package/{models → engine}/IntentsMachineFactory.js +5 -4
  9. package/{models → engine}/MongodbBotsDataSource.js +31 -55
  10. package/{models → engine}/MongodbIntentsMachine.js +6 -5
  11. package/{models → engine}/TiledeskChatbot.js +82 -259
  12. package/{models → engine}/TiledeskChatbotConst.js +9 -0
  13. package/{models → engine}/TiledeskIntentsMachine.js +5 -15
  14. package/{models → engine/mock}/MockBotsDataSource.js +3 -19
  15. package/{models → engine/mock}/MockTdCache.js +0 -9
  16. package/index.js +103 -380
  17. package/logs/app.log +12723 -277
  18. package/logs/app1.log +62258 -0
  19. package/logs/app2.log +46280 -0
  20. package/logs/app3.log +31686 -0
  21. package/logs/app4.log +46163 -0
  22. package/logs/app5.log +33173 -0
  23. package/models/faq.js +2 -5
  24. package/package.json +5 -2
  25. package/{TiledeskServices → services}/AIService.js +4 -3
  26. package/{models/faqKbService.js → services/FaqKbService.js} +1 -2
  27. package/{models/faqService.js → services/FaqService.js} +4 -3
  28. package/services/IntegrationService.js +43 -0
  29. package/services/TilebotService.js +47 -0
  30. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +49 -135
  31. package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +8 -14
  32. package/tiledeskChatbotPlugs/Filler.js +0 -1
  33. package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +12 -20
  34. package/tiledeskChatbotPlugs/MessagePipeline.js +5 -15
  35. package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +4 -13
  36. package/tiledeskChatbotPlugs/TiledeskRequestVariables.js +1 -1
  37. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +21 -89
  38. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirSetAttribute.js +1 -1
  39. package/tiledeskChatbotPlugs/directives/DirAddTags.js +23 -140
  40. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +42 -128
  41. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +37 -127
  42. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +52 -145
  43. package/tiledeskChatbotPlugs/directives/DirAssign.js +12 -23
  44. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +16 -12
  45. package/tiledeskChatbotPlugs/directives/DirAssistant.js +56 -198
  46. package/tiledeskChatbotPlugs/directives/DirBrevo.js +41 -101
  47. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +9 -19
  48. package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +1 -1
  49. package/tiledeskChatbotPlugs/directives/DirClose.js +4 -2
  50. package/tiledeskChatbotPlugs/directives/DirCode.js +16 -23
  51. package/tiledeskChatbotPlugs/directives/DirCondition.js +19 -25
  52. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -82
  53. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +10 -22
  54. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +34 -89
  55. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +17 -22
  56. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +8 -8
  57. package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -12
  58. package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +2 -6
  59. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -4
  60. package/tiledeskChatbotPlugs/directives/DirForm.js +17 -24
  61. package/tiledeskChatbotPlugs/directives/DirGptTask.js +49 -139
  62. package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +8 -53
  63. package/tiledeskChatbotPlugs/directives/DirHubspot.js +31 -91
  64. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
  65. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +24 -78
  66. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -68
  67. package/tiledeskChatbotPlugs/directives/DirIntent.js +6 -100
  68. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +15 -14
  69. package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
  70. package/tiledeskChatbotPlugs/directives/DirMake.js +21 -53
  71. package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
  72. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +8 -87
  73. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +6 -4
  74. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +6 -4
  75. package/tiledeskChatbotPlugs/directives/DirQapla.js +26 -120
  76. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +11 -19
  77. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
  78. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +5 -2
  79. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +12 -58
  80. package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +11 -57
  81. package/tiledeskChatbotPlugs/directives/DirReply.js +36 -30
  82. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +30 -72
  83. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +9 -10
  84. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +15 -40
  85. package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +8 -5
  86. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +25 -113
  87. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
  88. package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
  89. package/tiledeskChatbotPlugs/directives/DirWait.js +5 -6
  90. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +14 -49
  91. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +22 -77
  92. package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +1 -1
  93. package/tiledeskChatbotPlugs/directives/DirWebResponse.js +11 -14
  94. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +13 -42
  95. package/tiledeskChatbotPlugs/directives/Directives.js +0 -3
  96. package/utils/HttpUtils.js +128 -0
  97. package/{models → utils}/TiledeskChatbotUtil.js +164 -234
  98. package/utils/winston.js +42 -0
  99. package/TiledeskServices/utils.js +0 -99
  100. /package/{models → engine/mock}/MockIntentsMachine.js +0 -0
package/ExtApi.js CHANGED
@@ -1,5 +1,7 @@
1
1
  let axios = require('axios');
2
2
  let https = require("https");
3
+ const winston = require('./utils/winston');
4
+ const httpUtils = require('./utils/HttpUtils');
3
5
 
4
6
  class ExtApi {
5
7
 
@@ -38,7 +40,7 @@ class ExtApi {
38
40
  sendSupportMessageExt(message, projectId, requestId, token, callback) {
39
41
  const jwt_token = this.fixToken(token);
40
42
  const url = `${this.TILEBOT_ENDPOINT}/ext/${projectId}/requests/${requestId}/messages`;
41
- if (this.log) {console.log("sendSupportMessageExt URL", url);}
43
+ winston.verbose("(ExtApi) sendSupportMessageExt URL" + url);
42
44
  const HTTPREQUEST = {
43
45
  url: url,
44
46
  headers: {
@@ -48,12 +50,10 @@ class ExtApi {
48
50
  json: message,
49
51
  method: 'POST'
50
52
  };
51
- this.myrequest(
53
+ httpUtils.request(
52
54
  HTTPREQUEST,
53
55
  function(err, resbody) {
54
- //console.log("sendSupportMessageExt resbody:", resbody);
55
56
  if (err) {
56
- //console.error("sendSupportMessageExt error:", err)
57
57
  if (callback) {
58
58
  callback(err);
59
59
  }
@@ -67,85 +67,6 @@ class ExtApi {
67
67
  );
68
68
  }
69
69
 
70
- /**
71
- * A stub to send message to the "ext/botId" endpoint, hosted by tilebot on:
72
- * /${TILEBOT_ROUTE}/ext/${botId}
73
- *
74
- * @param {Object} message. The message to send
75
- * @param {string} botId. Tiledesk botId
76
- * @param {string} token. User token
77
- */
78
- // sendMessageToBot(message, botId, token, callback) {
79
- // const url = `${this.ENDPOINT}/ext/${botId}`;
80
- // if (this.log) {console.log("sendMessageToBot URL", url);}
81
- // const HTTPREQUEST = {
82
- // url: url,
83
- // headers: {
84
- // 'Content-Type' : 'application/json',
85
- // 'Authorization': jwt_token
86
- // },
87
- // json: message,
88
- // method: 'POST'
89
- // };
90
- // this.myrequest(
91
- // HTTPREQUEST,
92
- // function(err, resbody) {
93
- // if (err) {
94
- // if (callback) {
95
- // callback(err);
96
- // }
97
- // }
98
- // else {
99
- // if (callback) {
100
- // callback(null, resbody);
101
- // }
102
- // }
103
- // }, this.log
104
- // );
105
- // }
106
-
107
- myrequest(options, callback, log) {
108
- if (this.log) {
109
- console.log("API URL:", options.url);
110
- console.log("** Options:", JSON.stringify(options));
111
- }
112
- let axios_options = {
113
- url: options.url,
114
- method: options.method,
115
- data: options.json,
116
- params: options.params,
117
- headers: options.headers
118
- }
119
- if (options.url.startsWith("https:")) {
120
- const httpsAgent = new https.Agent({
121
- rejectUnauthorized: false,
122
- });
123
- axios_options.httpsAgent = httpsAgent;
124
- }
125
- axios(axios_options)
126
- .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
- if (res && res.status == 200 && res.data) {
132
- if (callback) {
133
- callback(null, res.data);
134
- }
135
- }
136
- else {
137
- if (callback) {
138
- callback(TiledeskClient.getErr({message: "Response status not 200"}, options, res), null, null);
139
- }
140
- }
141
- })
142
- .catch( (error) => {
143
- console.error("(ExtApi) An error occurred:", JSON.stringify(error));
144
- if (callback) {
145
- callback(error, null, null);
146
- }
147
- });
148
- }
149
70
  }
150
71
 
151
72
  module.exports = { ExtApi };
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,105 @@
1
+ let { Publisher } = require("@tiledesk/tiledesk-multi-worker");
2
+
3
+ const FLOW_LOGS_ENABLED = process.env.FLOW_LOGS_ENABLED;
4
+ const AMQP_MANAGER_URL = process.env.AMQP_MANAGER_URL;
5
+ let publisher = new Publisher(AMQP_MANAGER_URL, {
6
+ debug: false,
7
+ queueName: "logs_queue",
8
+ exchange: "tiledesk-multi",
9
+ topic: "logs",
10
+ })
11
+
12
+ class Logger {
13
+
14
+ constructor(config) {
15
+
16
+ if (!config) {
17
+ throw new Error('config is mandatory');
18
+ }
19
+
20
+ if (!config.request_id) {
21
+ console.error('config.request_id is mandatory');
22
+ //throw new Error('config.request_id is mandatory');
23
+ }
24
+
25
+ if (!FLOW_LOGS_ENABLED || FLOW_LOGS_ENABLED === false || FLOW_LOGS_ENABLED === 'false') {
26
+ console.warn("(Logger) Flow logs disabled");
27
+ this._disableMethods();
28
+ }
29
+
30
+ if (!AMQP_MANAGER_URL) {
31
+ console.warn("(Logger) No AQMP Manager url provided. Flow logs disabled");
32
+ this._disableMethods();
33
+ }
34
+
35
+ this.request_id = config.request_id;
36
+ this.dev = false;
37
+ if (config.dev && config.dev === true) {
38
+ this.dev = true;
39
+ }
40
+
41
+ // if (!AMQP_MANAGER_URL) {
42
+ // console.error('AMQP_MANAGER_URL is undefined. Logger not available...');
43
+ // return;
44
+ // //throw new Error("Error starting logger: AMQP_MANAGER_URL is undefined.")
45
+ // }
46
+
47
+ }
48
+
49
+ error(...args) {
50
+ let log = this.formatLog(args);
51
+ return this.base('error', log);
52
+ }
53
+
54
+ warn(...args) {
55
+ let log = this.formatLog(args);
56
+ return this.base('warn', log);
57
+ }
58
+
59
+ info(...args) {
60
+ let log = this.formatLog(args);
61
+ return this.base('info', log);
62
+ }
63
+
64
+ debug(...args) {
65
+ let log = this.formatLog(args);
66
+ return this.base('debug', log);
67
+ }
68
+
69
+ base(level, text) {
70
+ if (!this.request_id || !publisher) {
71
+ console.log("Return because request or publisher is undefined", this.request_id, publisher);
72
+ return;
73
+ }
74
+
75
+ let data = {
76
+ request_id: this.request_id,
77
+ text: text,
78
+ level: level,
79
+ timestamp: new Date(),
80
+ dev: this.dev
81
+ }
82
+
83
+ publisher.publish(data, (err, ok) => {
84
+ if (err) console.warn("publish log fail: ", err);
85
+ return;
86
+ })
87
+ }
88
+
89
+ formatLog(args) {
90
+ return args
91
+ .map(arg => (typeof arg === "object" ? JSON.stringify(arg, null, 2) : arg ))
92
+ .join(" ")
93
+ }
94
+
95
+ // Substitute methods with empty function if flow flogs are disabled
96
+ _disableMethods() {
97
+ const methods = ['error', 'warn', 'info', 'debug'];
98
+ methods.forEach(method => {
99
+ this[method] = () => {};
100
+ });
101
+ }
102
+
103
+ }
104
+
105
+ 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) + '"';