@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.
- package/ExtApi.js +4 -83
- package/ExtUtil.js +0 -1
- package/Logger.js +105 -0
- package/TdCache.js +5 -3
- package/TiledeskClientTest.js +5 -28
- package/TiledeskExpression.js +6 -47
- package/{models → engine}/IntentForm.js +30 -44
- package/{models → engine}/IntentsMachineFactory.js +5 -4
- package/{models → engine}/MongodbBotsDataSource.js +31 -55
- package/{models → engine}/MongodbIntentsMachine.js +6 -5
- package/{models → engine}/TiledeskChatbot.js +82 -259
- package/{models → engine}/TiledeskChatbotConst.js +9 -0
- package/{models → engine}/TiledeskIntentsMachine.js +5 -15
- package/{models → engine/mock}/MockBotsDataSource.js +3 -19
- package/{models → engine/mock}/MockTdCache.js +0 -9
- package/index.js +103 -380
- package/logs/app.log +12723 -277
- package/logs/app1.log +62258 -0
- package/logs/app2.log +46280 -0
- package/logs/app3.log +31686 -0
- package/logs/app4.log +46163 -0
- package/logs/app5.log +33173 -0
- package/models/faq.js +2 -5
- package/package.json +5 -2
- package/{TiledeskServices → services}/AIService.js +4 -3
- package/{models/faqKbService.js → services/FaqKbService.js} +1 -2
- package/{models/faqService.js → services/FaqService.js} +4 -3
- package/services/IntegrationService.js +43 -0
- package/services/TilebotService.js +47 -0
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +49 -135
- package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +8 -14
- package/tiledeskChatbotPlugs/Filler.js +0 -1
- package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +12 -20
- package/tiledeskChatbotPlugs/MessagePipeline.js +5 -15
- package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +4 -13
- package/tiledeskChatbotPlugs/TiledeskRequestVariables.js +1 -1
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +21 -89
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirSetAttribute.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +23 -140
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +42 -128
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +37 -127
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +52 -145
- package/tiledeskChatbotPlugs/directives/DirAssign.js +12 -23
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +16 -12
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +56 -198
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +41 -101
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +9 -19
- package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirClose.js +4 -2
- package/tiledeskChatbotPlugs/directives/DirCode.js +16 -23
- package/tiledeskChatbotPlugs/directives/DirCondition.js +19 -25
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -82
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +10 -22
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +34 -89
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +17 -22
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +8 -8
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -12
- package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +2 -6
- package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -4
- package/tiledeskChatbotPlugs/directives/DirForm.js +17 -24
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +49 -139
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +8 -53
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +31 -91
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +24 -78
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -68
- package/tiledeskChatbotPlugs/directives/DirIntent.js +6 -100
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +15 -14
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
- package/tiledeskChatbotPlugs/directives/DirMake.js +21 -53
- package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +8 -87
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +6 -4
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +6 -4
- package/tiledeskChatbotPlugs/directives/DirQapla.js +26 -120
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +11 -19
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +5 -2
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +12 -58
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +11 -57
- package/tiledeskChatbotPlugs/directives/DirReply.js +36 -30
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +30 -72
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +9 -10
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +15 -40
- package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +8 -5
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +25 -113
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
- package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
- package/tiledeskChatbotPlugs/directives/DirWait.js +5 -6
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +14 -49
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +22 -77
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +11 -14
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +13 -42
- package/tiledeskChatbotPlugs/directives/Directives.js +0 -3
- package/utils/HttpUtils.js +128 -0
- package/{models → utils}/TiledeskChatbotUtil.js +164 -234
- package/utils/winston.js +42 -0
- package/TiledeskServices/utils.js +0 -99
- /package/{models → engine/mock}/MockIntentsMachine.js +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
//const CURRENT_FIELD_K = "tilebot:requests:forms:currentField"; // form field index
|
|
2
2
|
const CURRENT_FORM_K = "CURRENT_FORM"; // form json
|
|
3
|
+
const winston = require('../utils/winston');
|
|
3
4
|
|
|
4
5
|
class IntentForm {
|
|
5
6
|
|
|
@@ -18,10 +19,8 @@ class IntentForm {
|
|
|
18
19
|
if (!this.requestParameters) {
|
|
19
20
|
return null;
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
console.log("this.requestParameters[" + paramKey + "]:", this.requestParameters[paramKey]);
|
|
24
|
-
}
|
|
22
|
+
winston.debug("(IntentForm) requestParameters: ", this.requestParameters);
|
|
23
|
+
winston.debug("(IntentForm) requestParameters[" + paramKey + "]:" + this.requestParameters[paramKey]);
|
|
25
24
|
return this.requestParameters[paramKey];
|
|
26
25
|
}
|
|
27
26
|
|
|
@@ -61,13 +60,11 @@ class IntentForm {
|
|
|
61
60
|
}
|
|
62
61
|
*/
|
|
63
62
|
async getMessage(user_text) {
|
|
64
|
-
//console.log("get message:", user_text)
|
|
65
63
|
let current_form = null;
|
|
66
64
|
const _current_form = await this.getValue(this.CURRENT_FORM_KEY);
|
|
67
65
|
if (_current_form) {
|
|
68
66
|
current_form = JSON.parse(_current_form);
|
|
69
67
|
}
|
|
70
|
-
//console.log("CURRENT FORM IS", current_form);
|
|
71
68
|
if (
|
|
72
69
|
current_form &&
|
|
73
70
|
this.form &&
|
|
@@ -90,7 +87,7 @@ class IntentForm {
|
|
|
90
87
|
}
|
|
91
88
|
|
|
92
89
|
if (current_field == null) {
|
|
93
|
-
|
|
90
|
+
winston.debug("(IntentForm) current_field is undefined");
|
|
94
91
|
current_field = 0;
|
|
95
92
|
|
|
96
93
|
// first "freeze" the currente form, so that eventual form modifications
|
|
@@ -105,58 +102,48 @@ class IntentForm {
|
|
|
105
102
|
// set the first field under the "await the response-value" state (=0)
|
|
106
103
|
await this.setValue(this.CURRENT_FIELD_INDEX_KEY, current_field);
|
|
107
104
|
// now look for an already set value for this field in request parameters
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
winston.debug("(IntentForm) parameters ", this.requestParameters);
|
|
106
|
+
winston.debug("(IntentForm) checking field: " + this.form.fields[current_field].name);
|
|
110
107
|
const is_current_value = this.getParam(this.form.fields[current_field].name);
|
|
111
108
|
if (is_current_value) {
|
|
112
|
-
|
|
109
|
+
winston.debug("(IntentForm) is_current_value: " + is_current_value);
|
|
113
110
|
return await this.getMessage(is_current_value);
|
|
114
111
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (this.log) {console.log("CURRENT FIELD:", current_field);}
|
|
112
|
+
winston.debug("(IntentForm) asking fist value. No 'is_current_value' for first form field" + is_current_value);
|
|
113
|
+
winston.debug("(IntentForm) current_field: " + current_field);
|
|
118
114
|
let message = {
|
|
119
115
|
text: this.form.fields[current_field].label
|
|
120
116
|
}
|
|
121
|
-
|
|
117
|
+
winston.debug("(IntentForm)form reply message: ", message);
|
|
122
118
|
return {
|
|
123
119
|
message: message
|
|
124
120
|
}
|
|
125
121
|
}
|
|
126
122
|
else {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
//
|
|
130
|
-
//inc(current_field)=1 getMessage(null)
|
|
131
|
-
// == 1?
|
|
132
|
-
// n => continue =>
|
|
133
|
-
// param[1] n? => continue
|
|
134
|
-
// == 2? => set fields[2].name => user_text
|
|
135
|
-
//console.log("current_form:", current_form);
|
|
136
|
-
if (this.log) {console.log("current_field:", current_field);}
|
|
137
|
-
|
|
123
|
+
|
|
124
|
+
winston.debug("(IntentForm) current_field: " + current_field);
|
|
138
125
|
|
|
139
126
|
if (current_form.fields[current_field].regex) {
|
|
140
127
|
if (!this.validate(user_text, current_form.fields[current_field].regex)) {
|
|
141
|
-
|
|
128
|
+
winston.verbose("(IntentForm) text is invalid");
|
|
142
129
|
// send error message
|
|
143
130
|
let error_reply_text = this.form.fields[current_field].label;
|
|
144
|
-
|
|
131
|
+
winston.debug("(IntentForm) text is invalid label: " + error_reply_text);
|
|
145
132
|
if (current_form.fields[current_field].errorLabel) {
|
|
146
|
-
|
|
133
|
+
winston.debug("(IntentForm) text is invalid errorLabel: " + current_form.fields[current_field].errorLabel);
|
|
147
134
|
error_reply_text = current_form.fields[current_field].errorLabel;
|
|
148
135
|
}
|
|
149
136
|
let message = {
|
|
150
137
|
text: error_reply_text // Error
|
|
151
138
|
}
|
|
152
|
-
|
|
139
|
+
winston.debug("(IntentForm) error message: ", message);
|
|
153
140
|
return {
|
|
154
141
|
message: message
|
|
155
142
|
};
|
|
156
143
|
}
|
|
157
144
|
}
|
|
158
145
|
else {
|
|
159
|
-
|
|
146
|
+
winston.verbose("(IntentForm) no regex validation requested. next field...")
|
|
160
147
|
}
|
|
161
148
|
|
|
162
149
|
// text ok?
|
|
@@ -169,12 +156,12 @@ class IntentForm {
|
|
|
169
156
|
// persist parameter
|
|
170
157
|
const parameter_name = current_form.fields[current_field].name;
|
|
171
158
|
const parameter_value = user_text;
|
|
172
|
-
|
|
159
|
+
winston.debug("(IntentForm) adding parameters, name: " + parameter_name + " value: " + parameter_value)
|
|
173
160
|
await this.chatbot.addParameter(parameter_name, parameter_value);
|
|
174
161
|
if (current_form.fields[current_field].type) { // adding type
|
|
175
162
|
await this.chatbot.addParameter("_tdTypeOf:" + parameter_name, current_form.fields[current_field].type);
|
|
176
163
|
}
|
|
177
|
-
|
|
164
|
+
winston.verbose("(IntentForm) next field...");
|
|
178
165
|
|
|
179
166
|
current_field += 1;
|
|
180
167
|
if (current_field === current_form.fields.length) {
|
|
@@ -186,23 +173,22 @@ class IntentForm {
|
|
|
186
173
|
};
|
|
187
174
|
}
|
|
188
175
|
else {
|
|
189
|
-
|
|
176
|
+
winston.debug("(IntentForm) Processing next field: " + current_field);
|
|
190
177
|
await this.setValue(this.CURRENT_FIELD_INDEX_KEY, current_field);
|
|
191
178
|
|
|
192
|
-
|
|
193
|
-
if (this.log) {console.log("checking field:", this.form.fields[current_field].name);}
|
|
179
|
+
winston.debug("(IntentForm)checking field:", this.form.fields[current_field].name);
|
|
194
180
|
|
|
195
181
|
const is_current_value = this.getParam(this.form.fields[current_field].name);
|
|
196
182
|
if (is_current_value) {
|
|
197
|
-
|
|
198
|
-
|
|
183
|
+
winston.debug("(IntentForm) is_current_value! " + is_current_value);
|
|
184
|
+
return await this.getMessage(is_current_value);
|
|
199
185
|
}
|
|
200
186
|
else {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
187
|
+
return {
|
|
188
|
+
message: {
|
|
189
|
+
text: current_form.fields[current_field].label
|
|
190
|
+
}
|
|
191
|
+
};
|
|
206
192
|
}
|
|
207
193
|
|
|
208
194
|
}
|
|
@@ -215,13 +201,13 @@ class IntentForm {
|
|
|
215
201
|
// removing leading and trailing / if regex is sorrounded by (legacy support, to be removed)
|
|
216
202
|
_regex = regex.substring(1, regex.length-1);
|
|
217
203
|
}
|
|
218
|
-
|
|
204
|
+
winston.debug("(IntentForm)Validating using regex: " + _regex);
|
|
219
205
|
try {
|
|
220
206
|
const rg = new RegExp(_regex, "g");
|
|
221
207
|
return rg.test(text);
|
|
222
208
|
}
|
|
223
209
|
catch(error) {
|
|
224
|
-
|
|
210
|
+
winston.error("(IntentForm) Error, invalid regex: " + _regex);
|
|
225
211
|
return true;
|
|
226
212
|
}
|
|
227
213
|
|
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
const { MongodbIntentsMachine } = require('./MongodbIntentsMachine.js');
|
|
2
2
|
const { TiledeskIntentsMachine } = require("./TiledeskIntentsMachine.js");
|
|
3
|
+
const winston = require('../utils/winston.js')
|
|
3
4
|
|
|
4
5
|
class IntentsMachineFactory {
|
|
5
6
|
|
|
6
7
|
static getMachine(bot, botId, projectId, log) {
|
|
7
8
|
let machine;
|
|
8
9
|
if (bot && bot.intentsEngine === "tiledesk-ai") {
|
|
9
|
-
|
|
10
|
+
winston.verbose("(IntentsMachineFactory) bot.intentsEngine is tiledesk-ai");
|
|
10
11
|
machine = new TiledeskIntentsMachine(
|
|
11
12
|
{
|
|
12
13
|
botId: botId
|
|
13
14
|
});
|
|
14
15
|
}
|
|
15
16
|
else if (bot) {
|
|
16
|
-
|
|
17
|
+
winston.verbose("(IntentsMachineFactory) Setting MongodbIntentsMachine with bot:", JSON.stringify(bot));
|
|
17
18
|
machine = new MongodbIntentsMachine({projectId: projectId, language: bot.language, log});
|
|
18
19
|
}
|
|
19
20
|
else {
|
|
20
|
-
|
|
21
|
+
winston.error("bot is null for: " + botId + " on projectId: " + projectId);
|
|
21
22
|
}
|
|
22
23
|
return machine;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
static getBackupMachine(bot, botId, projectId, log) {
|
|
26
27
|
let machine;
|
|
27
|
-
|
|
28
|
+
winston.verbose("(IntentsMachineFactory) Setting MongodbIntentsMachine as Backup Intents Machine on bot:", JSON.stringify(bot));
|
|
28
29
|
machine = new MongodbIntentsMachine({projectId: projectId, language: bot.language, log});
|
|
29
30
|
return machine;
|
|
30
31
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
let Faq = require('
|
|
2
|
-
let Faq_kb = require('
|
|
1
|
+
let Faq = require('../models/faq');
|
|
2
|
+
let Faq_kb = require('../models/faq_kb');
|
|
3
|
+
const winston = require('../utils/winston');
|
|
3
4
|
|
|
4
5
|
class MongodbBotsDataSource {
|
|
5
6
|
|
|
@@ -22,51 +23,33 @@ class MongodbBotsDataSource {
|
|
|
22
23
|
async getBotByIdCache(botId, tdcache) {
|
|
23
24
|
let bot = null;
|
|
24
25
|
if (tdcache) {
|
|
25
|
-
// console.log("getBotByIdCache cache ok");
|
|
26
26
|
let botCacheKey = "cacheman:cachegoose-cache:faq_kbs:id:" + botId;
|
|
27
27
|
try {
|
|
28
28
|
let _bot_as_string = await tdcache.get(botCacheKey);
|
|
29
29
|
const value_type = typeof _bot_as_string;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
console.log("__bot_as_string found in chache:", _bot_as_string);
|
|
33
|
-
console.log("value_type:", value_type);
|
|
34
|
-
}
|
|
30
|
+
winston.debug("(MongodbBotsDataSource) _bot_as_string found in chache: " + _bot_as_string);
|
|
31
|
+
winston.debug("(MongodbBotsDataSource) value_type: " + value_type);
|
|
35
32
|
if (_bot_as_string) {
|
|
36
33
|
bot = JSON.parse(_bot_as_string);
|
|
37
|
-
|
|
38
|
-
if (this.log) {
|
|
39
|
-
console.log("got bot from cache:", JSON.stringify(bot));
|
|
40
|
-
}
|
|
34
|
+
winston.debug("(MongodbBotsDataSource) got bot from cache: ", bot);
|
|
41
35
|
}
|
|
42
36
|
else {
|
|
43
|
-
|
|
44
|
-
if (this.log) {
|
|
45
|
-
console.log("bot not found, getting from datasource...");
|
|
46
|
-
}
|
|
37
|
+
winston.debug("(MongodbBotsDataSource) bot not found, getting from datasource...");
|
|
47
38
|
bot = await this.getBotById(botId);
|
|
48
|
-
|
|
49
|
-
if (this.log) {
|
|
50
|
-
console.log("bot found in datasource:", JSON.stringify(bot));
|
|
51
|
-
}
|
|
39
|
+
winston.debug("(MongodbBotsDataSource) bot found in datasource: ", bot);
|
|
52
40
|
await tdcache.set(botCacheKey, JSON.stringify(bot));
|
|
53
41
|
// DEBUG CODE REMOVE
|
|
54
42
|
// let bot_ = await tdcache.get(botCacheKey);
|
|
55
|
-
// console.log("_bot_as_string from cache debug:", bot_)
|
|
56
43
|
}
|
|
57
44
|
}
|
|
58
45
|
catch(err) {
|
|
59
|
-
|
|
46
|
+
winston.error("(MongodbBotsDataSource) Error getting bot by id: ", err);
|
|
60
47
|
}
|
|
61
48
|
}
|
|
62
49
|
else {
|
|
63
|
-
|
|
64
|
-
console.log("no chache. getting bot from datasource...");
|
|
65
|
-
// }
|
|
50
|
+
winston.verbose("(MongodbBotsDataSource) No chache. getting bot from datasource...");
|
|
66
51
|
bot = await this.getBotById(botId);
|
|
67
|
-
|
|
68
|
-
console.log("bot found in datasource:", JSON.stringify(bot));
|
|
69
|
-
// }
|
|
52
|
+
winston.debug("(MongodbBotsDataSource) bot found in datasource: ", bot);
|
|
70
53
|
}
|
|
71
54
|
return bot;
|
|
72
55
|
}
|
|
@@ -83,11 +66,11 @@ class MongodbBotsDataSource {
|
|
|
83
66
|
let query = { "id_faq_kb": botId, "question": text };
|
|
84
67
|
Faq.find(query).lean().exec(async (err, faqs) => {
|
|
85
68
|
if (err) {
|
|
86
|
-
|
|
69
|
+
winston.error("(MongodbBotsDataSource) Error getting faq object: ", err);
|
|
87
70
|
reject(err);
|
|
88
71
|
}
|
|
89
72
|
else if (faqs && faqs.length > 0 && faqs[0].answer) {
|
|
90
|
-
|
|
73
|
+
winston.debug("(MongodbBotsDataSource) Exact match or action Faq: ", faqs);
|
|
91
74
|
resolve(faqs);
|
|
92
75
|
}
|
|
93
76
|
else {
|
|
@@ -103,34 +86,34 @@ class MongodbBotsDataSource {
|
|
|
103
86
|
* @returns a single Intent
|
|
104
87
|
*/
|
|
105
88
|
async getByIntentDisplayName(botId, key) {
|
|
106
|
-
|
|
89
|
+
winston.debug("(MongodbBotsDataSource) Quering intent by botId: " + botId + " key: " + key );
|
|
107
90
|
return new Promise((resolve, reject) => {
|
|
108
91
|
// var query = { "id_project": this.projectId, "id_faq_kb": botId, "intent_display_name": name};
|
|
109
92
|
let query = null;
|
|
110
93
|
key = key.trim();
|
|
111
94
|
if (key.startsWith("#")) {
|
|
112
95
|
let intent_id = key.substring(key.indexOf("#") + 1);
|
|
113
|
-
|
|
96
|
+
winston.debug("(MongodbBotsDataSource)Query by intent_id: " + intent_id );
|
|
114
97
|
query = { "id_faq_kb": botId, "intent_id": intent_id };
|
|
115
98
|
}
|
|
116
99
|
else {
|
|
117
|
-
|
|
100
|
+
winston.debug("(MongodbBotsDataSource) Query by intent name: " + key);
|
|
118
101
|
query = { "id_faq_kb": botId, "intent_display_name": key };
|
|
119
102
|
}
|
|
120
|
-
|
|
103
|
+
winston.debug("(MongodbBotsDataSource) query", query);
|
|
121
104
|
Faq.find(query).lean().exec( (err, faqs) => {
|
|
122
105
|
if (err) {
|
|
123
|
-
|
|
106
|
+
winston.error("(MongodbBotsDataSource) Error getting faqs ", err);
|
|
124
107
|
return reject(err);
|
|
125
108
|
}
|
|
126
|
-
|
|
109
|
+
winston.debug("(MongodbBotsDataSource) getByIntentDisplayName faqs ", faqs);
|
|
127
110
|
if (faqs && faqs.length > 0) {
|
|
128
111
|
const intent = faqs[0];
|
|
129
|
-
|
|
112
|
+
winston.debug("(MongodbBotsDataSource) intent found: ", intent);
|
|
130
113
|
return resolve(intent);
|
|
131
114
|
}
|
|
132
115
|
else {
|
|
133
|
-
|
|
116
|
+
winston.verbose("(MongodbBotsDataSource) No intent found");
|
|
134
117
|
return resolve(null);
|
|
135
118
|
}
|
|
136
119
|
});
|
|
@@ -139,29 +122,23 @@ class MongodbBotsDataSource {
|
|
|
139
122
|
|
|
140
123
|
async getByIntentDisplayNameCache(botId, key, tdcache) {
|
|
141
124
|
let faq = null;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
console.log("key: -" + key + "-");
|
|
145
|
-
}
|
|
125
|
+
winston.verbose("(MongodbBotsDataSource) botID: -" + botId + "-");
|
|
126
|
+
winston.verbose("(MongodbBotsDataSource) key: -" + key + "-");
|
|
146
127
|
if (tdcache) {
|
|
147
|
-
if (this.log) {console.log("in tdcache");}
|
|
148
128
|
let faqCacheKey = "cacheman:cachegoose-cache:faqs:botid:"+ botId + ":faq:id:" + key;
|
|
149
|
-
|
|
129
|
+
winston.debug("(MongodbBotsDataSource) Looking in cache for: -" + faqCacheKey + "-");
|
|
150
130
|
try {
|
|
151
131
|
let _faq_as_string = await tdcache.get(faqCacheKey);
|
|
152
132
|
const value_type = typeof _faq_as_string;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
console.log("value_type:", value_type);
|
|
156
|
-
}
|
|
133
|
+
winston.debug("(MongodbBotsDataSource)_faq_as_string found in chache: " + _faq_as_string);
|
|
134
|
+
winston.debug("(MongodbBotsDataSource)value_type: " + value_type);
|
|
157
135
|
if (_faq_as_string) {
|
|
158
136
|
faq = JSON.parse(_faq_as_string);
|
|
159
|
-
|
|
137
|
+
winston.debug("(MongodbBotsDataSource) Got faq from cache: ", faq);
|
|
160
138
|
}
|
|
161
139
|
else {
|
|
162
|
-
//console.log("faq not found, getting from datasource...");
|
|
163
140
|
faq = await this.getByIntentDisplayName(botId, key);
|
|
164
|
-
|
|
141
|
+
winston.debug("(MongodbBotsDataSource) faq found in datasource:", faq);
|
|
165
142
|
await tdcache.set(
|
|
166
143
|
faqCacheKey,
|
|
167
144
|
JSON.stringify(faq),
|
|
@@ -169,17 +146,16 @@ class MongodbBotsDataSource {
|
|
|
169
146
|
);
|
|
170
147
|
// DEBUG CODE REMOVE
|
|
171
148
|
// let faq_ = await tdcache.get(faqCacheKey);
|
|
172
|
-
// console.log("_faq_as_string from cache debug:", faq_)
|
|
173
149
|
}
|
|
174
150
|
}
|
|
175
151
|
catch(err) {
|
|
176
|
-
|
|
152
|
+
winston.error("(MongodbBotsDataSource) Error getting faq by id: ", err);
|
|
177
153
|
}
|
|
178
154
|
}
|
|
179
155
|
else {
|
|
180
|
-
|
|
156
|
+
winston.debug("(MongodbBotsDataSource) No chache. Getting faq from datasource...");
|
|
181
157
|
faq = await this.getByIntentDisplayName(botId, key);
|
|
182
|
-
|
|
158
|
+
winston.debug("(MongodbBotsDataSource) Faq found in datasource (no-cache): ", faq);
|
|
183
159
|
}
|
|
184
160
|
return faq;
|
|
185
161
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
let mongoose = require('mongoose');
|
|
2
|
-
let Faq = require('
|
|
2
|
+
let Faq = require('../models/faq');
|
|
3
|
+
const winston = require('../utils/winston');
|
|
3
4
|
|
|
4
5
|
class MongodbIntentsMachine {
|
|
5
6
|
|
|
@@ -19,14 +20,14 @@ class MongodbIntentsMachine {
|
|
|
19
20
|
*/
|
|
20
21
|
async decode(botId, text) {
|
|
21
22
|
return new Promise( (resolve, reject) => {
|
|
22
|
-
|
|
23
|
+
winston.debug("(MongodbIntentsMachine) Mongodb NLP decode intent...");
|
|
23
24
|
// let query = { "id_project": this.projectId, "id_faq_kb": botId };
|
|
24
25
|
let query = { "id_faq_kb": botId };
|
|
25
26
|
var mongoproject = undefined;
|
|
26
27
|
var sort = undefined;
|
|
27
28
|
var search_obj = { "$search": text };
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
winston.debug("(MongodbIntentsMachine) chatbot lang: " + this.language);
|
|
30
31
|
if (this.language) {
|
|
31
32
|
search_obj["$language"] = this.language;
|
|
32
33
|
}
|
|
@@ -35,9 +36,9 @@ class MongodbIntentsMachine {
|
|
|
35
36
|
sort = { score: { $meta: "textScore" } }
|
|
36
37
|
// DA QUI RECUPERO LA RISPOSTA DATO (ID: SE EXT_AI) (QUERY FULLTEXT SE NATIVE-BASIC-AI)
|
|
37
38
|
Faq.find(query, mongoproject).sort(sort).lean().exec( (err, faqs) => {
|
|
38
|
-
|
|
39
|
+
winston.debug("(MongodbIntentsMachine) Found: ", faqs);
|
|
39
40
|
if (err) {
|
|
40
|
-
|
|
41
|
+
winston.error("(MongodbIntentsMachine) Error:", err);
|
|
41
42
|
}
|
|
42
43
|
if (faqs && faqs.length > 0) {
|
|
43
44
|
resolve(faqs);
|