@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
@@ -1,6 +1,7 @@
1
1
  const { TiledeskChatbotUtil } = require('@tiledesk/tiledesk-chatbot-util');
2
- const { TiledeskChatbot } = require('../models/TiledeskChatbot.js');
2
+ const { TiledeskChatbot } = require('../engine/TiledeskChatbot.js');
3
3
  const { Filler } = require('./Filler');
4
+ const winston = require('../utils/winston.js');
4
5
 
5
6
  class FillParamsChatbotPlug {
6
7
 
@@ -20,17 +21,16 @@ class FillParamsChatbotPlug {
20
21
  let message = pipeline.message;
21
22
  if (message) {
22
23
  if (message.attributes && (message.attributes.fillParams == undefined || message.attributes.fillParams == false)) { // defaults to disabled
23
- if (this.log) {console.log("fillParams disabled.");}
24
+ winston.verbose("(FillParamsChatbotPlug) fillParams disabled.");
24
25
  pipeline.nextplug();
25
26
  return;
26
27
  }
27
- if (this.log) {
28
- console.log("fillParams: true");
29
- }
28
+
29
+ winston.verbose("(FillParamsChatbotPlug) fillParams: true");
30
30
  const requestId = this.request.request_id;
31
- if (this.log) {console.log("all_parameters of requestId:", requestId)}
31
+ winston.debug("(FillParamsChatbotPlug) all_parameters of requestId: " + requestId)
32
32
  const all_parameters = await TiledeskChatbot.allParametersStatic(this.tdcache, requestId);
33
- if (this.log) {console.log("--got parameters", JSON.stringify(all_parameters));}
33
+ winston.debug("(FillParamsChatbotPlug) Got parameters: " + all_parameters);
34
34
  if (!all_parameters) {
35
35
  pipeline.nextplug();
36
36
  return;
@@ -40,7 +40,6 @@ class FillParamsChatbotPlug {
40
40
  const filled_message_text = filler.fill(message.text, all_parameters);
41
41
  // const filled_message_text = this.fillWithRequestParams(message.text, all_parameters);
42
42
  message.text = filled_message_text;
43
- //console.log("message filled_message_text:", message)
44
43
  if (!message.attributes) {
45
44
  message.attributes = {}
46
45
  }
@@ -54,7 +53,6 @@ class FillParamsChatbotPlug {
54
53
 
55
54
  if (message.attributes && message.attributes.commands) {
56
55
  let commands = message.attributes.commands;
57
- // if (this.log) {console.log("commands for fillMessage:", JSON.stringify(commands));}
58
56
  if (commands.length > 1) {
59
57
  for (let i = 0; i < commands.length; i++) {
60
58
  if (commands[i].type === 'message' && commands[i].message && commands[i].message.text) {
@@ -68,26 +66,22 @@ class FillParamsChatbotPlug {
68
66
  pipeline.nextplug();
69
67
  }
70
68
  else {
71
- if (this.log) {console.log("Fillparams. No message.");}
69
+ winston.debug("(FillParamsChatbotPlug) Fillparams. No message.");
72
70
  pipeline.nextplug();
73
71
  }
74
72
 
75
73
  }
76
74
 
77
75
  // fillWithRequestParams(message_text, all_parameters) {
78
- // if (this.log) {console.log("collected parameters:", JSON.stringify(all_parameters));}
79
76
  // if (!message_text) {
80
- // if (this.log) {console.log("fillWithRequestParams() Can't fill. message_text is null");}
81
77
  // return;
82
78
  // }
83
79
  // if (all_parameters) {
84
80
  // for (const [key, value] of Object.entries(all_parameters)) {
85
81
  // // const value = all_parameters[key];
86
82
  // const value_type = typeof value;
87
- // if (this.log) {console.log("checking parameter:", key, "value:", value, "type:", value_type)}
88
83
  // message_text = message_text.replace(new RegExp("(\\$\\{" + key + "\\})", 'i'), value);
89
84
  // }
90
- // if (this.log) {console.log("final:", message_text);}
91
85
  // }
92
86
  // return message_text;
93
87
  // }
@@ -17,7 +17,6 @@ class Filler {
17
17
 
18
18
  // legacy parser first
19
19
  if (text == null || text == undefined || typeof text !== 'string') {
20
- // console.log("Skip filling. 'text' is null or not a string");
21
20
  return text;
22
21
  }
23
22
  if (parameters) {
@@ -1,4 +1,5 @@
1
1
  const { TiledeskChatbotUtil } = require('@tiledesk/tiledesk-chatbot-util');
2
+ const winston = require('../utils/winston');
2
3
 
3
4
  class MarkbotChatbotPlug {
4
5
 
@@ -15,16 +16,14 @@ class MarkbotChatbotPlug {
15
16
 
16
17
  exec(pipeline) {
17
18
  let message = pipeline.message;
18
- // console.log("markbot on message", message)
19
19
  if (message.attributes && (message.attributes.markbot == undefined || message.attributes.markbot == false)) { // defaults to disabled
20
- if (this.log) {console.log("markbot disabled")}
20
+ winston.verbose("(MarkbotChatbotPlug) Markbot disabled")
21
21
  pipeline.nextplug();
22
22
  return;
23
23
  }
24
24
 
25
- // console.log("message.text", message.text)
26
25
  if (!message.text) {
27
- if (this.log) {console.log("No message.text (no content). Skipping markbot");}
26
+ winston.verbose("(MarkbotChatbotPlug) No message.text (no content). Skipping markbot");
28
27
  pipeline.message = null;
29
28
  pipeline.nextplug();
30
29
  return;
@@ -34,11 +33,9 @@ class MarkbotChatbotPlug {
34
33
  if (message.attributes && message.attributes.commands) {
35
34
  commands = message.attributes.commands;
36
35
  }
37
- // console.log("before taking decision:");
38
- // console.log("message.text:", incoming_message_text);
39
- // console.log("message commands:", commands)
36
+
40
37
  if (incoming_message_text === "" && !commands) {
41
- console.log("message with no content. Ignoring");
38
+ winston.verbose("(MarkbotChatbotPlug) Message with no content. Ignoring");
42
39
  pipeline.message = null;
43
40
  pipeline.nextplug();
44
41
  return;
@@ -48,9 +45,9 @@ class MarkbotChatbotPlug {
48
45
  message.attributes = {}
49
46
  }
50
47
  if (incoming_message_text !== "") {
51
- if (this.log) {console.log("markbotting main message...");}
48
+ winston.verbose("(MarkbotChatbotPlug) markbotting main message...");
52
49
  let parsed_reply = TiledeskChatbotUtil.parseReply(incoming_message_text);
53
- if (this.log) {console.log("parsed", JSON.stringify(parsed_reply));}
50
+ winston.debug("(MarkbotChatbotPlug) parsed_reply", parsed_reply);
54
51
  if (parsed_reply) {
55
52
  message.text = parsed_reply.message.text;
56
53
  if (!message.type || message.type === "text") {
@@ -61,7 +58,7 @@ class MarkbotChatbotPlug {
61
58
  // if already present, do not modify metadata
62
59
  message.metadata = parsed_reply.message.metadata;
63
60
  }
64
- if (this.log) {console.log("parsed_reply.message.attributes", JSON.stringify(parsed_reply.message.attributes));}
61
+ winston.debug("(MarkbotChatbotPlug) parsed_reply.message.attributes", parsed_reply.message.attributes);
65
62
  //this.mergeCurrentMessageButtons(message, parsed_reply);
66
63
  if (parsed_reply.message.attributes) {
67
64
  for(const [key, value] of Object.entries(parsed_reply.message.attributes)) {
@@ -71,30 +68,25 @@ class MarkbotChatbotPlug {
71
68
  }
72
69
  }
73
70
  else {
74
- console.log("no message text:", message.text);
71
+ winston.verbose("(MarkbotChatbotPlug) no message text: " + message.text);
75
72
  }
76
73
 
77
74
  // let commands = null;
78
75
  // if (message.attributes && message.attributes.commands) {
79
76
  // commands = message.attributes.commands;
80
77
  if (commands) {
81
- if (this.log) {console.log("commands for markbot:", commands);}
78
+ winston.debug("(MarkbotChatbotPlug) commands for markbot:", commands);
82
79
  if (commands.length > 1) {
83
80
  for (let i = 0; i < commands.length; i++) {
84
81
  if (commands[i].type === 'message' && commands[i].message && commands[i].message.text) {
85
82
  let parsed_reply = TiledeskChatbotUtil.parseReply(commands[i].message.text);
86
- //console.log("PARSED***", parsed_reply);
87
83
  commands[i].message = parsed_reply.message;
88
84
  }
89
85
  }
90
86
  }
91
87
  }
92
- // else if (message.attributes && !message.attributes.commands) {
93
- // console.log("no message commands.");
94
- // }
95
- // if (this.log) {console.log("Message out of Markbot:", JSON.stringify(message));}
96
- pipeline.nextplug();
97
-
88
+
89
+ pipeline.nextplug();
98
90
  }
99
91
 
100
92
  /*mergeCurrentMessageButtons(message, parsed_reply) {
@@ -1,3 +1,5 @@
1
+ const winston = require('../utils/winston');
2
+
1
3
  class MessagePipeline {
2
4
 
3
5
  /**
@@ -29,24 +31,18 @@ class MessagePipeline {
29
31
  /*
30
32
  exec(completionCallback) {
31
33
  this.completionPromise = new Promise((resolve, reject) => {
32
- console.log("The context", context)
33
34
  const plug = this.nextplug();
34
35
  if (!plug) {
35
- console.log("NO PLUGS!");
36
36
  if (completionCallback) {
37
- console.log("completionCallback found.");
38
37
  completionCallback();
39
38
  }
40
- console.log("Resolving...", this.message);
41
39
  return resolve();
42
40
  }
43
41
  else {
44
42
  plug.exec(this, () => {
45
43
  if (completionCallback) {
46
- console.log("completionCallback found.");
47
44
  completionCallback();
48
45
  }
49
- console.log("Resolving...", this.message);
50
46
  return resolve();
51
47
  });
52
48
  }
@@ -58,14 +54,10 @@ exec(completionCallback) {
58
54
  /*execOn(message, context, completionCallback) {
59
55
  return new Promise((resolve, reject) => {
60
56
  this.message = message;
61
- console.log("The context", context)
62
57
  this.process(this.nextplug(), context, (message) => {
63
- console.log("All plugs processed.", message)
64
58
  if (completionCallback) {
65
- console.log("completionCallback found.")
66
59
  completionCallback(message);
67
60
  }
68
- console.log("Resolving...", message)
69
61
  return resolve(message);
70
62
  });
71
63
  });
@@ -84,27 +76,25 @@ exec(completionCallback) {
84
76
 
85
77
  nextplug() {
86
78
  this.counter += 1;
87
- if (this.log) {console.log(`processing plug[${this.counter}]`);}
79
+ winston.verbose("(MessagePipeline) processing plug: " + this.coounter);
88
80
  if (this.counter < this.plugs.length) {
89
- if (this.log) {console.log("Still plugs...")}
81
+ winston.verbose("(MessagePipeline) Still plugs...")
90
82
  let nextp = this.plugs[this.counter];
91
83
  nextp.exec(this);
92
84
  }
93
85
  else {
94
- if (this.log) {console.log("no more plugs");}
86
+ winston.verbose("(MessagePipeline) no more plugs");
95
87
  this.resolve(this.message);
96
88
  }
97
89
  }
98
90
  /*
99
91
  nextplug() {
100
92
  this.counter += 1;
101
- console.log(`processing plug[${this.counter}]`);
102
93
  if (this.counter < this.plugs.length) {
103
94
  let nextp = this.plugs[this.counter];
104
95
  return nextp;
105
96
  }
106
97
  else {
107
- console.log("no more plugs");
108
98
  return null;
109
99
  }
110
100
  }
@@ -1,4 +1,5 @@
1
1
  const { TiledeskChatbotUtil } = require('@tiledesk/tiledesk-chatbot-util');
2
+ const winston = require('../utils/winston')
2
3
 
3
4
  class SplitsChatbotPlug {
4
5
 
@@ -15,11 +16,8 @@ class SplitsChatbotPlug {
15
16
 
16
17
  exec(pipeline) {
17
18
  let message = pipeline.message;
18
- // console.log("Splits disabled on message?", message);
19
19
  if (message.attributes && (message.attributes.splits == undefined || message.attributes.splits == false)) { // defaults to disabled
20
- if (this.log) {
21
- console.log("Splits disabled.");
22
- }
20
+ winston.verbose("(SplitsChatbotPlug) Splits disabled.");
23
21
  pipeline.nextplug();
24
22
  return;
25
23
  }
@@ -27,24 +25,17 @@ class SplitsChatbotPlug {
27
25
  pipeline.nextplug();
28
26
  return;
29
27
  }
30
- if (this.log) {
31
- console.log("Splitting...");
32
- }
28
+ winston.verbose("(SplitsChatbotPlug) Splitting...");
33
29
  // if splits found just a attributs.commands payload is attached
34
30
  // to the original json message with split commands
35
31
  let commands = TiledeskChatbotUtil.splitPars(message.text);
36
- if (this.log) {
37
- console.log("commands", JSON.stringify(commands))
38
- }
32
+ winston.debug("(SplitsChatbotPlug) commands", commands)
39
33
  if (commands && commands.length > 1) {
40
34
  if (!message.attributes) {
41
35
  message.attributes = {}
42
36
  }
43
37
  message.attributes.commands = commands;
44
38
  }
45
- if (this.log) {
46
- // console.log("Message out of Splits plugin:", JSON.stringify(message));
47
- }
48
39
  pipeline.nextplug();
49
40
  }
50
41
  }
@@ -1,4 +1,4 @@
1
- const { TiledeskChatbot } = require('../models/TiledeskChatbot');
1
+ const { TiledeskChatbot } = require('../engine/TiledeskChatbot');
2
2
 
3
3
  class TiledeskRequestVariables {
4
4
 
@@ -1,4 +1,5 @@
1
1
  let axios = require('axios');
2
+ const winston = require('../utils/winston');
2
3
 
3
4
  class WebhookChatbotPlug {
4
5
 
@@ -12,32 +13,32 @@ class WebhookChatbotPlug {
12
13
  exec(pipeline) {
13
14
  let answer = pipeline.message;
14
15
  let context = pipeline.context;
15
- if (this.log) {console.log("WEBHOOK?", answer.attributes.webhook);}
16
+ winston.verbose("(WebhookChatbotPlug) webhook" + answer.attributes.webhook);
16
17
  if (answer.attributes && answer.attributes.webhook && answer.attributes.webhook === true) {
17
- if (this.log) {console.log("EXECUTING WEBHOOK URL!", this.webhookurl);}
18
- if (this.log) {console.log("EXECUTING WEBHOOK ON CONTEXT:", JSON.stringify(context));}
18
+ winston.debug("(WebhookChatbotPlug) Executing webhook url " + this.webhookurl);
19
+ winston.debug("(WebhookChatbotPlug) Executing webhook on context: ", context);
19
20
  if (!this.validWebhookURL(this.webhookurl)) {
20
- if (this.log) {console.error("(WebhookChatbotPlug) Error. Invalid webhook URL:", this.webhookurl, "on context:", JSON.stringify(context));}
21
+ winston.error("(WebhookChatbotPlug) Error. Invalid webhook URL: " + this.webhookurl + " on context: " + JSON.stringify(context));
21
22
  pipeline.nextplug();
22
23
  return;
23
24
  }
24
25
  this.execWebhook(answer, context, this.webhookurl, (err, message_from_webhook) => {
25
- if (this.log) {console.log("message_from_webhook:", message_from_webhook);}
26
+ winston.debug("(WebhookChatbotPlug) message_from_webhook:", message_from_webhook);
26
27
  if (err) {
27
- console.error("Error calling webhook:", this.webhookurl)
28
+ winston.error("(WebhookChatbotPlug) Error calling webhook:", this.webhookurl)
28
29
  pipeline.nextplug();
29
30
  }
30
31
  else {
31
- if (this.log) {console.log("Webhook successfully end:", message_from_webhook);}
32
+ winston.debug("(WebhookChatbotPlug) Webhook successfully end:", message_from_webhook);
32
33
  const pipeline_original_message = pipeline.message
33
- if (this.log) {console.log("pipeline.message before webhook", JSON.stringify(pipeline.message));}
34
+ winston.debug("(WebhookChatbotPlug) pipeline.message before webhook", pipeline.message);
34
35
 
35
36
  // **** setting message from webhook,
36
37
  // **** MERGING with original not overwritten data, manually
37
38
  pipeline.message = message_from_webhook;
38
39
  // restore on message the original intent_info, necessary FOR further processING the message in the plugs pipeline
39
40
  if (pipeline.message && !pipeline.message.attributes) {
40
- if (this.log) {console.log("!pipeline.message.attributes", pipeline.message.attributes);}
41
+ winston.debug("(WebhookChatbotPlug) !pipeline.message.attributes", pipeline.message.attributes);
41
42
  pipeline.message.attributes = {};
42
43
  }
43
44
  pipeline.message.attributes.intent_info = pipeline_original_message.attributes.intent_info;
@@ -59,11 +60,11 @@ class WebhookChatbotPlug {
59
60
  });
60
61
  }
61
62
  else {
62
- if (this.log) {console.log("NO WEBHOOK!");}
63
+ winston.verbose("(WebhookChatbotPlug) No Webhook!");
63
64
  pipeline.nextplug();
64
65
  return;
65
66
  }
66
- if (this.log) {console.log("Start processing webhook...");}
67
+ winston.verbose("(WebhookChatbotPlug) Start processing webhook...");
67
68
  }
68
69
 
69
70
  validWebhookURL(webhookurl) {
@@ -74,10 +75,8 @@ class WebhookChatbotPlug {
74
75
  }
75
76
 
76
77
  execWebhook(reply_message, context, webhookurl, callback) {
77
- if (this.log) {
78
- console.log("WEBHOOK. on context", JSON.stringify(context));
79
- console.log("WEBHOOK. on message", JSON.stringify(reply_message));
80
- }
78
+ winston.debug("(WebhookChatbotPlug) Webhook on context ", context);
79
+ winston.debug("(WebhookChatbotPlug) WEBHOOK on message ", reply_message);
81
80
  const HTTPREQUEST = {
82
81
  url: webhookurl,
83
82
  headers: {
@@ -92,7 +91,7 @@ class WebhookChatbotPlug {
92
91
  HTTPREQUEST,
93
92
  function(err, res) {
94
93
  if (err || (res && res.status >= 400) || (res && !res.data)) {
95
- console.error("An error occurred calling intent's webhook url:", webhookurl);
94
+ winston.error("(WebhookChatbotPlug) An error occurred calling intent's webhook url: " + webhookurl);
96
95
  if (callback) {
97
96
  callback(reply_message);
98
97
  }
@@ -104,72 +103,6 @@ class WebhookChatbotPlug {
104
103
  }
105
104
  }, this.log
106
105
  );
107
-
108
- /*
109
- return request({
110
- uri : webhookurl,
111
- headers: {
112
- 'Content-Type' : 'application/json',
113
- 'User-Agent': 'tiledesk-bot',
114
- 'Origin': webhook_origin
115
- //'x-hook-secret': s.secret
116
- },
117
- method: 'POST',
118
- json: true,
119
- body: {payload:{text: text, bot: bot, message: message, intent: faq}, token: token},
120
- // }).then(response => {
121
- }, function(err, response, json){
122
- if (err) {
123
- winston.error("Error from webhook reply of getParsedMessage. Return standard reply", err);
124
-
125
- return resolve(messageReply);
126
-
127
- // return error
128
-
129
- }
130
- if (response.statusCode >= 400) {
131
- winston.verbose("The ChatBot webhook return error http status code. Return standard reply", response);
132
- return resolve(messageReply);
133
- }
134
-
135
- if (!json) { //the webhook return empty body
136
- winston.verbose("The ChatBot webhook return no json. Return standard reply", response);
137
- return resolve(messageReply);
138
- }
139
-
140
- winston.debug("webhookurl repl_message ", response);
141
-
142
- var text = undefined;
143
- if(json && json.text===undefined) {
144
- winston.verbose("webhookurl json is defined but text not. return standard reply",{json:json, response:response});
145
- // text = 'Field text is not defined in the webhook respose of the faq with id: '+ faq._id+ ". Error: " + JSON.stringify(response);
146
- return resolve(messageReply);
147
- }else {
148
- text = json.text;
149
- }
150
- winston.debug("webhookurl text: "+ text);
151
-
152
- // // let cloned_message = Object.assign({}, messageReply);
153
- // let cloned_message = message;
154
- // winston.debug("cloned_message : ",cloned_message);
155
-
156
- // if (json.attributes) {
157
- // if (!cloned_message.attributes) {
158
- // cloned_message.attributes = {}
159
- // }
160
- // winston.debug("ChatBot webhook json.attributes: ",json.attributes);
161
- // for(const [key, value] of Object.entries(json.attributes)) {
162
- // cloned_message.attributes[key] = value
163
- // }
164
- // }
165
-
166
- // winston.debug("cloned_message after attributes: ",cloned_message);
167
-
168
- that.parseMicrolanguage(text, message, bot, faq, true, json).then(function(bot_answer) {
169
- return resolve(bot_answer);
170
- });
171
- });
172
- */
173
106
  }
174
107
 
175
108
  // ************************************************
@@ -178,8 +111,8 @@ class WebhookChatbotPlug {
178
111
 
179
112
  static myrequest(options, callback, log) {
180
113
  if (log) {
181
- console.log("API URL:", options.url);
182
- console.log("** Options:", JSON.stringify(options));
114
+ winston.debug("(WebhookChatbotPlug) myrequest API URL:" + options.url);
115
+ winston.debug("(WebhookChatbotPlug) myrequest Options:", options);
183
116
  }
184
117
  axios(
185
118
  {
@@ -190,17 +123,16 @@ class WebhookChatbotPlug {
190
123
  })
191
124
  .then(function (res) {
192
125
  if (log) {
193
- console.log("Response for url:", options.url);
194
- console.log("Response headers:\n", JSON.stringify(res.headers));
195
- // console.log("******** Response for url:", JSON.stringify(res));
196
- console.log("Response body:\n", JSON.stringify(res.data));
126
+ winston.debug("(WebhookChatbotPlug) myrequest Response for url:", options.url);
127
+ winston.debug("(WebhookChatbotPlug) myrequest Response headers:\n", res.headers);
128
+ winston.debug("(WebhookChatbotPlug) myrequest Response body:\n", res.data);
197
129
  }
198
130
  if (callback) {
199
131
  callback(null, res);
200
132
  }
201
133
  })
202
134
  .catch(function (error) {
203
- console.error("(WebhookChatbotPlug) Axios error: ", JSON.stringify(error));
135
+ winston.debug("(WebhookChatbotPlug) Axios error: ", error.response.data);
204
136
  if (callback) {
205
137
  callback(error, null, null);
206
138
  }
@@ -1,4 +1,4 @@
1
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
1
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
2
2
  const { Filler } = require('../Filler');
3
3
 
4
4
  class DirSetAttribute {