@tiledesk/tiledesk-tybot-connector 0.5.0 → 0.5.1-rc1

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 (102) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/ExtApi.js +4 -83
  3. package/ExtUtil.js +0 -1
  4. package/Logger.js +113 -0
  5. package/TdCache.js +5 -3
  6. package/TiledeskClientTest.js +5 -28
  7. package/TiledeskExpression.js +6 -47
  8. package/{models → engine}/IntentForm.js +30 -44
  9. package/{models → engine}/IntentsMachineFactory.js +5 -4
  10. package/{models → engine}/MongodbBotsDataSource.js +31 -55
  11. package/{models → engine}/MongodbIntentsMachine.js +6 -5
  12. package/{models → engine}/TiledeskChatbot.js +82 -259
  13. package/{models → engine}/TiledeskChatbotConst.js +9 -0
  14. package/{models → engine}/TiledeskIntentsMachine.js +5 -15
  15. package/{models → engine/mock}/MockBotsDataSource.js +2 -19
  16. package/{models → engine/mock}/MockTdCache.js +0 -9
  17. package/index.js +106 -380
  18. package/logs/app.log +11557 -277
  19. package/logs/app1.log +62258 -0
  20. package/logs/app2.log +46280 -0
  21. package/logs/app3.log +31686 -0
  22. package/logs/app4.log +46163 -0
  23. package/logs/app5.log +33173 -0
  24. package/models/faq.js +2 -5
  25. package/package.json +5 -2
  26. package/{TiledeskServices → services}/AIService.js +4 -3
  27. package/{models/faqKbService.js → services/FaqKbService.js} +1 -2
  28. package/{models/faqService.js → services/FaqService.js} +4 -3
  29. package/services/IntegrationService.js +43 -0
  30. package/services/TilebotService.js +47 -0
  31. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +68 -142
  32. package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +8 -14
  33. package/tiledeskChatbotPlugs/Filler.js +0 -1
  34. package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +12 -20
  35. package/tiledeskChatbotPlugs/MessagePipeline.js +5 -15
  36. package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +4 -13
  37. package/tiledeskChatbotPlugs/TiledeskRequestVariables.js +1 -1
  38. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +21 -89
  39. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirSetAttribute.js +1 -1
  40. package/tiledeskChatbotPlugs/directives/DirAddTags.js +23 -140
  41. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +42 -128
  42. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +37 -127
  43. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +52 -145
  44. package/tiledeskChatbotPlugs/directives/DirAssign.js +12 -23
  45. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +16 -12
  46. package/tiledeskChatbotPlugs/directives/DirAssistant.js +56 -198
  47. package/tiledeskChatbotPlugs/directives/DirBrevo.js +41 -101
  48. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +9 -19
  49. package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +1 -1
  50. package/tiledeskChatbotPlugs/directives/DirClose.js +4 -2
  51. package/tiledeskChatbotPlugs/directives/DirCode.js +16 -23
  52. package/tiledeskChatbotPlugs/directives/DirCondition.js +19 -25
  53. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -82
  54. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +10 -22
  55. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +34 -89
  56. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +17 -22
  57. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +8 -8
  58. package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -12
  59. package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +2 -6
  60. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -4
  61. package/tiledeskChatbotPlugs/directives/DirForm.js +17 -24
  62. package/tiledeskChatbotPlugs/directives/DirGptTask.js +49 -139
  63. package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +8 -53
  64. package/tiledeskChatbotPlugs/directives/DirHubspot.js +31 -91
  65. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
  66. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +24 -78
  67. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -68
  68. package/tiledeskChatbotPlugs/directives/DirIntent.js +12 -104
  69. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +15 -14
  70. package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
  71. package/tiledeskChatbotPlugs/directives/DirMake.js +21 -53
  72. package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
  73. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +8 -87
  74. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +6 -4
  75. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +6 -4
  76. package/tiledeskChatbotPlugs/directives/DirQapla.js +26 -120
  77. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +11 -19
  78. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
  79. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +5 -2
  80. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +12 -58
  81. package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +11 -57
  82. package/tiledeskChatbotPlugs/directives/DirReply.js +34 -37
  83. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +30 -72
  84. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +9 -10
  85. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +15 -40
  86. package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +8 -5
  87. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +25 -113
  88. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
  89. package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
  90. package/tiledeskChatbotPlugs/directives/DirWait.js +5 -6
  91. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +14 -49
  92. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +22 -77
  93. package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +1 -1
  94. package/tiledeskChatbotPlugs/directives/DirWebResponse.js +23 -64
  95. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +13 -42
  96. package/tiledeskChatbotPlugs/directives/Directives.js +1 -3
  97. package/utils/HttpUtils.js +128 -0
  98. package/{models → utils}/TiledeskChatbotUtil.js +140 -234
  99. package/utils/winston.js +42 -0
  100. package/TdCache copy.js +0 -242
  101. package/TiledeskServices/utils.js +0 -99
  102. /package/{models → engine/mock}/MockIntentsMachine.js +0 -0
