@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
@@ -1,6 +1,7 @@
1
1
  const { Filler } = require('../Filler');
2
2
  const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
3
3
  const { DirIntent } = require('./DirIntent');
4
+ const winston = require('../../utils/winston');
4
5
 
5
6
  class DirCaptureUserReply {
6
7
  constructor(context) {
@@ -19,12 +20,13 @@ class DirCaptureUserReply {
19
20
  }
20
21
 
21
22
  execute(directive, callback) {
23
+ winston.verbose("Execute CaptureUserReply directive");
22
24
  let action;
23
25
  if (directive.action) {
24
26
  action = directive.action;
25
27
  }
26
28
  else {
27
- console.error("Incorrect directive:", JSON.stringify(directive));
29
+ winston.warn("DirCaptureUserReply Incorrect directive: ", directive);
28
30
  callback();
29
31
  return;
30
32
  }
@@ -34,34 +36,23 @@ class DirCaptureUserReply {
34
36
  }
35
37
 
36
38
  async go(action, callback) {
39
+ winston.debug("(DirCaptureUserReply) Action: ", action);
37
40
  const goToIntent = action.goToIntent;
38
- // console.log("(DirCaptureUserReply) goToIntent:", goToIntent);
39
41
  let lockedAction = await this.chatbot.currentLockedAction(this.requestId);
40
- // console.log("(DirCaptureUserReply) lockedAction:", lockedAction);
41
42
  if (!lockedAction) {
42
- // console.log("(DirCaptureUserReply) !lockedAction");
43
43
  const intent_name = this.reply.attributes.intent_info.intent_name
44
- const actionId = action["_tdActionId"];
45
- // console.log("(DirCaptureUserReply) intent_name:", intent_name);
46
- // console.log("(DirCaptureUserReply) actionId:", actionId);
44
+ const actionId = action["_tdActionId"];;
47
45
  await this.chatbot.lockIntent(this.requestId, intent_name);
48
- // console.log("(DirCaptureUserReply) lockIntent");
49
46
  await this.chatbot.lockAction(this.requestId, actionId);
50
- // console.log("(DirCaptureUserReply) lockAction");
51
- // let _lockedAction = await this.chatbot.currentLockedAction(this.requestId);
52
- // let _lockedIntent = await this.chatbot.currentLockedIntent(this.requestId);
53
- // console.log("(DirCaptureUserReply) _lockedAction", _lockedAction)
54
- // console.log("(DirCaptureUserReply) _lockedIntent", _lockedIntent)
55
47
  callback();
56
48
  return;
57
49
  } else {
58
50
  try {
59
51
  await this.chatbot.unlockIntent(this.requestId);
60
52
  await this.chatbot.unlockAction(this.requestId);
61
- // console.log("unlo")
62
53
  }
63
54
  catch(e) {
64
- console.error("Error", e)
55
+ winston.error("(DirCaptureUserReply) Error: ", e)
65
56
  }
66
57
 
67
58
  }
@@ -69,13 +60,12 @@ class DirCaptureUserReply {
69
60
  const user_reply = this.message.text;
70
61
  if (this.context.tdcache) {
71
62
  if (action.assignResultTo) {
72
- if (this.log) {console.log("assign assignResultTo:", action.assignResultTo);}
63
+ winston.debug("(DirCaptureUserReply) assign assignResultTo: " + action.assignResultTo);
73
64
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignResultTo, user_reply);
74
65
  }
75
66
  }
76
67
 
77
68
  if (callback) {
78
- // console.log("(DirCaptureUserReply) #executeGoTo(goToIntent)", goToIntent)
79
69
  if (goToIntent) {
80
70
  this.#executeGoTo(goToIntent, () => {
81
71
  callback(); // continue the flow
@@ -88,7 +78,7 @@ class DirCaptureUserReply {
88
78
  }
89
79
  }
90
80
  catch(error) {
91
- console.error("error is", error);
81
+ winston.error("(DirCaptureUserReply) error: ", error);
92
82
  }
93
83
  }
94
84
 
@@ -1,6 +1,7 @@
1
1
 
2
2
  const { TiledeskClient } = require("@tiledesk/tiledesk-client");
3
3
  const { TiledeskChatbotConst } = require("../../models/TiledeskChatbotConst");
4
+ const winston = require('../../utils/winston');
4
5
 
5
6
  class DirClose {
6
7
 
@@ -24,9 +25,10 @@ class DirClose {
24
25
  }
25
26
 
26
27
  execute(directive, callback) {
28
+ winston.verbose("Execute Close directive");
27
29
  this.tdClient.closeRequest(this.requestId, async (err) => {
28
30
  if (err) {
29
- console.error("Error in 'close directive':", err);
31
+ winston.error("(DirClose) Error: ", err);
30
32
  }
31
33
  else {
32
34
  await this.chatbot.deleteParameter(TiledeskChatbotConst.USER_INPUT);
@@ -1,6 +1,7 @@
1
1
  const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
2
2
  const { TiledeskExpression } = require('../../TiledeskExpression');
3
3
  const { TiledeskRequestVariables } = require('../TiledeskRequestVariables');
4
+ const winston = require('../../utils/winston');
4
5
 
5
6
  class DirCode {
6
7
 
@@ -13,11 +14,13 @@ class DirCode {
13
14
  }
14
15
 
15
16
  execute(directive, callback) {
17
+ winston.verbose("Execute Code directive");
16
18
  let action;
17
19
  if (directive.action) {
18
20
  action = directive.action
19
21
  }
20
22
  else {
23
+ winston.warn("DirCode Incorrect directive: ", directive);
21
24
  callback();
22
25
  return;
23
26
  }
@@ -28,10 +31,10 @@ class DirCode {
28
31
  }
29
32
 
30
33
  async go(action, callback) {
31
- // console.log("action.source:", action.source)
34
+ winston.debug("(DirCode) Action: ", action);
32
35
  const source_code = action.source;
33
36
  if (!source_code || source_code.trim() === "") {
34
- if (this.log) {console.log("Invalid source_code");}
37
+ winston.error("(DirCode) Invalid source_code");
35
38
  callback();
36
39
  return;
37
40
  }
@@ -44,44 +47,34 @@ class DirCode {
44
47
  await TiledeskChatbot.allParametersStatic(
45
48
  this.context.tdcache, this.context.requestId
46
49
  );
47
- if (this.log) {console.log("Attributes:", JSON.stringify(attributes))}
50
+ winston.debug("(DirCode) Attributes:", attributes)
48
51
  }
49
52
  else {
50
- console.error("(DirCode) No this.context.tdcache");
53
+ winston.error("(DirCode) No this.context.tdcache");
51
54
  callback();
52
55
  return;
53
56
  }
54
- // console.log("before variables:", variables);
55
- // for (const [key, value] of Object.entries(attributes)) {
56
- // script_context[key] = value;
57
- // }
57
+
58
58
  let variablesManager = new TiledeskRequestVariables(this.context.requestId, this.context.tdcache, attributes);
59
59
  script_context.context = variablesManager;
60
- // console.log("script_context:", script_context);
60
+
61
61
  const tdExpression = new TiledeskExpression();
62
- //console.log("tdExpression:", tdExpression.evaluateJavascriptExpression);
62
+
63
63
  try {
64
64
  const result = new TiledeskExpression().evaluateJavascriptExpression(source_code, script_context);
65
- // console.log("result:", result);
66
- // console.log("script_context.tiledeskVars:", script_context.tiledeskVars);
67
- for (const [key, value] of Object.entries(script_context.context.ops.set)) {
68
- // await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, key, value);
69
- // await variablesManager.set(key, value);
65
+
66
+ for (const [key, value] of Object.entries(script_context.context.ops.set)) {;
70
67
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, key, value);
71
68
  }
72
- // if (this.log) {
73
- // let newvars_set = await variablesManager.all();
74
- // console.log("newvars_set:", newvars_set);
75
- // }
76
69
  for (const [key, value] of Object.entries(script_context.context.ops.del)) {
77
- // await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, key, value);
78
70
  await variablesManager.delete(key);
79
71
  }
72
+
80
73
  const newvars_del = await variablesManager.all();
81
- // console.log("newvars_del:", newvars_del);
74
+
82
75
  }
83
76
  catch(err) {
84
- console.error("(DirCode) An error occurred:", err);
77
+ winston.error("(DirCode) An error occurred: ", err);
85
78
  }
86
79
  callback();
87
80
  return;
@@ -2,6 +2,7 @@ const { DirIntent } = require('./DirIntent');
2
2
  const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
3
3
  const { TiledeskExpression } = require('../../TiledeskExpression');
4
4
  const ms = require('minimist-string');
5
+ const winston = require('../../utils/winston');
5
6
 
6
7
  class DirCondition {
7
8
 
@@ -15,7 +16,7 @@ class DirCondition {
15
16
  }
16
17
 
17
18
  execute(directive, callback) {
18
- // console.log("Condition...")
19
+ winston.verbose("Execute Condition directive");
19
20
  let action;
20
21
  if (directive.action) {
21
22
  action = directive.action
@@ -34,6 +35,7 @@ class DirCondition {
34
35
  }
35
36
  }
36
37
  else {
38
+ winston.warn("DirCondition Incorrect directive: ", directive);
37
39
  callback();
38
40
  return;
39
41
  }
@@ -44,10 +46,12 @@ class DirCondition {
44
46
  }
45
47
 
46
48
  async go(action, callback) {
49
+ winston.debug("(DirCondition) Action: ", action);
47
50
  const scriptCondition = action.scriptCondition;
48
51
  const jsonCondition = action.jsonCondition;
49
- if (this.log) {console.log("scriptCondition:", scriptCondition);}
50
- if (this.log) {console.log("jsonCondition:", JSON.stringify(jsonCondition));}
52
+ winston.debug("(DirCondition) scriptCondition:", scriptCondition);
53
+ winston.debug("(DirCondition) jsonCondition:", jsonCondition);
54
+
51
55
  // const condition = action.condition;
52
56
  let trueIntent = action.trueIntent;
53
57
  let falseIntent = action.falseIntent;
@@ -58,24 +62,24 @@ class DirCondition {
58
62
  if (falseIntent && falseIntent.trim() === "") {
59
63
  falseIntent = null;
60
64
  }
61
- if (this.log) {console.log("condition action:", action);}
65
+ winston.debug("(DirCondition) condition action: ", action);
62
66
  if (!trueIntent && !falseIntent) {
63
- if (this.log) {console.log("Invalid condition, no intents specified");}
67
+ winston.error("(DirCondition) Invalid condition, no intents specified");
64
68
  callback();
65
69
  return;
66
70
  }
67
71
  if (scriptCondition === null && jsonCondition === null) {
68
- if (this.log) {console.log("Invalid condition, scriptCondition & jsonCondition null");}
72
+ winston.error("(DirCondition) Invalid condition, scriptCondition & jsonCondition null");
69
73
  callback();
70
74
  return;
71
75
  }
72
76
  if (scriptCondition !== null && scriptCondition.trim === "") {
73
- if (this.log) {console.log("Invalid condition, scriptCondition is empty");}
77
+ winston.error("(DirCondition) Invalid condition, scriptCondition is empty");
74
78
  callback();
75
79
  return;
76
80
  }
77
81
  else if (jsonCondition && jsonCondition.groups === null) {
78
- if (this.log) {console.log("Invalid jsonCondition, no groups:", JSON.stringify(jsonCondition));}
82
+ winston.error("(DirCondition) Invalid jsonCondition, no groups:", jsonCondition);
79
83
  callback();
80
84
  return;
81
85
  }
@@ -93,12 +97,12 @@ class DirCondition {
93
97
  await TiledeskChatbot.allParametersStatic(
94
98
  this.context.tdcache, this.context.requestId
95
99
  );
96
- if (this.log) {console.log("Variables:", JSON.stringify(variables))}
100
+ winston.debug("(DirCondition) Variables:", variables)
97
101
  }
98
102
  else {
99
- console.error("(DirCondition) No this.context.tdcache");
103
+ winston.error("(DirCondition) No this.context.tdcache");
100
104
  }
101
- if (this.log) {console.log("condition:", scriptCondition);}
105
+ winston.debug("(DirCondition) condition:", scriptCondition);
102
106
  // const result = await this.evaluateCondition(scriptCondition, variables);
103
107
  let result;
104
108
  if (scriptCondition) {
@@ -107,19 +111,17 @@ class DirCondition {
107
111
  }
108
112
  else if (jsonCondition) {
109
113
  const expression = TiledeskExpression.JSONGroupsToExpression(jsonCondition.groups, variables);
110
- // console.log("full json condition expression:", expression);
111
114
  result = new TiledeskExpression().evaluateStaticExpression(expression);
112
115
  }
113
- if (this.log) {console.log("executed condition:", scriptCondition, "result:", result);}
116
+ winston.debug("(DirCondition) executed condition: " + JSON.stringify(scriptCondition) + " result: " + JSON.stringify(result));
114
117
  if (result === true) {
115
118
  if (trueIntentDirective) {
116
119
  this.intentDir.execute(trueIntentDirective, () => {
117
- // console.log("result === true. stopOnConditionMet?", stopOnConditionMet);
118
120
  callback(stopOnConditionMet);
119
121
  });
120
122
  }
121
123
  else {
122
- if (this.log) {console.log("No trueIntentDirective specified");}
124
+ winston.debug("(DirCondition) No trueIntentDirective specified");
123
125
  callback();
124
126
  return;
125
127
  }
@@ -127,12 +129,11 @@ class DirCondition {
127
129
  else {
128
130
  if (falseIntentDirective) {
129
131
  this.intentDir.execute(falseIntentDirective, () => {
130
- // console.log("result === false. stopOnConditionMet?", stopOnConditionMet);
131
132
  callback(stopOnConditionMet);
132
133
  });
133
134
  }
134
135
  else {
135
- if (this.log) {console.log("No falseIntentDirective specified");}
136
+ winston.debug("(DirCondition) No falseIntentDirective specified");
136
137
  callback();
137
138
  return;
138
139
  }
@@ -141,14 +142,7 @@ class DirCondition {
141
142
 
142
143
  // async evaluateCondition(_condition, variables) {
143
144
  // let condition = _condition.replace("$", "$data.");
144
- // if (this.log) {
145
- // console.log("Evaluating expression:", condition);
146
- // console.log("With variables:", variables);
147
- // }
148
145
  // const result = new TiledeskExpression().evaluate(condition, variables)
149
- // if (this.log) {
150
- // console.log("Expression result:", result);
151
- // }
152
146
  // return result;
153
147
  // }
154
148
 
@@ -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 DirConnectBlock {
7
8
  constructor(context) {
@@ -17,12 +18,13 @@ class DirConnectBlock {
17
18
  }
18
19
 
19
20
  execute(directive, callback) {
21
+ winston.verbose("Execute ConnectBlock directive");
20
22
  let action;
21
23
  if (directive.action) {
22
24
  action = directive.action;
23
25
  }
24
26
  else {
25
- console.error("Incorrect DirConnectBlock directive:", directive);
27
+ winston.warn("DirConnectBlock Incorrect directive: ", directive);
26
28
  callback();
27
29
  return;
28
30
  }
@@ -32,6 +34,7 @@ class DirConnectBlock {
32
34
  }
33
35
 
34
36
  go(action, callback) {
37
+ winston.debug("(DirConnectBlock) Action: ", action);
35
38
  const intentName = action.intentName;
36
39
  const projectId = this.supportRequest.id_project;
37
40
  const requestId = this.supportRequest.request_id;
@@ -61,7 +64,7 @@ class DirConnectBlock {
61
64
  },
62
65
  "token": this.token
63
66
  }
64
- if (this.log) {console.log("move to intent message:", intent_command_request);}
67
+ winston.debug("(DirConnectBlock) move to intent message: ", intent_command_request);
65
68
 
66
69
  this.sendMessageToBot(this.TILEBOT_ENDPOINT, intent_command_request, botId, () => {
67
70
  callback();
@@ -75,7 +78,7 @@ class DirConnectBlock {
75
78
  string_params = JSON.stringify(json_params);
76
79
  }
77
80
  catch (error) {
78
- console.error("Error stringigying JSON PARAMS", json_params);
81
+ winston.error("(DirConnectBlock) Error stringing JSON PARAMS: ", json_params);
79
82
  }
80
83
  }
81
84
  if (string_params != null) {
@@ -108,8 +111,9 @@ class DirConnectBlock {
108
111
  * @param {string} token. User token
109
112
  */
110
113
  sendMessageToBot(TILEBOT_ENDPOINT, message, botId, callback) {
114
+
111
115
  const url = `${TILEBOT_ENDPOINT}/ext/${botId}`;
112
- // console.log("sendMessageToBot URL", url);
116
+ winston.verbose("sendMessageToBot URL" + url);
113
117
  const HTTPREQUEST = {
114
118
  url: url,
115
119
  headers: {
@@ -136,10 +140,6 @@ class DirConnectBlock {
136
140
  }
137
141
 
138
142
  myrequest(options, callback, log) {
139
- if (this.log) {
140
- console.log("API URL:", options.url);
141
- console.log("** Options:", JSON.stringify(options));
142
- }
143
143
  let axios_options = {
144
144
  url: options.url,
145
145
  method: options.method,
@@ -155,10 +155,6 @@ class DirConnectBlock {
155
155
  }
156
156
  axios(axios_options)
157
157
  .then((res) => {
158
- if (this.log) {
159
- console.log("Response for url:", options.url);
160
- console.log("Response headers:\n", JSON.stringify(res.headers));
161
- }
162
158
  if (res && res.status == 200 && res.data) {
163
159
  if (callback) {
164
160
  callback(null, res.data);
@@ -171,7 +167,7 @@ class DirConnectBlock {
171
167
  }
172
168
  })
173
169
  .catch( (error) => {
174
- console.error("(DirConnectBlock) Axios error: ", JSON.stringify(error));
170
+ winston.error("(DirConnectBlock) Axios error: ", error.response.data);
175
171
  if (callback) {
176
172
  callback(error, null, null);
177
173
  }
@@ -4,6 +4,7 @@ const { TiledeskChatbotUtil } = require('../../models/TiledeskChatbotUtil');
4
4
  let axios = require('axios');
5
5
  const { TiledeskChatbotConst } = require('../../models/TiledeskChatbotConst');
6
6
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
7
+ const winston = require('../../utils/winston');
7
8
 
8
9
  class DirContactUpdate {
9
10
 
@@ -30,6 +31,7 @@ class DirContactUpdate {
30
31
  }
31
32
 
32
33
  execute(directive, callback) {
34
+ winston.verbose("Execute ContactUpdate directive")
33
35
  let action;
34
36
  if (directive.action) {
35
37
  action = directive.action;
@@ -39,7 +41,7 @@ class DirContactUpdate {
39
41
  action.attributes.fillParams = true;
40
42
  }
41
43
  else {
42
- console.error("Incorrect directive (no action provided):", directive);
44
+ winston.warn("DirContactUpdate Incorrect directive: ", directive);
43
45
  callback();
44
46
  return;
45
47
  }
@@ -49,7 +51,7 @@ class DirContactUpdate {
49
51
  }
50
52
 
51
53
  async go(action, callback) {
52
- if (this.log) {console.log("(DirContactUpdate) start. Update properties:", action.update); }
54
+ winston.debug("(DirContactUpdate) Action: ", action);
53
55
  const contactProperties = action.update;
54
56
 
55
57
  // fill
@@ -64,32 +66,23 @@ class DirContactUpdate {
64
66
  let updateProperties = {}
65
67
  for (const [key, value] of Object.entries(contactProperties)) {
66
68
  let filled_value = filler.fill(value, requestAttributes);
67
- if (this.log) {console.log("(DirContactUpdate) setting property key:",key, "with value:", value, "filled value:", filled_value); }
68
69
  updateProperties[key] = filled_value;
69
70
  // it's important that all the lead's properties are immediatly updated in the current flow invocation so the updated values will be available in the next actions
70
71
  if (key === "fullname") {
71
72
  await this.context.chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY, filled_value);
72
- if (this.log) {console.log("(DirContactUpdate) updating attribute:",TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY, "with property key:", key, "and value:", filled_value); }
73
73
  }
74
74
  else if ( key === "email") {
75
75
  await this.context.chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY, filled_value);
76
- if (this.log) {console.log("(DirContactUpdate) updating attribute:",TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY, "with property key:", key, "and value:", filled_value); }
77
76
  }
78
- // else if (key === "phone") {
79
- // static REQ_USER_PHONE_KEY = "userPhone";
80
- // }
81
- if (this.log) {console.log("(DirContactUpdate) updating property:", key, "value:", filled_value); }
82
77
  }
83
78
  const leadId = requestAttributes[TiledeskChatbotConst.REQ_USER_LEAD_ID_KEY];
84
79
  this.tdClient.updateLead(leadId, updateProperties, null, null, () => {
85
- if (this.log) {console.log("(DirContactUpdate) Lead updated.", updateProperties);}
86
80
  // send hidden info to update widget lead fullname only if it is a conversation!
87
- if (this.log) {console.log("(DirContactUpdate) requestId:", this.requestId); }
88
- if (this.log) {console.log("(DirContactUpdate) updateProperties:", updateProperties); }
89
- if (this.log) {console.log("(DirContactUpdate) updateProperties['fullname']:", updateProperties['fullname']); }
81
+ winston.debug("(DirContactUpdate) requestId: " + this.requestId);
82
+ winston.debug("(DirContactUpdate) updateProperties: ", updateProperties);
83
+ winston.debug("(DirContactUpdate) updateProperties['fullname']: " + updateProperties['fullname']);
90
84
  callback();
91
85
  // if (this.requestId.startsWith("support-group") && updateProperties['userFullname']) {
92
- // if (this.log) {console.log("(DirContactUpdate) send hidden info to update widget lead fullname"); }
93
86
  // const userFullname = updateProperties['fullname'];
94
87
  // const updateLeadDataOnWidgetMessage = {
95
88
  // type: "text",
@@ -99,15 +92,10 @@ class DirContactUpdate {
99
92
  // updateUserFullname: userFullname
100
93
  // }
101
94
  // };
102
- // if (this.log) {console.log("(DirContactUpdate) sending updateLeadDataOnWidgetMessage:", updateLeadDataOnWidgetMessage); }
103
95
  // this.tdClient.sendSupportMessage(
104
96
  // this.requestId,
105
97
  // updateLeadDataOnWidgetMessage,
106
98
  // (err) => {
107
- // if (err) {
108
- // console.error("(DirContactUpdate) Error sending reply:", err);
109
- // }
110
- // if (this.log) {console.log("(DirContactUpdate) hidden message sent:", updateLeadDataOnWidgetMessage);}
111
99
  // callback();
112
100
  // });
113
101
  // }