@tiledesk/tiledesk-server 2.10.87 → 2.10.89
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 +19 -0
- package/app.js +4 -0
- package/errorCodes.js +6 -0
- package/event/botEvent.js +89 -42
- package/jobsManager.js +4 -1
- package/models/chatbotTemplates.js +22 -0
- package/models/faq.js +14 -1
- package/models/faq_kb.js +64 -2
- package/models/flowLogs.js +64 -0
- package/models/user.js +7 -0
- package/models/webhook.js +30 -0
- package/package.json +4 -4
- package/routes/auth.js +1 -1
- package/routes/faq.js +6 -0
- package/routes/faq_kb.js +123 -85
- package/routes/logs.js +80 -3
- package/routes/request.js +2 -2
- package/routes/users.js +3 -0
- package/routes/webhook.js +54 -25
- package/routes/webhooks.js +119 -2
- package/services/chatbotService.js +24 -18
- package/services/faqService.js +35 -331
- package/services/logsService.js +59 -0
- package/services/userService.js +3 -2
- package/services/webhookService.js +21 -2
- package/template/chatbot/blank.js +79 -0
- package/template/chatbot/blank_copilot.js +43 -0
- package/template/chatbot/blank_voice.js +108 -0
- package/template/chatbot/blank_voice_twilio.js +115 -0
- package/template/chatbot/blank_webhook.js +43 -0
- package/template/chatbot/empty.js +3 -0
- package/template/chatbot/example.js +88 -0
- package/template/chatbot/handoff.js +25 -0
- package/template/chatbot/index.js +12 -0
- package/template/chatbot/official_copilot.js +717 -0
- package/test/faqkbRoute.js +165 -23
- package/test/webhookRoute.js +247 -2
- package/utils/TdCache.js +3 -3
package/services/faqService.js
CHANGED
@@ -2,18 +2,16 @@ var Faq = require("../models/faq");
|
|
2
2
|
var Faq_kb = require("../models/faq_kb");
|
3
3
|
var winston = require('../config/winston');
|
4
4
|
const botEvent = require('../event/botEvent');
|
5
|
-
const ActionsConstants = require('../models/actionsConstants');
|
6
|
-
const uuidv4 = require('uuid/v4');
|
7
5
|
const chatbotTypes = require("../models/chatbotTypes");
|
8
|
-
|
6
|
+
const chatbotTemplates = require("../models/chatbotTemplates");
|
7
|
+
const templates = require('../template/chatbot');
|
9
8
|
|
10
9
|
class FaqService {
|
11
10
|
|
12
11
|
create(id_project, id_user, data) {
|
13
|
-
var that = this;
|
14
|
-
return new Promise(function (resolve, reject) {
|
15
12
|
|
16
|
-
|
13
|
+
return new Promise((resolve, reject) => {
|
14
|
+
|
17
15
|
var newFaq_kb = new Faq_kb({
|
18
16
|
name: data.name,
|
19
17
|
slug: data.slug,
|
@@ -35,349 +33,57 @@ class FaqService {
|
|
35
33
|
attributes: data.attributes
|
36
34
|
});
|
37
35
|
|
36
|
+
newFaq_kb.save((err, savedFaq_kb) => {
|
38
37
|
|
39
|
-
newFaq_kb.save(function (err, savedFaq_kb) {
|
40
38
|
if (err) {
|
41
|
-
winston.error('
|
39
|
+
winston.error('(FaqService) error saving new chatbot ', err)
|
42
40
|
return reject('Error saving object.');
|
43
41
|
}
|
44
|
-
winston.debug('-> -> SAVED FAQFAQ KB ', savedFaq_kb.toObject())
|
45
42
|
|
43
|
+
winston.debug('(FaqService) saved chatbot ', savedFaq_kb.toObject())
|
46
44
|
botEvent.emit('faqbot.create', savedFaq_kb);
|
47
45
|
|
48
46
|
winston.debug('type ' + data.type)
|
49
47
|
|
50
|
-
let template = "empty";
|
51
|
-
|
52
48
|
if (data.type === "internal" || data.type === "tilebot") {
|
53
|
-
if (data.subtype) {
|
54
|
-
if (data.subtype === chatbotTypes.WEBHOOK) {
|
55
|
-
if (data.template && data.template !== 'blank') {
|
56
|
-
template = data.template;
|
57
|
-
} else {
|
58
|
-
template = "blank_webhook"
|
59
|
-
}
|
60
|
-
} else if (data.subtype === chatbotTypes.COPILOT) {
|
61
|
-
if (data.template && data.template !== 'blank') {
|
62
|
-
template = data.template;
|
63
|
-
} else {
|
64
|
-
template = "blank_copilot"
|
65
|
-
}
|
66
|
-
} else if (data.subtype === chatbotTypes.CHATBOT) {
|
67
|
-
if (data.template) {
|
68
|
-
template = data.template;
|
69
|
-
}
|
70
|
-
}
|
71
|
-
} else {
|
72
|
-
if (data.template) {
|
73
|
-
template = data.template;
|
74
|
-
}
|
75
|
-
}
|
76
49
|
|
50
|
+
let template = this.#resolveTemplate(data.subtype, data.template);
|
77
51
|
winston.debug('template ' + template);
|
78
|
-
that.createGreetingsAndOperationalsFaqs(savedFaq_kb._id, savedFaq_kb.createdBy, savedFaq_kb.id_project, template);
|
79
|
-
} else {
|
80
|
-
winston.debug('external bot: ', savedFaq_kb);
|
81
|
-
}
|
82
52
|
|
53
|
+
let options = {};
|
54
|
+
if (data.namespace_id) {
|
55
|
+
options.namespace_id = data.namespace_id;
|
56
|
+
}
|
57
|
+
|
58
|
+
this.createGreetingsAndOperationalsFaqs(savedFaq_kb._id, savedFaq_kb.createdBy, savedFaq_kb.id_project, template, options);
|
83
59
|
|
60
|
+
} else {
|
61
|
+
winston.debug('(FaqService) Chatbot type: external bot');
|
62
|
+
}
|
84
63
|
|
85
64
|
return resolve(savedFaq_kb);
|
86
65
|
});
|
66
|
+
|
87
67
|
});
|
88
68
|
}
|
89
69
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
// url: url,
|
99
|
-
// id_project: projectid,
|
100
|
-
// webhook_url: webhook_url,
|
101
|
-
// webhook_enabled: webhook_enabled,
|
102
|
-
// type: type,
|
103
|
-
// subtype: subtype,
|
104
|
-
// language: language,
|
105
|
-
// public: false,
|
106
|
-
// certified: false,
|
107
|
-
// mainCategory: mainCategory,
|
108
|
-
// intentsEngine: intentsEngine,
|
109
|
-
// trashed: false,
|
110
|
-
// createdBy: user_id,
|
111
|
-
// updatedBy: user_id,
|
112
|
-
// attributes: attributes
|
113
|
-
// });
|
114
|
-
|
115
|
-
|
116
|
-
// newFaq_kb.save(function (err, savedFaq_kb) {
|
117
|
-
// if (err) {
|
118
|
-
// winston.error('--- > ERROR ', err)
|
119
|
-
// return reject('Error saving object.');
|
120
|
-
// }
|
121
|
-
// winston.debug('-> -> SAVED FAQFAQ KB ', savedFaq_kb.toObject())
|
122
|
-
|
123
|
-
// botEvent.emit('faqbot.create', savedFaq_kb);
|
124
|
-
|
125
|
-
// winston.debug('type ' + type)
|
126
|
-
|
127
|
-
// if (type === "internal" || type === "tilebot") {
|
128
|
-
|
129
|
-
// if (!subtype) {
|
130
|
-
// if (!template) {
|
131
|
-
// template = "empty";
|
132
|
-
// }
|
133
|
-
// } else {
|
134
|
-
|
135
|
-
// if (subtype === chatbotTypes.CHATBOT) {
|
136
|
-
// if (!template) {
|
137
|
-
// template = "empty";
|
138
|
-
// }
|
139
|
-
// } else if (subtype === chatbotTypes.WEBHOOK) {
|
140
|
-
// template = "blank_webhook"
|
141
|
-
// } else if (subtype === chatbotTypes.COPILOT) {
|
142
|
-
// template = "blank_copilot"
|
143
|
-
// } else {
|
144
|
-
// template = "empty";
|
145
|
-
// }
|
146
|
-
// }
|
147
|
-
|
148
|
-
// if (!template) {
|
149
|
-
// template = "empty";
|
150
|
-
// }
|
151
|
-
// winston.debug('template ' + template);
|
152
|
-
// that.createGreetingsAndOperationalsFaqs(savedFaq_kb._id, savedFaq_kb.createdBy, savedFaq_kb.id_project, template);
|
153
|
-
// } else {
|
154
|
-
// winston.debug('external bot: ', savedFaq_kb);
|
155
|
-
// }
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
// return resolve(savedFaq_kb);
|
160
|
-
// });
|
161
|
-
// });
|
162
|
-
// }
|
163
|
-
|
164
|
-
createGreetingsAndOperationalsFaqs(faq_kb_id, created_by, projectid, template) {
|
165
|
-
var that = this;
|
166
|
-
return new Promise(function (resolve, reject) {
|
167
|
-
|
168
|
-
// aggiungi esempio tdAction con intent_id
|
169
|
-
|
170
|
-
// TODO non scatta i trigger sui rest hook. fare?
|
171
|
-
winston.debug('template: ' + template);
|
172
|
-
|
173
|
-
var faqsArray;
|
174
|
-
|
175
|
-
if (template === "example") {
|
176
|
-
|
177
|
-
faqsArray = [
|
178
|
-
{ 'question': 'Hi', 'answer': 'Hi', 'topic': 'greetings' },
|
179
|
-
{ 'question': 'Hello', 'answer': 'Hello', 'topic': 'greetings' },
|
180
|
-
{ 'question': 'Who are you?', 'answer': 'Hi, I\'m a bot 🤖. You can find more about me [here](https://tiledesk.com/chatbot-for-customer-service).\ntdImage:https://console.tiledesk.com/assets/images/tily-welcomebot.gif\n* See the website https://tiledesk.com/\n* Back to start tdAction:start', 'topic': 'greetings' },
|
181
|
-
{ 'question': '👨🏻🦰 I want an agent', 'answer': 'We are looking for an operator.. ' + ActionsConstants.CHAT_ACTION_MESSAGE.AGENT, 'intent_display_name': 'agent_handoff', 'topic': 'internal' },
|
182
|
-
{ 'question': 'Close\nResolved', 'answer': ActionsConstants.CHAT_ACTION_MESSAGE.CLOSE, 'topic': 'internal' },
|
183
|
-
{ 'question': '\\start', 'answer': 'Hello 👋. I\'m a bot 🤖.\n\nChoose one of the options below or write a message to reach our staff.\n* Who are you?\n* Where are you?\n* What can you do?\n* 👨🏻🦰 I want an agent', 'intent_display_name': 'start', 'topic': 'internal' },
|
184
|
-
{ 'question': 'defaultFallback', 'answer': 'I can not provide an adequate answer. Write a new question or talk to a human agent.\n* Back to start tdAction:start\n* See the docs https://docs.tiledesk.com/\n* 👨🏻🦰 I want an agent', 'intent_display_name': 'defaultFallback', 'topic': 'internal' }, //TODO se metto spazio n * nn va
|
185
|
-
{ 'question': 'What can you do?', 'answer': 'Using natural language processing, I\'m able to find the best answer for your users. I also support images, videos etc.. Let\'s try:\n* Sample Image\n* Sample Video\n* Sample Action tdAction:action1\n* Sample Frame\n* Back to start tdAction:start', 'topic': 'sample' },
|
186
|
-
{ 'question': 'Sample Image', 'answer': 'tdImage:https://tiledesk.com/wp-content/uploads/2022/07/tiledesk_v2.png\n* What can you do?\n* Back to start tdAction:start', 'topic': 'sample' },
|
187
|
-
{ 'question': 'Sample Frame', 'answer': 'tdFrame:https://www.emanueleferonato.com/wp-content/uploads/2019/02/runner/\n* What can you do?\n* Back to start tdAction:start', 'topic': 'sample' },
|
188
|
-
{ 'question': 'Sample Video', 'answer': 'tdVideo:https://www.youtube.com/embed/EngW7tLk6R8\n* What can you do?\n* Back to start tdAction:start', 'topic': 'sample' },
|
189
|
-
{ 'question': 'Where are you?', 'answer': 'We are here ❤️\ntdFrame:https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d6087916.923447935!2d8.234804542117423!3d41.836572992140624!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x12d4fe82448dd203%3A0xe22cf55c24635e6f!2sItaly!5e0!3m2!1sen!2sit!4v1613657475377!5m2!1sen!2sit\n* Back to start tdAction:start', 'topic': 'sample' },
|
190
|
-
// { 'question': 'Sample Webhook', 'answer': 'tdWebhook:https://tiledesk-bot-webhook.tiledesk.repl.co', 'topic': 'sample' },
|
191
|
-
{ 'question': 'Sample Action', 'answer': 'Hello 👋 Would you like to take a closer look at our offer?\n* Yes, please tdAction:yes_action\n* No tdAction:no_action', 'intent_display_name': 'action1', 'topic': 'sample' },
|
192
|
-
{ 'question': 'Yes Action', 'answer': 'Great! Take a look here:\n* Tiledesk Pricing https://tiledesk.com/pricing-cloud/', 'intent_display_name': 'yes_action', 'topic': 'sample' },
|
193
|
-
{ 'question': 'No Action', 'answer': 'All right! If you need anything, let us know.', 'intent_display_name': 'no_action', 'topic': 'sample' },
|
194
|
-
|
195
|
-
|
196
|
-
// action button nn si può fare perche gli id cambiano
|
197
|
-
]
|
198
|
-
|
199
|
-
}
|
200
|
-
|
201
|
-
if (template === "blank") {
|
202
|
-
|
203
|
-
let custom_intent_id = uuidv4();
|
204
|
-
// faqsArray = [
|
205
|
-
// { 'question': '\\start', 'answer': 'Hello', 'intent_display_name': 'start', 'topic': 'internal' },
|
206
|
-
// { 'question': 'defaultFallback', 'answer': 'I can not provide an adequate answer. Write a new question or talk to a human agent.\n* Back to start tdAction:start\n* See the docs https://docs.tiledesk.com/\n* 👨🏻🦰 I want an agent', 'intent_display_name': 'defaultFallback', 'topic': 'internal' }, //TODO se metto spazio n * nn va
|
207
|
-
// ]
|
208
|
-
faqsArray = [
|
209
|
-
{
|
210
|
-
"webhook_enabled": false,
|
211
|
-
"enabled": true,
|
212
|
-
"actions": [{
|
213
|
-
"_tdActionType": "reply",
|
214
|
-
"text": "I didn't understand. Can you rephrase your question?",
|
215
|
-
"attributes": {
|
216
|
-
"commands": [{
|
217
|
-
"type": "wait",
|
218
|
-
"time": 500
|
219
|
-
}, {
|
220
|
-
"type": "message",
|
221
|
-
"message": {
|
222
|
-
"type": "text",
|
223
|
-
"text": "I didn't understand. Can you rephrase your question?"
|
224
|
-
}
|
225
|
-
}]
|
226
|
-
}
|
227
|
-
}],
|
228
|
-
"intent_display_name": "defaultFallback",
|
229
|
-
"attributes": {
|
230
|
-
"position": {
|
231
|
-
"x": 714,
|
232
|
-
"y": 528
|
233
|
-
}
|
234
|
-
}
|
235
|
-
}, {
|
236
|
-
"webhook_enabled": false,
|
237
|
-
"enabled": true,
|
238
|
-
"actions": [{
|
239
|
-
"_tdActionType": "intent",
|
240
|
-
"intentName": "#" + custom_intent_id
|
241
|
-
}],
|
242
|
-
"question": "\\start",
|
243
|
-
"intent_display_name": "start",
|
244
|
-
"attributes": {
|
245
|
-
"position": {
|
246
|
-
"x": 172,
|
247
|
-
"y": 384
|
248
|
-
}
|
249
|
-
}
|
250
|
-
}, {
|
251
|
-
"webhook_enabled": false,
|
252
|
-
"enabled": true,
|
253
|
-
"actions": [{
|
254
|
-
"_tdActionType": "reply",
|
255
|
-
"attributes": {
|
256
|
-
"disableInputMessage": false,
|
257
|
-
"commands": [{
|
258
|
-
"type": "wait",
|
259
|
-
"time": 500
|
260
|
-
}, {
|
261
|
-
"type": "message",
|
262
|
-
"message": {
|
263
|
-
"type": "text",
|
264
|
-
"text": "Hi, how can I help you?"
|
265
|
-
}
|
266
|
-
}]
|
267
|
-
},
|
268
|
-
"text": "Hi, how can I help you?\r\n"
|
269
|
-
}],
|
270
|
-
"intent_display_name": "welcome",
|
271
|
-
"intent_id": custom_intent_id,
|
272
|
-
"attributes": {
|
273
|
-
"position": {
|
274
|
-
"x": 714,
|
275
|
-
"y": 113
|
276
|
-
}
|
277
|
-
}
|
278
|
-
}
|
279
|
-
]
|
280
|
-
|
281
|
-
}
|
282
|
-
|
283
|
-
|
284
|
-
if (template === "handoff") {
|
285
|
-
|
286
|
-
faqsArray = [
|
287
|
-
{ 'question': '\\start', 'answer': 'Hello', 'intent_display_name': 'start', 'topic': 'internal' },
|
288
|
-
{ 'question': '👨🏻🦰 I want an agent', 'answer': 'We are looking for an operator.. ' + ActionsConstants.CHAT_ACTION_MESSAGE.AGENT, 'intent_display_name': 'agent_handoff', 'topic': 'internal' },
|
289
|
-
{ 'question': 'defaultFallback', 'answer': 'I can not provide an adequate answer. Write a new question or talk to a human agent.\n* Back to start tdAction:start\n* See the docs https://docs.tiledesk.com/\n* 👨🏻🦰 I want an agent', 'intent_display_name': 'defaultFallback', 'topic': 'internal' }, //TODO se metto spazio n * nn va
|
290
|
-
]
|
291
|
-
|
292
|
-
}
|
293
|
-
|
294
|
-
if (template === "empty") {
|
295
|
-
faqsArray = [];
|
296
|
-
}
|
297
|
-
|
298
|
-
if (template === "blank_webhook") {
|
299
|
-
let custom_intent_id = uuidv4();
|
70
|
+
#resolveTemplate(subtype, template) {
|
71
|
+
subtype = chatbotTemplates[subtype] ? subtype : 'chatbot';
|
72
|
+
const { templates, default: defaultTemplate } = chatbotTemplates[subtype];
|
73
|
+
if (template && templates.includes(template)) {
|
74
|
+
return template;
|
75
|
+
}
|
76
|
+
return defaultTemplate;
|
77
|
+
}
|
300
78
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
"enabled": true,
|
305
|
-
"actions": [{
|
306
|
-
"_tdActionType": "intent",
|
307
|
-
"intentName": "#" + custom_intent_id
|
308
|
-
}],
|
309
|
-
"question": "",
|
310
|
-
"intent_display_name": "webhook",
|
311
|
-
"attributes": {
|
312
|
-
"position": {
|
313
|
-
"x": 172,
|
314
|
-
"y": 384
|
315
|
-
}
|
316
|
-
}
|
317
|
-
},
|
318
|
-
{
|
319
|
-
"webhook_enabled": false,
|
320
|
-
"enabled": true,
|
321
|
-
"actions": [{
|
322
|
-
"_tdActionType": "web_response",
|
323
|
-
"status": 200,
|
324
|
-
"bodyType": "json",
|
325
|
-
"payload": '{"success": true , "message": "Your webhook is online!"}'
|
326
|
-
}],
|
327
|
-
"intent_display_name": "response",
|
328
|
-
"intent_id": custom_intent_id,
|
329
|
-
"attributes": {
|
330
|
-
"position": {
|
331
|
-
"x": 714,
|
332
|
-
"y": 113
|
333
|
-
}
|
334
|
-
}
|
335
|
-
}
|
336
|
-
]
|
337
|
-
}
|
79
|
+
createGreetingsAndOperationalsFaqs(faq_kb_id, created_by, projectid, template, options) {
|
80
|
+
|
81
|
+
return new Promise( async (resolve, reject) => {
|
338
82
|
|
339
|
-
|
340
|
-
let custom_intent_id = uuidv4();
|
83
|
+
winston.debug('(FaqService) create faqs from template: ' + template);
|
341
84
|
|
342
|
-
|
343
|
-
{
|
344
|
-
"webhook_enabled": false,
|
345
|
-
"enabled": true,
|
346
|
-
"actions": [{
|
347
|
-
"_tdActionType": "intent",
|
348
|
-
"intentName": "#" + custom_intent_id
|
349
|
-
}],
|
350
|
-
"question": "",
|
351
|
-
"intent_display_name": "webhook",
|
352
|
-
"attributes": {
|
353
|
-
"position": {
|
354
|
-
"x": 172,
|
355
|
-
"y": 384
|
356
|
-
}
|
357
|
-
}
|
358
|
-
},
|
359
|
-
{
|
360
|
-
"webhook_enabled": false,
|
361
|
-
"enabled": true,
|
362
|
-
"actions": [{
|
363
|
-
"_tdActionType": "web_response",
|
364
|
-
"status": 200,
|
365
|
-
"bodyType": "json",
|
366
|
-
"payload": '{"title": "Official Copilot", "text": "This is a suggestion!"}'
|
367
|
-
}],
|
368
|
-
"intent_display_name": "response",
|
369
|
-
"intent_id": custom_intent_id,
|
370
|
-
"attributes": {
|
371
|
-
"position": {
|
372
|
-
"x": 714,
|
373
|
-
"y": 113
|
374
|
-
}
|
375
|
-
}
|
376
|
-
}
|
377
|
-
]
|
378
|
-
}
|
85
|
+
let faqsArray = templates[template](options);
|
379
86
|
|
380
|
-
|
381
87
|
faqsArray.forEach(faq => {
|
382
88
|
|
383
89
|
var newFaq = new Faq({
|
@@ -398,13 +104,11 @@ class FaqService {
|
|
398
104
|
|
399
105
|
newFaq.save(function (err, savedFaq) {
|
400
106
|
if (err) {
|
401
|
-
winston.error('
|
107
|
+
winston.error('(FaqService) error saving faq: ', err)
|
402
108
|
return reject({ success: false, msg: 'Error saving object.', err: err });
|
403
109
|
}
|
404
|
-
|
405
|
-
winston.debug('
|
406
|
-
winston.debug('FAQ SERVICE (save new faq) - ANSWER OF THE NEW GREETINGS FAQ CREATED ', savedFaq.answer)
|
407
|
-
winston.debug('FAQ SERVICE (save new faq) - ID FAQKB GET IN THE OBJECT OF NEW FAQ CREATED ', savedFaq.id_faq_kb)
|
110
|
+
|
111
|
+
winston.debug('(FaqService) saved new faq for chatbot ' + savedFaq.id_faq_kb);
|
408
112
|
|
409
113
|
})
|
410
114
|
});
|
@@ -413,7 +117,7 @@ class FaqService {
|
|
413
117
|
|
414
118
|
getAll(faq_kb_id) {
|
415
119
|
|
416
|
-
winston.debug("(
|
120
|
+
winston.debug("(FaqService) Get all faq for chatbot: ", faq_kb_id);
|
417
121
|
|
418
122
|
return new Promise((resolve, reject) => {
|
419
123
|
|
@@ -0,0 +1,59 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const { FlowLogs } = require("../models/flowLogs");
|
4
|
+
const default_log_level = 'info';
|
5
|
+
|
6
|
+
const levels = { error: 0, warn: 1, info: 2, debug: 3 };
|
7
|
+
|
8
|
+
class LogsService {
|
9
|
+
|
10
|
+
async getLastRows(request_id, limit, logLevel) {
|
11
|
+
let level = logLevel || default_log_level;
|
12
|
+
if (level === 'default') {
|
13
|
+
level = default_log_level
|
14
|
+
}
|
15
|
+
let nlevel = levels[level];
|
16
|
+
return FlowLogs.aggregate([
|
17
|
+
{ $match: { request_id: request_id } },
|
18
|
+
{ $unwind: "$rows" },
|
19
|
+
{ $match: { "rows.nlevel": { $lt: nlevel } } },
|
20
|
+
{ $sort: { "rows.timestamp": -1, "rows._id": -1 } },
|
21
|
+
{ $limit: limit }
|
22
|
+
]).then(rows => rows.reverse())
|
23
|
+
}
|
24
|
+
|
25
|
+
async getOlderRows(request_id, limit, logLevel, timestamp) {
|
26
|
+
let level = logLevel || default_log_level;
|
27
|
+
if (level === 'default') {
|
28
|
+
level = default_log_level
|
29
|
+
}
|
30
|
+
let nlevel = levels[level];
|
31
|
+
return FlowLogs.aggregate([
|
32
|
+
{ $match: { request_id: request_id } },
|
33
|
+
{ $unwind: "$rows" },
|
34
|
+
{ $match: { "rows.nlevel": { $lt: nlevel }, "rows.timestamp": { $lt: timestamp } } },
|
35
|
+
{ $sort: { "rows.timestamp": -1, "rows._id": -1 } },
|
36
|
+
{ $limit: limit }
|
37
|
+
]).then(rows => rows.reverse())
|
38
|
+
}
|
39
|
+
|
40
|
+
async getNewerRows(request_id, limit, logLevel, timestamp) {
|
41
|
+
let level = logLevel || default_log_level;
|
42
|
+
if (level === 'default') {
|
43
|
+
level = default_log_level
|
44
|
+
}
|
45
|
+
let nlevel = levels[level];
|
46
|
+
return FlowLogs.aggregate([
|
47
|
+
{ $match: { request_id: request_id } },
|
48
|
+
{ $unwind: "$rows" },
|
49
|
+
{ $match: { "rows.nlevel": { $lt: nlevel }, "rows.timestamp": { $gt: timestamp } } },
|
50
|
+
{ $sort: { "rows.timestamp": 1, "rows._id": 1 } },
|
51
|
+
{ $limit: limit }
|
52
|
+
])
|
53
|
+
}
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
let logsService = new LogsService();
|
58
|
+
|
59
|
+
module.exports = logsService;
|
package/services/userService.js
CHANGED
@@ -5,7 +5,7 @@ var winston = require('../config/winston');
|
|
5
5
|
|
6
6
|
class UserService {
|
7
7
|
|
8
|
-
signup ( email, password, firstname, lastname, emailverified) {
|
8
|
+
signup ( email, password, firstname, lastname, emailverified, phone) {
|
9
9
|
return new Promise(function (resolve, reject) {
|
10
10
|
|
11
11
|
// winston.info("email: " + email);
|
@@ -21,7 +21,8 @@ class UserService {
|
|
21
21
|
password: password,
|
22
22
|
firstname: firstname,
|
23
23
|
lastname: lastname,
|
24
|
-
emailverified: emailverified,
|
24
|
+
emailverified: emailverified,
|
25
|
+
phone: phone
|
25
26
|
});
|
26
27
|
// save the user
|
27
28
|
newUser.save(function (err, savedUser) {
|
@@ -3,6 +3,7 @@ const httpUtil = require("../utils/httpUtil");
|
|
3
3
|
const uuidv4 = require('uuid/v4');
|
4
4
|
var jwt = require('jsonwebtoken');
|
5
5
|
var winston = require('../config/winston');
|
6
|
+
const errorCodes = require("../errorCodes");
|
6
7
|
|
7
8
|
const port = process.env.PORT || '3000';
|
8
9
|
let TILEBOT_ENDPOINT = "http://localhost:" + port + "/modules/tilebot/";;
|
@@ -13,7 +14,7 @@ winston.debug("TILEBOT_ENDPOINT: " + TILEBOT_ENDPOINT);
|
|
13
14
|
|
14
15
|
class WebhookService {
|
15
16
|
|
16
|
-
async run(webhook, payload) {
|
17
|
+
async run(webhook, payload, dev, redis_client) {
|
17
18
|
|
18
19
|
return new Promise(async (resolve, reject) => {
|
19
20
|
|
@@ -28,9 +29,26 @@ class WebhookService {
|
|
28
29
|
reject("Chatbot not found with id " + webhook.chatbot_id);
|
29
30
|
}
|
30
31
|
|
32
|
+
let chatbot_id
|
33
|
+
if (chatbot.url) {
|
34
|
+
chatbot_id = chatbot.url.substr(chatbot.url.lastIndexOf("/") + 1)
|
35
|
+
}
|
36
|
+
|
37
|
+
if (dev) {
|
38
|
+
chatbot_id = webhook.chatbot_id;
|
39
|
+
let key = "logs:webhook:" + webhook.id_project + ":" + webhook.webhook_id;
|
40
|
+
let value = await redis_client.get(key);
|
41
|
+
if (!value) {
|
42
|
+
reject({ success: false, code: errorCodes.WEBHOOK.ERRORS.NO_PRELOADED_DEV_REQUEST})
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
let json_value = JSON.parse(value);
|
46
|
+
payload.preloaded_request_id = json_value.request_id;
|
47
|
+
}
|
48
|
+
|
31
49
|
let token = await this.generateChatbotToken(chatbot);
|
32
50
|
|
33
|
-
let url = TILEBOT_ENDPOINT + 'block/' + webhook.id_project + "/" +
|
51
|
+
let url = TILEBOT_ENDPOINT + 'block/' + webhook.id_project + "/" + chatbot_id + "/" + webhook.block_id;
|
34
52
|
winston.info("Webhook chatbot URL: " + url);
|
35
53
|
|
36
54
|
payload.async = webhook.async;
|
@@ -38,6 +56,7 @@ class WebhookService {
|
|
38
56
|
|
39
57
|
if (process.env.NODE_ENV === 'test') {
|
40
58
|
resolve({ success: true, message: "Webhook disabled in test mode" });
|
59
|
+
return;
|
41
60
|
}
|
42
61
|
|
43
62
|
await httpUtil.post(url, payload).then((response) => {
|
@@ -0,0 +1,79 @@
|
|
1
|
+
const uuidv4 = require('uuid/v4');
|
2
|
+
|
3
|
+
module.exports = function generateTemplate(options) {
|
4
|
+
|
5
|
+
const custom_intent_id = uuidv4();
|
6
|
+
|
7
|
+
return [
|
8
|
+
{
|
9
|
+
"webhook_enabled": false,
|
10
|
+
"enabled": true,
|
11
|
+
"actions": [{
|
12
|
+
"_tdActionType": "reply",
|
13
|
+
"text": "I didn't understand. Can you rephrase your question?",
|
14
|
+
"attributes": {
|
15
|
+
"commands": [{
|
16
|
+
"type": "wait",
|
17
|
+
"time": 500
|
18
|
+
}, {
|
19
|
+
"type": "message",
|
20
|
+
"message": {
|
21
|
+
"type": "text",
|
22
|
+
"text": "I didn't understand. Can you rephrase your question?"
|
23
|
+
}
|
24
|
+
}]
|
25
|
+
}
|
26
|
+
}],
|
27
|
+
"intent_display_name": "defaultFallback",
|
28
|
+
"attributes": {
|
29
|
+
"position": {
|
30
|
+
"x": 714,
|
31
|
+
"y": 528
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}, {
|
35
|
+
"webhook_enabled": false,
|
36
|
+
"enabled": true,
|
37
|
+
"actions": [{
|
38
|
+
"_tdActionType": "intent",
|
39
|
+
"intentName": "#" + custom_intent_id
|
40
|
+
}],
|
41
|
+
"question": "\\start",
|
42
|
+
"intent_display_name": "start",
|
43
|
+
"attributes": {
|
44
|
+
"position": {
|
45
|
+
"x": 172,
|
46
|
+
"y": 384
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}, {
|
50
|
+
"webhook_enabled": false,
|
51
|
+
"enabled": true,
|
52
|
+
"actions": [{
|
53
|
+
"_tdActionType": "reply",
|
54
|
+
"attributes": {
|
55
|
+
"disableInputMessage": false,
|
56
|
+
"commands": [{
|
57
|
+
"type": "wait",
|
58
|
+
"time": 500
|
59
|
+
}, {
|
60
|
+
"type": "message",
|
61
|
+
"message": {
|
62
|
+
"type": "text",
|
63
|
+
"text": "Hi, how can I help you?"
|
64
|
+
}
|
65
|
+
}]
|
66
|
+
},
|
67
|
+
"text": "Hi, how can I help you?\r\n"
|
68
|
+
}],
|
69
|
+
"intent_display_name": "welcome",
|
70
|
+
"intent_id": custom_intent_id,
|
71
|
+
"attributes": {
|
72
|
+
"position": {
|
73
|
+
"x": 714,
|
74
|
+
"y": 113
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
]
|
79
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
const uuidv4 = require('uuid/v4');
|
2
|
+
|
3
|
+
module.exports = function generateTemplate(options) {
|
4
|
+
|
5
|
+
const custom_intent_id = uuidv4();
|
6
|
+
|
7
|
+
return [
|
8
|
+
{
|
9
|
+
"webhook_enabled": false,
|
10
|
+
"enabled": true,
|
11
|
+
"actions": [{
|
12
|
+
"_tdActionType": "intent",
|
13
|
+
"intentName": "#" + custom_intent_id
|
14
|
+
}],
|
15
|
+
"question": "",
|
16
|
+
"intent_display_name": "webhook",
|
17
|
+
"attributes": {
|
18
|
+
"position": {
|
19
|
+
"x": 172,
|
20
|
+
"y": 384
|
21
|
+
}
|
22
|
+
}
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"webhook_enabled": false,
|
26
|
+
"enabled": true,
|
27
|
+
"actions": [{
|
28
|
+
"_tdActionType": "web_response",
|
29
|
+
"status": 200,
|
30
|
+
"bodyType": "json",
|
31
|
+
"payload": '{"title": "Official Copilot", "text": "This is a suggestion!"}'
|
32
|
+
}],
|
33
|
+
"intent_display_name": "response",
|
34
|
+
"intent_id": custom_intent_id,
|
35
|
+
"attributes": {
|
36
|
+
"position": {
|
37
|
+
"x": 714,
|
38
|
+
"y": 113
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
]
|
43
|
+
}
|