@tiledesk/tiledesk-tybot-connector 0.2.5 → 0.2.7

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.
@@ -22,28 +22,33 @@ class MongodbBotsDataSource {
22
22
  async getBotByIdCache(botId, tdcache) {
23
23
  let bot = null;
24
24
  if (tdcache) {
25
+ console.log("getBotByIdCache cache ok");
25
26
  let botCacheKey = "cacheman:cachegoose-cache:faq_kbs:id:" + botId;
26
27
  try {
27
28
  let _bot_as_string = await tdcache.get(botCacheKey);
28
29
  const value_type = typeof _bot_as_string;
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
+ console.log("__bot_as_string found in chache:", _bot_as_string);
31
+ // if (this.log) {
32
+ // console.log("__bot_as_string found in chache:", _bot_as_string);
33
+ // console.log("value_type:", value_type);
34
+ // }
33
35
  if (_bot_as_string) {
34
36
  bot = JSON.parse(_bot_as_string);
35
- if (this.log) {
36
- console.log("got bot from cache:", JSON.stringify(bot));
37
- }
37
+ console.log("got bot from cache:", JSON.stringify(bot));
38
+ // if (this.log) {
39
+ // console.log("got bot from cache:", JSON.stringify(bot));
40
+ // }
38
41
  }
39
42
  else {
40
- if (this.log) {
41
- console.log("bot not found, getting from datasource...");
42
- }
43
+ console.log("bot not found, getting from datasource...");
44
+ // if (this.log) {
45
+ // console.log("bot not found, getting from datasource...");
46
+ // }
43
47
  bot = await this.getBotById(botId);
44
- if (this.log) {
45
- console.log("bot found in datasource:", JSON.stringify(bot));
46
- }
48
+ console.log("bot found in datasource:", JSON.stringify(bot));
49
+ // if (this.log) {
50
+ // console.log("bot found in datasource:", JSON.stringify(bot));
51
+ // }
47
52
  await tdcache.set(botCacheKey, JSON.stringify(bot));
48
53
  // DEBUG CODE REMOVE
49
54
  // let bot_ = await tdcache.get(botCacheKey);
@@ -55,13 +60,13 @@ class MongodbBotsDataSource {
55
60
  }
56
61
  }
57
62
  else {
58
- if (this.log) {
63
+ // if (this.log) {
59
64
  console.log("no chache. getting bot from datasource...");
60
- }
65
+ // }
61
66
  bot = await this.getBotById(botId);
62
- if (this.log) {
67
+ // if (this.log) {
63
68
  console.log("bot found in datasource:", JSON.stringify(bot));
64
- }
69
+ // }
65
70
  }
66
71
  return bot;
67
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -114,10 +114,10 @@ class DirReply {
114
114
  message,
115
115
  (err) => {
116
116
  if (err) {
117
- console.error("Error sending reply:", err.message);
117
+ console.error("Error sending reply:", err);
118
118
  }
119
119
  // if (this.log) {console.log("Reply message sent.");}
120
- console.log("Reply message sent.");
120
+ console.log("Reply message sent.", JSON.parse(message));
121
121
  callback();
122
122
  });
123
123
  }
@@ -137,24 +137,27 @@ class DirReply {
137
137
  };
138
138
  this.myrequest(
139
139
  HTTPREQUEST,
140
- function(err, response, resbody) {
141
- if (response.status === 200) {
140
+ function(err, resbody) {
141
+ if (err) {
142
142
  if (callback) {
143
- callback(null, resbody)
143
+ callback(err);
144
144
  }
145
145
  }
146
- else if (callback) {
147
- callback(err);
146
+ else {
147
+ if (callback) {
148
+ callback(null, resbody);
149
+ }
148
150
  }
149
151
  }, this.log
150
152
  );
151
153
  }
152
154
 
153
155
  myrequest(options, callback, log) {
154
- if (log) {
156
+ // if (log) {
155
157
  console.log("API URL:", options.url);
156
158
  console.log("** Options:", JSON.stringify(options));
157
- }
159
+ console.log("** Sending reply json:", JSON.stringify(options.json));
160
+ // }
158
161
  axios(
159
162
  {
160
163
  url: options.url,
@@ -167,24 +170,28 @@ class DirReply {
167
170
  // if (log) {
168
171
  console.log("Reply: Response for url:", options.url);
169
172
  console.log("Reply: Response headers:\n", JSON.stringify(res.headers));
173
+ console.log("Reply: Status:", res.status);
174
+ console.log("Reply: Data:", res.data);
175
+
170
176
  //console.log("******** Response for url:", res);
171
177
  // }
172
178
  if (res && res.status == 200 && res.data) {
179
+ console.log("Status 200 OK");
173
180
  if (callback) {
174
181
  callback(null, res.data);
175
182
  }
176
183
  }
177
184
  else {
185
+ console.error("Status ! 200");
178
186
  if (callback) {
179
- console.error("Status ! 200");
180
- callback({ message: "Response status not 200" });
187
+ callback({ message: "Response status not 200" }, null);
181
188
  }
182
189
  }
183
190
  })
184
191
  .catch((error) => {
185
- console.error("An error occurred:", error);
192
+ console.error("Reply error:", error);
186
193
  if (callback) {
187
- callback(error, null, null);
194
+ callback(error, null);
188
195
  }
189
196
  });
190
197
  }