@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 +3 -0
- package/index.js +1 -1
- package/models/MongodbBotsDataSource.js +31 -16
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
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
|
-
|
|
29
|
-
|
|
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
|
-
|
|
35
|
+
if (this.log) {
|
|
36
|
+
console.log("got bot from cache:", JSON.stringify(bot));
|
|
37
|
+
}
|
|
33
38
|
}
|
|
34
39
|
else {
|
|
35
|
-
|
|
40
|
+
if (this.log) {
|
|
41
|
+
console.log("bot not found, getting from datasource...");
|
|
42
|
+
}
|
|
36
43
|
bot = await this.getBotById(botId);
|
|
37
|
-
|
|
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
|
-
|
|
58
|
+
if (this.log) {
|
|
59
|
+
console.log("no chache. getting bot from datasource...");
|
|
60
|
+
}
|
|
50
61
|
bot = await this.getBotById(botId);
|
|
51
|
-
|
|
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
|
-
|
|
134
|
-
|
|
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
|
}
|