package/models/faq.js CHANGED
@@ -1,6 +1,7 @@
1
1
  var mongoose = require('mongoose');
2
2
  var Schema = mongoose.Schema;
3
3
  var { nanoid } = require("nanoid");
4
+ const winston = require('../utils/winston')
4
5
  //const { v4: uuidv4 } = require('uuid');
5
6
  var defaultFullTextLanguage = process.env.DEFAULT_FULLTEXT_INDEX_LANGUAGE || "none";
6
7
 
@@ -105,14 +106,10 @@ FaqSchema.index({ id_project: 1, id_faq_kb: 1, intent_display_name: 1 }, { uniq
105
106
 
106
107
  var faq = mongoose.model('faq', FaqSchema);
107
108
 
108
- //faq.on('index', function(error) {
109
- // "_id index cannot be sparse"
110
- //console.debug('index:', error);
111
- //});
112
109
 
113
110
  if (process.env.MONGOOSE_SYNCINDEX) {
114
111
  faq.syncIndexes();
115
- console.info("faq syncIndexes")
112
+ winston.verbose("faq syncIndexes")
116
113
  }
117
114
 
118
115
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.5.0",
3
+ "version": "0.5.1-rc1",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -15,7 +15,9 @@
15
15
  "@tiledesk/tiledesk-chatbot-client": "^0.5.30",
16
16
  "@tiledesk/tiledesk-chatbot-util": "^0.8.39",
17
17
  "@tiledesk/tiledesk-client": "^0.10.13",
18
+ "@tiledesk/tiledesk-multi-worker": "^0.2.1-rc2",
18
19
  "accept-language-parser": "^1.5.0",
20
+ "app-root-path": "^3.1.0",
19
21
  "axios": "^1.7.7",
20
22
  "body-parser": "^1.19.0",
21
23
  "cors": "^2.8.5",
@@ -31,7 +33,8 @@
31
33
  "nanoid": "^3.1.25",
32
34
  "redis": "^4.7.0",
33
35
  "uuid": "^3.3.3",
34
- "vm2": "^3.9.13"
36
+ "vm2": "^3.9.13",
37
+ "winston": "^3.17.0"
35
38
  },
36
39
  "devDependencies": {
37
40
  "mocha": "^8.4.0"
@@ -1,4 +1,5 @@
1
- const Utils = require('./utils')
1
+ const httpUtils = require("../utils/HttpUtils");
2
+
2
3
  class AiService {
3
4
 
4
5
  constructor(options){
@@ -13,7 +14,7 @@ class AiService {
13
14
  url: `${this.APIURL}/${this.PROJECT_ID}/llm/transcription`,
14
15
  headers: {
15
16
  'Content-Type' : 'application/json',
16
- 'Authorization': Utils.fixToken(this.TOKEN)
17
+ 'Authorization': httpUtils.fixToken(this.TOKEN)
17
18
  },
18
19
  json: {
19
20
  url: url
@@ -21,7 +22,7 @@ class AiService {
21
22
  method: 'POST',
22
23
  httpsOptions: this.httpsOptions
23
24
  };
24
- Utils.myrequest(
25
+ httpUtils.request(
25
26
  HTTPREQUEST,
26
27
  function(err, resbody) {
27
28
  if (err) {
@@ -1,4 +1,4 @@
1
- var Faq_kb = require("./faq_kb");
1
+ var Faq_kb = require("../models/faq_kb");
2
2
 
3
3
  class FaqKbService {
4
4
 
@@ -13,7 +13,6 @@ class FaqKbService {
13
13
  }
14
14
  var sortQuery = {};
15
15
  sortQuery["score"] = -1;
16
- // console.log("(Service) GET ALL FAQ_KBs");
17
16
  return new Promise((resolve, reject) => {
18
17
  // let query = {public: options.public, certified: options.certified};
19
18
  Faq_kb.find(query).sort(sortQuery).lean().exec( (err, bots) => {
@@ -1,10 +1,11 @@
1
- var Faq = require("./faq");
2
- var Faq_kb = require("./faq_kb");
1
+ var Faq = require("../models/faq");
2
+ var Faq_kb = require("../models/faq_kb");
3
+ const winston = require('../utils/winston');
3
4
 
4
5
  class FaqService {
5
6
 
6
7
  async getAll(faq_kb_id) {
7
- console.log("(Service) GET ALL FAQ OF THE BOT ID (req.query): ", faq_kb_id);
8
+ winston.verbose("(Service) GET ALL FAQ OF THE BOT ID (req.query): " + faq_kb_id);
8
9
  return new Promise((resolve, reject) => {
9
10
  let query = { id_faq_kb: faq_kb_id};
10
11
  Faq.find(query).lean().exec( (err, faqs) => {
@@ -0,0 +1,43 @@
1
+ const httpUtils = require('../utils/HttpUtils');
2
+ const winston = require('../utils/winston');
3
+ let API_ENDPOINT = process.env.API_ENDPOINT;
4
+
5
+ class IntegrationService {
6
+
7
+ constructor() {}
8
+
9
+ async getKeyFromIntegrations(id_project, integration_name, token) {
10
+ return new Promise((resolve) => {
11
+
12
+ const INTEGRATIONS_HTTPREQUEST = {
13
+ url: API_ENDPOINT + "/" + id_project + "/integration/name/" + integration_name,
14
+ headers: {
15
+ 'Content-Type': 'application/json',
16
+ 'Authorization': 'JWT ' + token
17
+ },
18
+ method: "GET"
19
+ }
20
+ winston.debug("Integration HttpRequest ", INTEGRATIONS_HTTPREQUEST)
21
+
22
+ httpUtils.request(
23
+ INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
24
+ if (err) {
25
+ resolve(null);
26
+ } else {
27
+
28
+ if (integration &&
29
+ integration.value) {
30
+ resolve(integration.value.apikey)
31
+ }
32
+ else {
33
+ resolve(null)
34
+ }
35
+ }
36
+ })
37
+ })
38
+ }
39
+
40
+ }
41
+
42
+ const integrationService = new IntegrationService();
43
+ module.exports = integrationService;
@@ -0,0 +1,47 @@
1
+ const httpUtils = require("../utils/HttpUtils");
2
+ const winston = require('../utils/winston');
3
+ const TILEBOT_ENDPOINT = process.env.TILEBOT_ENDPOINT;
4
+
5
+ class TilebotService {
6
+
7
+ constructor() { }
8
+
9
+ /**
10
+ * A stub to send message to the "ext/botId" endpoint, hosted by tilebot on:
11
+ * /${TILEBOT_ROUTE}/ext/${botId}
12
+ *
13
+ * @param {Object} message. The message to send
14
+ * @param {string} botId. Tiledesk botId
15
+ * @param {string} token. User token
16
+ */
17
+ sendMessageToBot(message, botId, callback) {
18
+ const url = `${TILEBOT_ENDPOINT}/ext/${botId}`;
19
+ winston.verbose("sendMessageToBot URL" + url);
20
+ const HTTPREQUEST = {
21
+ url: url,
22
+ headers: {
23
+ 'Content-Type': 'application/json'
24
+ },
25
+ json: message,
26
+ method: 'POST'
27
+ };
28
+ httpUtils.request(
29
+ HTTPREQUEST,
30
+ function (err, resbody) {
31
+ if (err) {
32
+ if (callback) {
33
+ callback(err);
34
+ }
35
+ }
36
+ else {
37
+ if (callback) {
38
+ callback(null, resbody);
39
+ }
40
+ }
41
+ }, false
42
+ );
43
+ }
44
+ }
45
+
46
+ let tilebotService = new TilebotService();
47
+ module.exports = tilebotService;