@tiledesk/tiledesk-tybot-connector 0.1.67 → 0.1.68

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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,9 @@
5
5
  available on:
6
6
  ▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
7
7
 
8
+ ### 0.1.68
9
+ - Log clean
10
+
8
11
  ### 0.1.67
9
12
  - adds tdActionId to Schema for SetAttribute
10
13
  - removes hidden vars from attributes
package/index.js CHANGED
@@ -90,7 +90,7 @@ router.post('/ext/:botid', async (req, res) => {
90
90
 
91
91
  let botsDS;
92
92
  if (!staticBots) {
93
- botsDS = new MongodbBotsDataSource({projectId: projectId, botId: botId});
93
+ botsDS = new MongodbBotsDataSource({projectId: projectId, botId: botId, log: log});
94
94
  if (log) {console.log("botsDS created with Mongo");}
95
95
  }
96
96
  else {
@@ -8,6 +8,7 @@ class MongodbBotsDataSource {
8
8
  throw new Error("config.projectId is mandatory");
9
9
  }
10
10
  this.projectId = config.projectId;
11
+ this.log = config.log;
11
12
  }
12
13
 
13
14
  async getBotById(botId) {
@@ -25,19 +26,27 @@ class MongodbBotsDataSource {
25
26
  try {
26
27
  let _bot_as_string = await tdcache.get(botCacheKey);
27
28
  const value_type = typeof _bot_as_string;
28
- // console.log("__bot_as_string found in chache:", _bot_as_string);
29
- // console.log("value_type:", value_type);
29
+ if (this.log) {
30
+ console.log("__bot_as_string found in chache:", _bot_as_string);
31
+ console.log("value_type:", value_type);
32
+ }
30
33
  if (_bot_as_string) {
31
34
  bot = JSON.parse(_bot_as_string);
32
- // console.log("got bot from cache:", JSON.stringify(bot));
35
+ if (this.log) {
36
+ console.log("got bot from cache:", JSON.stringify(bot));
37
+ }
33
38
  }
34
39
  else {
35
- // console.log("bot not found, getting from datasource...");
40
+ if (this.log) {
41
+ console.log("bot not found, getting from datasource...");
42
+ }
36
43
  bot = await this.getBotById(botId);
37
- // console.log("bot found in datasource:", JSON.stringify(bot));
44
+ if (this.log) {
45
+ console.log("bot found in datasource:", JSON.stringify(bot));
46
+ }
38
47
  await tdcache.set(botCacheKey, JSON.stringify(bot));
39
48
  // DEBUG CODE REMOVE
40
- let bot_ = await tdcache.get(botCacheKey);
49
+ // let bot_ = await tdcache.get(botCacheKey);
41
50
  // console.log("_bot_as_string from cache debug:", bot_)
42
51
  }
43
52
  }
@@ -46,9 +55,13 @@ class MongodbBotsDataSource {
46
55
  }
47
56
  }
48
57
  else {
49
- // console.log("no chache. getting bot from datasource...");
58
+ if (this.log) {
59
+ console.log("no chache. getting bot from datasource...");
60
+ }
50
61
  bot = await this.getBotById(botId);
51
- // console.log("bot found in datasource:", JSON.stringify(bot));
62
+ if (this.log) {
63
+ console.log("bot found in datasource:", JSON.stringify(bot));
64
+ }
52
65
  }
53
66
  return bot;
54
67
  }
@@ -124,22 +137,24 @@ class MongodbBotsDataSource {
124
137
  console.log("botID:", botId);
125
138
  console.log("key:", key);
126
139
  if (tdcache) {
127
- console.log("in tdcache");
140
+ if (this.log) {console.log("in tdcache");}
128
141
  let faqCacheKey = "cacheman:cachegoose-cache:faqs:botid:"+ botId + ":faq:id:" + key;
129
- console.log("Looking in cache for:", faqCacheKey);
142
+ if (this.log) {console.log("Looking in cache for:", faqCacheKey);}
130
143
  try {
131
144
  let _faq_as_string = await tdcache.get(faqCacheKey);
132
145
  const value_type = typeof _faq_as_string;
133
- console.log("_faq_as_string found in chache:", _faq_as_string);
134
- console.log("value_type:", value_type);
146
+ if (this.log) {
147
+ console.log("_faq_as_string found in chache:", _faq_as_string);
148
+ console.log("value_type:", value_type);
149
+ }
135
150
  if (_faq_as_string) {
136
151
  faq = JSON.parse(_faq_as_string);
137
- console.log("got faq from cache:", JSON.stringify(faq));
152
+ if (this.log) {console.log("got faq from cache:", JSON.stringify(faq));}
138
153
  }
139
154
  else {
140
155
  console.log("faq not found, getting from datasource...");
141
156
  faq = await this.getByIntentDisplayName(botId, key);
142
- console.log(".faq found in datasource:", JSON.stringify(faq));
157
+ if (this.log) {console.log(".faq found in datasource:", JSON.stringify(faq));}
143
158
  await tdcache.set(faqCacheKey, JSON.stringify(faq));
144
159
  // DEBUG CODE REMOVE
145
160
  // let faq_ = await tdcache.get(faqCacheKey);
@@ -151,9 +166,9 @@ class MongodbBotsDataSource {
151
166
  }
152
167
  }
153
168
  else {
154
- console.log("no chache. getting faq from datasource...");
169
+ if (this.log) {console.log("no chache. getting faq from datasource...");}
155
170
  faq = await this.getByIntentDisplayName(botId, key);
156
- console.log("faq found in datasource (no-cache):", JSON.stringify(faq));
171
+ if (this.log) {console.log("faq found in datasource (no-cache):", JSON.stringify(faq));}
157
172
  }
158
173
  return faq;
159
174
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.1.67",
3
+ "version": "0.1.68",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {