@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
@@ -3,6 +3,8 @@ let axios = require('axios');
3
3
  const { DirIntent } = require('./DirIntent');
4
4
  let https = require("https");
5
5
  const ms = require('minimist-string');
6
+ const winston = require('../../utils/winston');
7
+ const httpUtils = require('../../utils/HttpUtils');
6
8
 
7
9
  class DirIfOpenHours {
8
10
 
@@ -18,6 +20,7 @@ class DirIfOpenHours {
18
20
  }
19
21
 
20
22
  execute(directive, callback) {
23
+ winston.verbose("Execute IfOpenHours directive");
21
24
  let action;
22
25
  if (directive.action) {
23
26
  action = directive.action
@@ -26,9 +29,7 @@ class DirIfOpenHours {
26
29
  let params;
27
30
  params = this.parseParams(directive.parameter);
28
31
  if (!params.trueIntent && !params.falseIntent) {
29
- if (this.log) {
30
- console.log("missing both params.trueIntent & params.falseIntent");
31
- }
32
+ winston.warn("DirIfOpenHours both params.trueIntent & params.falseIntent");
32
33
  callback();
33
34
  return;
34
35
  }
@@ -38,6 +39,7 @@ class DirIfOpenHours {
38
39
  }
39
40
  }
40
41
  else {
42
+ winston.warn("DirIfOpenHours Incorrect directive: ", directive);
41
43
  callback();
42
44
  return;
43
45
  }
@@ -47,6 +49,7 @@ class DirIfOpenHours {
47
49
  }
48
50
 
49
51
  go(action, callback) {
52
+ winston.debug("(DirIfOpenHours) Action: ", action);
50
53
 
51
54
  const trueIntent = action.trueIntent;
52
55
  const falseIntent = action.falseIntent;
@@ -60,9 +63,9 @@ class DirIfOpenHours {
60
63
  if (falseIntent && falseIntent.trim() === "") {
61
64
  falseIntent = null;
62
65
  }
63
- if (this.log) {console.log("condition action:", action);}
66
+
64
67
  if (!trueIntent && !falseIntent) {
65
- if (this.log) {console.log("Invalid condition, no intents specified");}
68
+ winston.error("(DirIfOpenHours) Invalid condition, no intents specified");
66
69
  callback();
67
70
  return;
68
71
  }
@@ -85,20 +88,19 @@ class DirIfOpenHours {
85
88
  },
86
89
  method: 'GET'
87
90
  }
88
- if (this.log) { console.log("DirIfOpenHours HTTPREQUEST", HTTPREQUEST); }
91
+ winston.debug("(DirIfOpenHours) HttpRequest ", HTTPREQUEST);
89
92
 
90
- this.#myrequest(
93
+ httpUtils.request(
91
94
  HTTPREQUEST, async (err, resbody) => {
92
- if (this.log && err) {
93
- console.log("DirIfOpenHours error: ", err);
94
- }
95
- if (this.log) { console.log("DirIfOpenHours resbody:", resbody); }
96
95
 
96
+ winston.debug("(DirIfOpenHours) resbody:", resbody);
97
+
97
98
  if (err) {
99
+ winston.debug("(DirIfOpenHours) error: ", err);
98
100
  if (callback) {
99
101
  if (falseIntent) {
100
102
  let intentDirective = DirIntent.intentDirectiveFor(falseIntent);
101
- if (this.log) {console.log("!agents (openHours) => falseIntent", falseIntent);}
103
+ winston.debug("(DirIfOpenHours) !agents (openHours) => falseIntent " + falseIntent);
102
104
  this.intentDir.execute(intentDirective, () => {
103
105
  callback(stopOnConditionMet);
104
106
  });
@@ -108,7 +110,7 @@ class DirIfOpenHours {
108
110
  if (resbody.isopen && resbody.isopen === true) {
109
111
  if (trueIntent) {
110
112
  let intentDirective = DirIntent.intentDirectiveFor(trueIntent);
111
- if (this.log) {console.log("agents (openHours) => trueIntent");}
113
+ winston.debug("(DirIfOpenHours) agents (openHours) => trueIntent");
112
114
  this.intentDir.execute(intentDirective, () => {
113
115
  callback(stopOnConditionMet);
114
116
  });
@@ -118,7 +120,7 @@ class DirIfOpenHours {
118
120
  } else {
119
121
  if (falseIntent) {
120
122
  let intentDirective = DirIntent.intentDirectiveFor(falseIntent);
121
- if (this.log) {console.log("!agents (openHours) => falseIntent", falseIntent);}
123
+ winston.debug("(DirIfOpenHours) !agents (openHours) => falseIntent", falseIntent);
122
124
  this.intentDir.execute(intentDirective, () => {
123
125
  callback(stopOnConditionMet);
124
126
  });
@@ -131,17 +133,13 @@ class DirIfOpenHours {
131
133
  )
132
134
 
133
135
  // this.tdClient.openNow(action.slot_id, (err, result) => {
134
- // console.log("openNow():", result);
135
- // if (this.log) {console.log("openNow():", result);}
136
+
136
137
  // if (err) {
137
- // console.error("*** DirIfOpenHours Error:", err);
138
138
  // callback();
139
139
  // }
140
140
  // else if (result && result.isopen) {
141
- // console.log("yes is open")
142
141
  // if (trueIntent) {
143
142
  // let intentDirective = DirIntent.intentDirectiveFor(trueIntent);
144
- // if (this.log) {console.log("agents (openHours) => trueIntent");}
145
143
  // this.intentDir.execute(intentDirective, () => {
146
144
  // callback(stopOnConditionMet);
147
145
  // });
@@ -153,7 +151,6 @@ class DirIfOpenHours {
153
151
  // }
154
152
  // else if (falseIntent) {
155
153
  // let intentDirective = DirIntent.intentDirectiveFor(falseIntent);
156
- // if (this.log) {console.log("!agents (openHours) => falseIntent", falseIntent);}
157
154
  // this.intentDir.execute(intentDirective, () => {
158
155
  // callback(stopOnConditionMet);
159
156
  // });
@@ -164,54 +161,6 @@ class DirIfOpenHours {
164
161
  // });
165
162
  }
166
163
 
167
- #myrequest(options, callback) {
168
- if (this.log) {
169
- console.log("API URL:", options.url);
170
- console.log("** Options:", JSON.stringify(options));
171
- }
172
- let axios_options = {
173
- url: options.url,
174
- method: options.method,
175
- params: options.params,
176
- headers: options.headers
177
- }
178
- if (options.json !== null) {
179
- axios_options.data = options.json
180
- }
181
- if (this.log) {
182
- console.log("axios_options:", JSON.stringify(axios_options));
183
- }
184
- if (options.url.startsWith("https:")) {
185
- const httpsAgent = new https.Agent({
186
- rejectUnauthorized: false,
187
- });
188
- axios_options.httpsAgent = httpsAgent;
189
- }
190
- axios(axios_options)
191
- .then((res) => {
192
- if (this.log) {
193
- console.log("Response for url:", options.url);
194
- console.log("Response headers:\n", JSON.stringify(res.headers));
195
- }
196
- if (res && res.status == 200 && res.data) {
197
- if (callback) {
198
- callback(null, res.data);
199
- }
200
- }
201
- else {
202
- if (callback) {
203
- callback(new Error("Response status is not 200"), null);
204
- }
205
- }
206
- })
207
- .catch((error) => {
208
- console.error("(DirIfOpenHours) Axios error: ", JSON.stringify(error));
209
- if (callback) {
210
- callback(error, null);
211
- }
212
- });
213
- }
214
-
215
164
  parseParams(directive_parameter) {
216
165
  let trueIntent = null;
217
166
  let falseIntent = null;
@@ -2,6 +2,8 @@ let axios = require('axios');
2
2
  let https = require("https");
3
3
  const { v4: uuidv4 } = require('uuid');
4
4
  const ms = require('minimist-string');
5
+ const winston = require('../../utils/winston');
6
+ const tilebotService = require('../../services/TilebotService');
5
7
 
6
8
  class DirIntent {
7
9
 
@@ -18,10 +20,8 @@ class DirIntent {
18
20
  }
19
21
 
20
22
  execute(directive, callback) {
21
- // console.log("exec intent:", JSON.stringify(directive));
22
23
  let action;
23
24
  if (directive.action) {
24
- // console.log("got intent action:", JSON.stringify(directive.action));
25
25
  action = directive.action;
26
26
  }
27
27
  else if (directive.parameter && directive.parameter.trim() !== "") {
@@ -30,7 +30,7 @@ class DirIntent {
30
30
  }
31
31
  }
32
32
  else {
33
- console.error("Incorrect directive:", directive);
33
+ winston.error("DirIntent Incorrect directive:", directive);
34
34
  callback();
35
35
  return;
36
36
  }
@@ -40,10 +40,7 @@ class DirIntent {
40
40
  }
41
41
 
42
42
  go(action, callback) {
43
- // console.log("action intent:", action);
44
43
  const intentName = action.intentName;
45
- // const intentId = action.intentId;
46
- //console.log("new_supportRequest", JSON.stringify(this.supportRequest));
47
44
  const projectId = this.supportRequest.id_project;
48
45
  const requestId = this.supportRequest.request_id;
49
46
  const botId = this.supportRequest.bot_id;
@@ -51,17 +48,11 @@ class DirIntent {
51
48
  if (intentName) {
52
49
  intent_command = "/" + intentName;
53
50
  }
54
- // else if (intentId) {
55
- // intent_command = "/#" + intentId;
56
- // }
57
51
  else {
58
- // console.error("(DirIntent) No intent name found in action");
59
52
  callback();
60
53
  return;
61
54
  }
62
55
 
63
- // if (intentName) {
64
- // let intent_command = "/" + intentName;
65
56
  let intent_command_request = {
66
57
  "payload": {
67
58
  "_id": uuidv4(),
@@ -74,23 +65,16 @@ class DirIntent {
74
65
  "request": {
75
66
  "request_id": requestId,
76
67
  "id_project": projectId
77
- // "bot_id": botId
78
68
  }
79
69
  },
80
70
  "token": this.token
81
71
  }
82
- if (this.log) {console.log("move to intent message:", intent_command_request);}
72
+ winston.debug("DirIntent move to intent message: ", intent_command_request);
83
73
 
84
-
85
- this.sendMessageToBot(this.TILEBOT_ENDPOINT, intent_command_request, botId, () => {
86
- // console.log("sendMessageToBot() req_body sent:", intent_command_request);
74
+ tilebotService.sendMessageToBot(intent_command_request, botId, () => {
87
75
  callback(true);
88
76
  });
89
77
 
90
- // }
91
- // else {
92
- // callback();
93
- // }
94
78
  }
95
79
 
96
80
  static intentDirectiveFor(intent, json_params) {
@@ -100,7 +84,7 @@ class DirIntent {
100
84
  string_params = JSON.stringify(json_params);
101
85
  }
102
86
  catch (error) {
103
- console.error("Error stringigying JSON PARAMS", json_params);
87
+ winston.error("(DirIfOpenHours) Error stringing JSON PARAMS ", json_params);
104
88
  }
105
89
  }
106
90
  if (string_params != null) {
@@ -124,84 +108,6 @@ class DirIntent {
124
108
  return intentDirective;
125
109
  }
126
110
 
127
- /**
128
- * A stub to send message to the "ext/botId" endpoint, hosted by tilebot on:
129
- * /${TILEBOT_ROUTE}/ext/${botId}
130
- *
131
- * @param {Object} message. The message to send
132
- * @param {string} botId. Tiledesk botId
133
- * @param {string} token. User token
134
- */
135
- sendMessageToBot(TILEBOT_ENDPOINT, message, botId, callback) {
136
- const url = `${TILEBOT_ENDPOINT}/ext/${botId}`;
137
- // console.log("sendMessageToBot URL", url);
138
- const HTTPREQUEST = {
139
- url: url,
140
- headers: {
141
- 'Content-Type' : 'application/json'
142
- },
143
- json: message,
144
- method: 'POST'
145
- };
146
- this.myrequest(
147
- HTTPREQUEST,
148
- function(err, resbody) {
149
- if (err) {
150
- if (callback) {
151
- callback(err);
152
- }
153
- }
154
- else {
155
- if (callback) {
156
- callback(null, resbody);
157
- }
158
- }
159
- }, false
160
- );
161
- }
162
-
163
- myrequest(options, callback, log) {
164
- if (this.log) {
165
- console.log("API URL:", options.url);
166
- console.log("** Options:", JSON.stringify(options));
167
- }
168
- let axios_options = {
169
- url: options.url,
170
- method: options.method,
171
- data: options.json,
172
- params: options.params,
173
- headers: options.headers
174
- }
175
- if (options.url.startsWith("https:")) {
176
- const httpsAgent = new https.Agent({
177
- rejectUnauthorized: false,
178
- });
179
- axios_options.httpsAgent = httpsAgent;
180
- }
181
- axios(axios_options)
182
- .then((res) => {
183
- if (this.log) {
184
- console.log("Response for url:", options.url);
185
- console.log("Response headers:\n", JSON.stringify(res.headers));
186
- }
187
- if (res && res.status == 200 && res.data) {
188
- if (callback) {
189
- callback(null, res.data);
190
- }
191
- }
192
- else {
193
- if (callback) {
194
- callback(TiledeskClient.getErr({message: "Response status not 200"}, options, res), null, null);
195
- }
196
- }
197
- })
198
- .catch( (error) => {
199
- console.error("(DirIntent) Axios error: ", JSON.stringify(error));
200
- if (callback) {
201
- callback(error, null, null);
202
- }
203
- });
204
- }
205
111
  }
206
112
 
207
113
  module.exports = { DirIntent };
@@ -1,6 +1,7 @@
1
1
  const { DirIntent } = require('./DirIntent');
2
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
2
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
3
3
  const { TiledeskExpression } = require('../../TiledeskExpression');
4
+ const winston = require('../../utils/winston');
4
5
 
5
6
  class DirJSONCondition {
6
7
 
@@ -16,12 +17,13 @@ class DirJSONCondition {
16
17
  }
17
18
 
18
19
  execute(directive, callback) {
19
- // console.log("Condition...")
20
+ winston.verbose("Execute JSONCondition directive");
20
21
  let action;
21
22
  if (directive.action) {
22
23
  action = directive.action
23
24
  }
24
25
  else {
26
+ winston.warn("DirJSONCondition Incorrect directive: ", directive);
25
27
  callback();
26
28
  return;
27
29
  }
@@ -32,14 +34,15 @@ class DirJSONCondition {
32
34
  }
33
35
 
34
36
  async go(action, callback) {
35
- // const groups = action.jsonCondition.groups;
37
+ winston.debug("(DirJSONCondition) Action: ", action);
38
+
36
39
  const groups = action.groups; // NEXT
37
40
  const trueIntent = action.trueIntent;
38
41
  const falseIntent = action.falseIntent;
39
42
  const trueIntentAttributes = action.trueIntentAttributes;
40
43
  const falseIntentAttributes = action.falseIntentAttributes;
41
44
  let stopOnConditionMet = true; //action.stopOnConditionMet;
42
- if (this.log) {console.log("groups:", JSON.stringify(groups));}
45
+
43
46
  if (trueIntent && trueIntent.trim() === "") {
44
47
  trueIntent = null;
45
48
  }
@@ -47,15 +50,16 @@ class DirJSONCondition {
47
50
  falseIntent = null;
48
51
  }
49
52
  if (!trueIntent && !falseIntent) {
50
- if (this.log) {console.log("Invalid jsonCondition, no intents specified");}
53
+ winston.warn("(DirJSONCondition) Invalid jsonCondition, no intents specified");
51
54
  callback();
52
55
  return;
53
56
  }
54
57
  else if (groups === null) {
55
- if (this.log) {console.log("Invalid jsonCondition, no groups.");}
58
+ winston.warn("(DirJSONCondition) Invalid jsonCondition, no groups.");
56
59
  callback();
57
60
  return;
58
61
  }
62
+
59
63
  let trueIntentDirective = null;
60
64
  if (trueIntent) {
61
65
  trueIntentDirective = DirIntent.intentDirectiveFor(trueIntent, trueIntentAttributes);
@@ -70,26 +74,24 @@ class DirJSONCondition {
70
74
  await TiledeskChatbot.allParametersStatic(
71
75
  this.context.tdcache, this.context.requestId
72
76
  );
73
- if (this.log) {console.log("Variables:", JSON.stringify(variables))}
74
77
  }
75
78
  else {
76
- console.error("(DirJSONCondition) No this.context.tdcache");
79
+ winston.error("(DirJSONCondition) No this.context.tdcache")
77
80
  }
78
81
  // const result = await this.evaluateCondition(scriptCondition, variables);
79
82
  let result;
80
83
  const expression = TiledeskExpression.JSONGroupsToExpression(groups, variables);
81
- // console.log("full json condition expression:", expression);
84
+
82
85
  result = new TiledeskExpression().evaluateStaticExpression(expression, variables);
83
- if (this.log) {console.log("executed condition:", expression, "result:", result);}
86
+ winston.debug("(DirJSONCondition) executed condition: ", expression);
84
87
  if (result === true) {
85
88
  if (trueIntentDirective) {
86
89
  this.intentDir.execute(trueIntentDirective, () => {
87
- // console.log("result === true. stopOnConditionMet?", stopOnConditionMet);
88
90
  callback(stopOnConditionMet);
89
91
  });
90
92
  }
91
93
  else {
92
- if (this.log) {console.log("No trueIntentDirective specified");}
94
+ winston.debug("(DirJSONCondition) No trueIntentDirective specified");
93
95
  callback();
94
96
  return;
95
97
  }
@@ -100,12 +102,11 @@ class DirJSONCondition {
100
102
  }
101
103
  if (falseIntentDirective) {
102
104
  this.intentDir.execute(falseIntentDirective, () => {
103
- // console.log("result === false. stopOnConditionMet?", stopOnConditionMet);
104
105
  callback(stopOnConditionMet);
105
106
  });
106
107
  }
107
108
  else {
108
- if (this.log) {console.log("No falseIntentDirective specified");}
109
+ winston.debug("(DirJSONCondition) No falseIntentDirective specified");
109
110
  callback();
110
111
  return;
111
112
  }
@@ -1,4 +1,5 @@
1
1
  const ms = require('minimist-string');
2
+ const winston = require('../../utils/winston');
2
3
 
3
4
  class DirLockIntent {
4
5
 
@@ -15,23 +16,19 @@ class DirLockIntent {
15
16
  }
16
17
 
17
18
  async execute(directive, callback) {
18
- if (this.log) {console.log("Locking intent:", JSON.stringify(directive));}
19
+ winston.verbose("Execute LockIntent directive");
19
20
  let action;
20
21
  if (directive.action) {
21
- // console.log("got intent action:", JSON.stringify(directive.action));
22
22
  action = directive.action;
23
23
  }
24
24
  else if (directive.parameter && directive.parameter.trim() !== "") {
25
25
  const params = this.parseParams(directive.parameter);
26
26
  action = {
27
- // body: {
28
- intentName: params.intentName // directive.parameter.trim()
29
- // variableName: params.variableName
30
- // }
27
+ intentName: params.intentName
31
28
  }
32
29
  }
33
30
  else {
34
- console.error("Incorrect directive:", directive);
31
+ winston.warn("DirLockIntent Incorrect directive: ", directive);
35
32
  callback();
36
33
  return;
37
34
  }
@@ -49,11 +46,11 @@ class DirLockIntent {
49
46
  }
50
47
 
51
48
  async go(action, callback) {
52
- // let intent_name = action.body.intentName;
49
+ winston.debug("(DirLockIntent) Action: ", action);
53
50
  let intent_name = action.intentName;
54
51
  // let variable_name = action.body.variableName;
55
52
  await DirLockIntent.lockIntent(this.tdcache, this.context.requestId, intent_name); //, variable_name);
56
- if (this.log) {console.log("Locked intent:", action.intentName);}
53
+ winston.debug("(DirLockIntent) Locked intent:", action.intentName);
57
54
  if (callback) {
58
55
  callback();
59
56
  }
@@ -64,14 +61,12 @@ class DirLockIntent {
64
61
  await tdcache.set("tilebot:requests:" + requestId + ":locked", intent_name);
65
62
  }
66
63
  else {
67
- console.error("lockIntent recoverable error, one of requestId:", requestId, "intent_name:", intent_name, "is not valid");
64
+ winston.error("(DirLockIntent) lockIntent recoverable error, one of requestId: " + requestId + " intent_name: " + intent_name + " is not valid");
68
65
  }
69
66
 
70
67
  // if (variable_name) {
71
- // console.log("locking intent with variable:", variable_name);
72
68
  // await this.tdcache.set("tilebot:requests:" + requestId + ":lockedValue", variable_name);
73
69
  // }
74
- // console.log("locked. Intent name:", intent_name, "intent variable:", variable_name);
75
70
  }
76
71
 
77
72
  parseParams(directive_parameter) {