@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
@@ -2,6 +2,7 @@
2
2
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
3
3
  const { DirIntent } = require('./DirIntent');
4
4
  const ms = require('minimist-string');
5
+ const winston = require('../../utils/winston');
5
6
 
6
7
  class DirIfOnlineAgents {
7
8
 
@@ -25,6 +26,7 @@ class DirIfOnlineAgents {
25
26
  }
26
27
 
27
28
  execute(directive, callback) {
29
+ winston.verbose("Execute IfOnlineAgents directive");
28
30
  let action;
29
31
  if (directive.action) {
30
32
  action = directive.action
@@ -32,19 +34,13 @@ class DirIfOnlineAgents {
32
34
  else if (directive.parameter) {
33
35
  let params;
34
36
  params = this.parseParams(directive.parameter);
35
- // if (!params.trueIntent && !params.falseIntent) {
36
- // if (this.log) {
37
- // console.log("missing both params.trueIntent & params.falseIntent");
38
- // }
39
- // callback();
40
- // return;
41
- // }
42
37
  action = {
43
38
  trueIntent: params.trueIntent,
44
39
  falseIntent: params.falseIntent
45
40
  }
46
41
  }
47
42
  else {
43
+ winston.warn("DirIfOnlineAgents Incorrect directive: ", directive);
48
44
  callback();
49
45
  return;
50
46
  }
@@ -54,56 +50,55 @@ class DirIfOnlineAgents {
54
50
  }
55
51
 
56
52
  go(action, callback) {
53
+ winston.debug("(DirIfOnlineAgents) Action: ", action);
54
+
57
55
  if (!action.trueIntent && !action.falseIntent) {
58
- if (this.log) {
59
- console.log("Error DirIfOnlineAgents: missing both action.trueIntent & action.falseIntent");
60
- }
56
+ winston.error("(DirIfOnlineAgents) Error: missing both action.trueIntent & action.falseIntent");
61
57
  callback();
62
58
  return;
63
59
  }
64
60
  const trueIntent = action.trueIntent;
65
61
  const falseIntent = action.falseIntent;
66
- if (this.log) {
67
- console.log("(DirIfOnlineAgents) IfOnlineAgents:trueIntent:", trueIntent);
68
- console.log("(DirIfOnlineAgents) IfOnlineAgents:falseIntent:", falseIntent);
69
- }
70
62
  const trueIntentAttributes = action.trueIntentAttributes;
71
63
  const falseIntentAttributes = action.falseIntentAttributes;
64
+
65
+ winston.debug("(DirIfOnlineAgents) IfOnlineAgents:trueIntent: " + trueIntent);
66
+ winston.debug("(DirIfOnlineAgents) IfOnlineAgents:falseIntent: " + falseIntent);
67
+
72
68
  let stopOnConditionMet = action.stopOnConditionMet;
73
69
  this.tdClient.openNow((err, result) => {
74
- if (this.log) {console.log("openNow():", result);}
70
+ winston.debug("(DirIfOnlineAgents) openNow(): ", result);
75
71
  if (err) {
76
- console.error("IfOnlineAgents:tdclient.openNow Error:", err);
72
+ winston.error("(DirIfOnlineAgents) openNow Error: ", err);
77
73
  callback();
78
74
  return;
79
75
  }
80
76
  else {
81
77
  if (result && result.isopen) {
82
78
  this.tdClient.getProjectAvailableAgents((err, agents) => {
83
- if (this.log) {console.log("Agents", agents);}
84
79
  if (err) {
85
- console.error("IfOnlineAgents:Error getting available agents:", err);
80
+ winston.error("(DirIfOnlineAgents) Error getting available agents: ", err);
86
81
  callback();
87
82
  }
88
83
  else {
89
- if (this.log) {console.log("Agents count:", agents.length);}
84
+ winston.debug("(DirIfOnlineAgents) Agents count: " + agents.length);
90
85
  if (agents.length > 0) {
91
86
  if (trueIntent) {
92
87
  let intentDirective = DirIntent.intentDirectiveFor(trueIntent, trueIntentAttributes);
93
- if (this.log) {console.log("agents (openHours) => trueIntent");}
88
+ winston.debug("(DirIfOnlineAgents) agents (openHours) => trueIntent");
94
89
  this.intentDir.execute(intentDirective, () => {
95
90
  callback(stopOnConditionMet);
96
91
  });
97
92
  }
98
93
  else {
99
- console.log("NO IfOnlineAgents trueIntent defined. callback()") // prod
94
+ winston.debug("(DirIfOnlineAgents) NO IfOnlineAgents trueIntent defined. callback()") // prod
100
95
  callback();
101
96
  return;
102
97
  }
103
98
  }
104
99
  else if (falseIntent) {
105
100
  let intentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
106
- if (this.log) {console.log("!agents (openHours) => falseIntent", intentDirective);}
101
+ winston.debug("(DirIfOnlineAgents) !agents (openHours) => falseIntent: ", intentDirective);
107
102
  this.intentDir.execute(intentDirective, () => {
108
103
  callback(stopOnConditionMet);
109
104
  });
@@ -117,8 +112,7 @@ class DirIfOnlineAgents {
117
112
  else if (result && !result.isopen) {
118
113
  if (falseIntent) {
119
114
  let intentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
120
- if (this.log) {console.log("!agents (!openHours) => falseIntent");}
121
- console.log("!agents (!openHours) => falseIntent BECAUSE CLOSED"); //PROD
115
+ winston.debug("(DirIfOnlineAgents) !agents (!openHours) => falseIntent BECAUSE CLOSED"); //PROD
122
116
  this.intentDir.execute(intentDirective, () => {
123
117
  callback();
124
118
  });
@@ -128,8 +122,7 @@ class DirIfOnlineAgents {
128
122
  }
129
123
  }
130
124
  else {
131
- if (this.log) {console.log("undeterminate result.");}
132
- console.log("undeterminate result.");
125
+ winston.verbose("(DirIfOnlineAgents) undeterminate result.");
133
126
  callback();
134
127
  }
135
128
  }
@@ -4,6 +4,7 @@ const axios = require("axios").default;
4
4
  let https = require("https");
5
5
  const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
6
6
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
7
+ const winston = require('../../utils/winston');
7
8
 
8
9
  class DirIfOnlineAgentsV2 {
9
10
 
@@ -28,11 +29,13 @@ class DirIfOnlineAgentsV2 {
28
29
  }
29
30
 
30
31
  execute(directive, callback) {
32
+ winston.verbose("Execute IfOnlineAgentsV2 directive");
31
33
  let action;
32
34
  if (directive.action) {
33
35
  action = directive.action
34
36
  }
35
37
  else {
38
+ winston.warn("DirIfOnlineAgentsV2 Incorrect directive: ", directive);
36
39
  callback();
37
40
  return;
38
41
  }
@@ -42,22 +45,21 @@ class DirIfOnlineAgentsV2 {
42
45
  }
43
46
 
44
47
  async go(action, callback) {
45
- // console.log("(DirIfOnlineAgents) action:", action);
48
+ winston.debug("(DirIfOnlineAgentsV2) Action: ", action);
49
+
46
50
  if (!action.trueIntent && !action.falseIntent) {
47
- if (this.log) {
48
- console.log("Error DirIfOnlineAgents: missing both action.trueIntent & action.falseIntent");
49
- }
51
+ winston.error("(DirIfOnlineAgentsV2) Error: missing both action.trueIntent & action.falseIntent");
50
52
  callback();
51
53
  return;
52
54
  }
53
55
  const trueIntent = action.trueIntent;
54
56
  const falseIntent = action.falseIntent;
55
- if (this.log) {
56
- console.log("(DirIfOnlineAgents) IfOnlineAgents:trueIntent:", trueIntent);
57
- console.log("(DirIfOnlineAgents) IfOnlineAgents:falseIntent:", falseIntent);
58
- }
59
57
  const trueIntentAttributes = action.trueIntentAttributes;
60
58
  const falseIntentAttributes = action.falseIntentAttributes;
59
+
60
+ winston.debug("(DirIfOnlineAgentsV2) IfOnlineAgents:trueIntent: " + trueIntent);
61
+ winston.debug("(DirIfOnlineAgentsV2) IfOnlineAgents:falseIntent: " + falseIntent);
62
+
61
63
  let stopOnConditionMet = true; //action.stopOnConditionMet;
62
64
 
63
65
  try {
@@ -83,18 +85,15 @@ class DirIfOnlineAgentsV2 {
83
85
 
84
86
  let agents;
85
87
  if (selectedOption === "currentDep") {
86
- if (this.log) {console.log("(DirIfOnlineAgents) currentDep"); }
88
+ winston.debug("(DirIfOnlineAgentsV2) currentDep");
87
89
  let departmentId = await this.chatbot.getParameter("department_id");
88
- if (this.log) {console.log("this.context.departmentId:", departmentId);}
90
+ winston.debug("(DirIfOnlineAgentsV2) this.context.departmentId: " + departmentId);
89
91
 
90
92
  if (departmentId) {
91
- if (this.log) {console.log("(DirIfOnlineAgents) agents = await this.getProjectAvailableAgents(", departmentId, ", true);"); }
92
93
  agents = await this.getProjectAvailableAgents(departmentId, true);
93
- if (this.log) {console.log("(DirIfOnlineAgents) agents:", agents); }
94
94
  } else {
95
- console.error("(DirIfOnlineAgents) no departmentId found in attributes");
95
+ winston.error("(DirIfOnlineAgentsV2) no departmentId found in attributes");
96
96
  await this.chatbot.addParameter("flowError", "(If online Agents) No departmentId found in attributes.");
97
- if (this.log) {console.log("(DirIfOnlineAgents) flowError added in attributes", await this.chatbot.getParameter("flowError") ); }
98
97
  if (falseIntent) { // no agents available
99
98
  let intentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
100
99
  this.intentDir.execute(intentDirective, () => {
@@ -108,29 +107,23 @@ class DirIfOnlineAgentsV2 {
108
107
  }
109
108
  }
110
109
  }
111
- else if (selectedOption === "selectedDep") {
112
- if (this.log) {console.log("(DirIfOnlineAgents) selectedOption === selectedDep", action.selectedDepartmentId); }
113
- if (this.log) {console.log("(DirIfOnlineAgents) agents = await this.getProjectAvailableAgents(", action.selectedDepartmentId, ", true);"); }
114
-
110
+ else if (selectedOption === "selectedDep") {
115
111
  agents = await this.getProjectAvailableAgents(action.selectedDepartmentId, true);
116
- if (this.log) {console.log("(DirIfOnlineAgents) agents:", agents); }
117
112
  }
118
113
  else { // if (checkAll) => go project-wide
119
- if (this.log) {console.log("(DirIfOnlineAgents) selectedOption === all | getProjectAvailableAgents(null, true)"); }
120
114
  agents = await this.getProjectAvailableAgents(null, true);
121
- if (this.log) {console.log("(DirIfOnlineAgents) agents:", agents); }
122
115
  }
123
116
 
124
117
  if (agents && agents.length > 0) {
125
118
  if (trueIntent) {
126
119
  let intentDirective = DirIntent.intentDirectiveFor(trueIntent, trueIntentAttributes);
127
- if (this.log) {console.log("agents (openHours) => trueIntent");}
120
+ winston.debug("(DirIfOnlineAgentsV2) agents (openHours) => trueIntent");
128
121
  this.intentDir.execute(intentDirective, () => {
129
122
  callback(stopOnConditionMet);
130
123
  });
131
124
  }
132
125
  else {
133
- if (this.log) { console.log("(DirIfOnlineAgents) No IfOnlineAgents trueIntent defined. callback()"); } // prod
126
+ winston.debug("(DirIfOnlineAgentsV2) No IfOnlineAgents trueIntent defined. callback()"); // prod
134
127
  this.chatbot.addParameter("flowError", "(If online Agents) No IfOnlineAgents success path defined.");
135
128
  callback();
136
129
  return;
@@ -138,20 +131,20 @@ class DirIfOnlineAgentsV2 {
138
131
  }
139
132
  else if (falseIntent) { // no agents available
140
133
  let intentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
141
- if (this.log) {console.log("(DirIfOnlineAgents) !agents (openHours) => falseIntent", intentDirective);}
134
+ winston.debug("(DirIfOnlineAgentsV2) !agents (openHours) => falseIntent", intentDirective);
142
135
  this.intentDir.execute(intentDirective, () => {
143
136
  callback(stopOnConditionMet);
144
137
  });
145
138
  }
146
139
  else {
147
- if (this.log) {console.log("(DirIfOnlineAgents) Error: No falseIntent defined", intentDirective);}
140
+ winston.error("(DirIfOnlineAgentsV2) Error: No falseIntent defined", intentDirective);
148
141
  this.chatbot.addParameter("flowError", "(If online Agents) No path for 'no available agents' defined.");
149
142
  callback();
150
143
  }
151
144
  } else {
152
145
  if (falseIntent) {
153
146
  let intentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
154
- if (this.log) { console.log("!agents (!openHours) => falseIntent"); }
147
+ winston.debug("(DirIfOnlineAgentsV2) !agents (!openHours) => falseIntent");
155
148
  this.intentDir.execute(intentDirective, () => {
156
149
  callback();
157
150
  });
@@ -162,7 +155,7 @@ class DirIfOnlineAgentsV2 {
162
155
  }
163
156
  }
164
157
  catch(err) {
165
- console.error("(DirIfOnlineAgents) An error occurred:" + err);
158
+ winston.error("(DirIfOnlineAgentsV2) An error occurred: ", err);
166
159
  this.chatbot.addParameter("flowError", "(If online Agents) An error occurred: " + err);
167
160
  callback();
168
161
  }
@@ -171,7 +164,7 @@ class DirIfOnlineAgentsV2 {
171
164
  async openNow() {
172
165
  return new Promise( (resolve, reject) => {
173
166
  this.tdClient.openNow(async (err, result) => {
174
- if (this.log) {console.log("(DirIfOnlineAgents) openNow():", result);}
167
+ winston.debug("(DirIfOnlineAgentsV2) openNow(): ", result);
175
168
  if (err) {
176
169
  reject(err);
177
170
  }
@@ -218,10 +211,6 @@ class DirIfOnlineAgentsV2 {
218
211
  }
219
212
 
220
213
  #myrequest(options, callback) {
221
- if (this.log) {
222
- console.log("API URL:", options.url);
223
- console.log("** Options:", JSON.stringify(options));
224
- }
225
214
  let axios_options = {
226
215
  url: options.url,
227
216
  method: options.method,
@@ -231,9 +220,6 @@ class DirIfOnlineAgentsV2 {
231
220
  if (options.json !== null) {
232
221
  axios_options.data = options.json
233
222
  }
234
- if (this.log) {
235
- console.log("axios_options:", JSON.stringify(axios_options));
236
- }
237
223
  if (options.url.startsWith("https:")) {
238
224
  const httpsAgent = new https.Agent({
239
225
  rejectUnauthorized: false,
@@ -242,10 +228,6 @@ class DirIfOnlineAgentsV2 {
242
228
  }
243
229
  axios(axios_options)
244
230
  .then((res) => {
245
- if (this.log) {
246
- console.log("Response for url:", options.url);
247
- console.log("Response headers:\n", JSON.stringify(res.headers));
248
- }
249
231
  if (res && res.status == 200 && res.data) {
250
232
  if (callback) {
251
233
  callback(null, res.data);
@@ -258,7 +240,7 @@ class DirIfOnlineAgentsV2 {
258
240
  }
259
241
  })
260
242
  .catch((error) => {
261
- console.error("(DirIfOnlineAgents) Axios error: ", JSON.stringify(error));
243
+ winston.error("(DirIfOnlineAgents) Axios error: ", error.response.data);
262
244
  if (callback) {
263
245
  callback(error, null);
264
246
  }
@@ -3,6 +3,7 @@ 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');
6
7
 
7
8
  class DirIfOpenHours {
8
9
 
@@ -18,6 +19,7 @@ class DirIfOpenHours {
18
19
  }
19
20
 
20
21
  execute(directive, callback) {
22
+ winston.verbose("Execute IfOpenHours directive");
21
23
  let action;
22
24
  if (directive.action) {
23
25
  action = directive.action
@@ -26,9 +28,7 @@ class DirIfOpenHours {
26
28
  let params;
27
29
  params = this.parseParams(directive.parameter);
28
30
  if (!params.trueIntent && !params.falseIntent) {
29
- if (this.log) {
30
- console.log("missing both params.trueIntent & params.falseIntent");
31
- }
31
+ winston.warn("DirIfOpenHours both params.trueIntent & params.falseIntent");
32
32
  callback();
33
33
  return;
34
34
  }
@@ -38,6 +38,7 @@ class DirIfOpenHours {
38
38
  }
39
39
  }
40
40
  else {
41
+ winston.warn("DirIfOpenHours Incorrect directive: ", directive);
41
42
  callback();
42
43
  return;
43
44
  }
@@ -47,6 +48,7 @@ class DirIfOpenHours {
47
48
  }
48
49
 
49
50
  go(action, callback) {
51
+ winston.debug("(DirIfOpenHours) Action: ", action);
50
52
 
51
53
  const trueIntent = action.trueIntent;
52
54
  const falseIntent = action.falseIntent;
@@ -60,9 +62,9 @@ class DirIfOpenHours {
60
62
  if (falseIntent && falseIntent.trim() === "") {
61
63
  falseIntent = null;
62
64
  }
63
- if (this.log) {console.log("condition action:", action);}
65
+
64
66
  if (!trueIntent && !falseIntent) {
65
- if (this.log) {console.log("Invalid condition, no intents specified");}
67
+ winston.error("(DirIfOpenHours) Invalid condition, no intents specified");
66
68
  callback();
67
69
  return;
68
70
  }
@@ -85,20 +87,19 @@ class DirIfOpenHours {
85
87
  },
86
88
  method: 'GET'
87
89
  }
88
- if (this.log) { console.log("DirIfOpenHours HTTPREQUEST", HTTPREQUEST); }
90
+ winston.debug("(DirIfOpenHours) HttpRequest ", HTTPREQUEST);
89
91
 
90
92
  this.#myrequest(
91
93
  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
94
 
95
+ winston.debug("(DirIfOpenHours) resbody:", resbody);
96
+
97
97
  if (err) {
98
+ winston.debug("(DirIfOpenHours) error: ", err);
98
99
  if (callback) {
99
100
  if (falseIntent) {
100
101
  let intentDirective = DirIntent.intentDirectiveFor(falseIntent);
101
- if (this.log) {console.log("!agents (openHours) => falseIntent", falseIntent);}
102
+ winston.debug("(DirIfOpenHours) !agents (openHours) => falseIntent " + falseIntent);
102
103
  this.intentDir.execute(intentDirective, () => {
103
104
  callback(stopOnConditionMet);
104
105
  });
@@ -108,7 +109,7 @@ class DirIfOpenHours {
108
109
  if (resbody.isopen && resbody.isopen === true) {
109
110
  if (trueIntent) {
110
111
  let intentDirective = DirIntent.intentDirectiveFor(trueIntent);
111
- if (this.log) {console.log("agents (openHours) => trueIntent");}
112
+ winston.debug("(DirIfOpenHours) agents (openHours) => trueIntent");
112
113
  this.intentDir.execute(intentDirective, () => {
113
114
  callback(stopOnConditionMet);
114
115
  });
@@ -118,7 +119,7 @@ class DirIfOpenHours {
118
119
  } else {
119
120
  if (falseIntent) {
120
121
  let intentDirective = DirIntent.intentDirectiveFor(falseIntent);
121
- if (this.log) {console.log("!agents (openHours) => falseIntent", falseIntent);}
122
+ winston.debug("(DirIfOpenHours) !agents (openHours) => falseIntent", falseIntent);
122
123
  this.intentDir.execute(intentDirective, () => {
123
124
  callback(stopOnConditionMet);
124
125
  });
@@ -131,17 +132,13 @@ class DirIfOpenHours {
131
132
  )
132
133
 
133
134
  // this.tdClient.openNow(action.slot_id, (err, result) => {
134
- // console.log("openNow():", result);
135
- // if (this.log) {console.log("openNow():", result);}
135
+
136
136
  // if (err) {
137
- // console.error("*** DirIfOpenHours Error:", err);
138
137
  // callback();
139
138
  // }
140
139
  // else if (result && result.isopen) {
141
- // console.log("yes is open")
142
140
  // if (trueIntent) {
143
141
  // let intentDirective = DirIntent.intentDirectiveFor(trueIntent);
144
- // if (this.log) {console.log("agents (openHours) => trueIntent");}
145
142
  // this.intentDir.execute(intentDirective, () => {
146
143
  // callback(stopOnConditionMet);
147
144
  // });
@@ -153,7 +150,6 @@ class DirIfOpenHours {
153
150
  // }
154
151
  // else if (falseIntent) {
155
152
  // let intentDirective = DirIntent.intentDirectiveFor(falseIntent);
156
- // if (this.log) {console.log("!agents (openHours) => falseIntent", falseIntent);}
157
153
  // this.intentDir.execute(intentDirective, () => {
158
154
  // callback(stopOnConditionMet);
159
155
  // });
@@ -165,10 +161,6 @@ class DirIfOpenHours {
165
161
  }
166
162
 
167
163
  #myrequest(options, callback) {
168
- if (this.log) {
169
- console.log("API URL:", options.url);
170
- console.log("** Options:", JSON.stringify(options));
171
- }
172
164
  let axios_options = {
173
165
  url: options.url,
174
166
  method: options.method,
@@ -178,9 +170,6 @@ class DirIfOpenHours {
178
170
  if (options.json !== null) {
179
171
  axios_options.data = options.json
180
172
  }
181
- if (this.log) {
182
- console.log("axios_options:", JSON.stringify(axios_options));
183
- }
184
173
  if (options.url.startsWith("https:")) {
185
174
  const httpsAgent = new https.Agent({
186
175
  rejectUnauthorized: false,
@@ -188,11 +177,7 @@ class DirIfOpenHours {
188
177
  axios_options.httpsAgent = httpsAgent;
189
178
  }
190
179
  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
- }
180
+ .then((res) => {
196
181
  if (res && res.status == 200 && res.data) {
197
182
  if (callback) {
198
183
  callback(null, res.data);
@@ -205,7 +190,7 @@ class DirIfOpenHours {
205
190
  }
206
191
  })
207
192
  .catch((error) => {
208
- console.error("(DirIfOpenHours) Axios error: ", JSON.stringify(error));
193
+ winston.error("(DirIfOpenHours) Axios error: ", error);
209
194
  if (callback) {
210
195
  callback(error, null);
211
196
  }
@@ -2,6 +2,7 @@ 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');
5
6
 
6
7
  class DirIntent {
7
8
 
@@ -18,10 +19,8 @@ class DirIntent {
18
19
  }
19
20
 
20
21
  execute(directive, callback) {
21
- // console.log("exec intent:", JSON.stringify(directive));
22
22
  let action;
23
23
  if (directive.action) {
24
- // console.log("got intent action:", JSON.stringify(directive.action));
25
24
  action = directive.action;
26
25
  }
27
26
  else if (directive.parameter && directive.parameter.trim() !== "") {
@@ -30,7 +29,7 @@ class DirIntent {
30
29
  }
31
30
  }
32
31
  else {
33
- console.error("Incorrect directive:", directive);
32
+ winston.error("DirIntent Incorrect directive:", directive);
34
33
  callback();
35
34
  return;
36
35
  }
@@ -40,10 +39,7 @@ class DirIntent {
40
39
  }
41
40
 
42
41
  go(action, callback) {
43
- // console.log("action intent:", action);
44
42
  const intentName = action.intentName;
45
- // const intentId = action.intentId;
46
- //console.log("new_supportRequest", JSON.stringify(this.supportRequest));
47
43
  const projectId = this.supportRequest.id_project;
48
44
  const requestId = this.supportRequest.request_id;
49
45
  const botId = this.supportRequest.bot_id;
@@ -51,17 +47,11 @@ class DirIntent {
51
47
  if (intentName) {
52
48
  intent_command = "/" + intentName;
53
49
  }
54
- // else if (intentId) {
55
- // intent_command = "/#" + intentId;
56
- // }
57
50
  else {
58
- // console.error("(DirIntent) No intent name found in action");
59
51
  callback();
60
52
  return;
61
53
  }
62
54
 
63
- // if (intentName) {
64
- // let intent_command = "/" + intentName;
65
55
  let intent_command_request = {
66
56
  "payload": {
67
57
  "_id": uuidv4(),
@@ -71,26 +61,21 @@ class DirIntent {
71
61
  "recipient": requestId,
72
62
  "text": intent_command,
73
63
  "id_project": projectId,
74
- "request": {
75
- "request_id": requestId,
76
- "id_project": projectId
77
- // "bot_id": botId
78
- }
64
+ "request": this.supportRequest,
65
+ // "request": {
66
+ // "request_id": requestId,
67
+ // "id_project": projectId
68
+ // // "bot_id": botId
69
+ // }
79
70
  },
80
71
  "token": this.token
81
72
  }
82
- if (this.log) {console.log("move to intent message:", intent_command_request);}
83
-
73
+ winston.debug("DirIntent move to intent message: ", intent_command_request);
84
74
 
85
75
  this.sendMessageToBot(this.TILEBOT_ENDPOINT, intent_command_request, botId, () => {
86
- // console.log("sendMessageToBot() req_body sent:", intent_command_request);
87
76
  callback(true);
88
77
  });
89
78
 
90
- // }
91
- // else {
92
- // callback();
93
- // }
94
79
  }
95
80
 
96
81
  static intentDirectiveFor(intent, json_params) {
@@ -100,7 +85,7 @@ class DirIntent {
100
85
  string_params = JSON.stringify(json_params);
101
86
  }
102
87
  catch (error) {
103
- console.error("Error stringigying JSON PARAMS", json_params);
88
+ winston.error("(DirIfOpenHours) Error stringing JSON PARAMS ", json_params);
104
89
  }
105
90
  }
106
91
  if (string_params != null) {
@@ -134,7 +119,6 @@ class DirIntent {
134
119
  */
135
120
  sendMessageToBot(TILEBOT_ENDPOINT, message, botId, callback) {
136
121
  const url = `${TILEBOT_ENDPOINT}/ext/${botId}`;
137
- // console.log("sendMessageToBot URL", url);
138
122
  const HTTPREQUEST = {
139
123
  url: url,
140
124
  headers: {
@@ -161,10 +145,9 @@ class DirIntent {
161
145
  }
162
146
 
163
147
  myrequest(options, callback, log) {
164
- if (this.log) {
165
- console.log("API URL:", options.url);
166
- console.log("** Options:", JSON.stringify(options));
167
- }
148
+ winston.debug("DirIntent API URL:" + options.url);
149
+ winston.debug("DirIntent Options:", options);
150
+
168
151
  let axios_options = {
169
152
  url: options.url,
170
153
  method: options.method,
@@ -181,8 +164,8 @@ class DirIntent {
181
164
  axios(axios_options)
182
165
  .then((res) => {
183
166
  if (this.log) {
184
- console.log("Response for url:", options.url);
185
- console.log("Response headers:\n", JSON.stringify(res.headers));
167
+ winston.debug("DirIntent Response for url: " + options.url);
168
+ winston.debug("DirIntentResponse headers:\n", res.headers);
186
169
  }
187
170
  if (res && res.status == 200 && res.data) {
188
171
  if (callback) {
@@ -196,7 +179,7 @@ class DirIntent {
196
179
  }
197
180
  })
198
181
  .catch( (error) => {
199
- console.error("(DirIntent) Axios error: ", JSON.stringify(error));
182
+ winston.error("(DirIntent) Axios error: ", error.response.data);
200
183
  if (callback) {
201
184
  callback(error, null, null);
202
185
  }