@tiledesk/tiledesk-server 2.4.47 → 2.4.49
Sign up to get free protection for your applications and to get access to all the features.
- package/app.js +3 -0
- package/models/openai_kbs.js +30 -0
- package/package.json +1 -1
- package/routes/email.js +6 -1
- package/routes/faq.js +3 -1
- package/routes/openai_kbs.js +58 -0
- package/routes/request.js +61 -1
- package/services/faqService.js +141 -115
- package/test/faqRoute.js +1 -1
- package/test/faqkbRoute.js +42 -0
- package/test/openaiKbsRoute.js +75 -0
package/app.js
CHANGED
@@ -112,6 +112,7 @@ var jwtroute = require('./routes/jwt');
|
|
112
112
|
var key = require('./routes/key');
|
113
113
|
var widgets = require('./routes/widget');
|
114
114
|
var widgetsLoader = require('./routes/widgetLoader');
|
115
|
+
var openai_kbs = require('./routes/openai_kbs');
|
115
116
|
|
116
117
|
// var admin = require('./routes/admin');
|
117
118
|
var faqpub = require('./routes/faqpub');
|
@@ -549,6 +550,8 @@ app.use('/:projectid/emails',[passport.authenticate(['basic', 'jwt'], { session:
|
|
549
550
|
|
550
551
|
app.use('/:projectid/properties',[passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRoleOrTypes('agent', ['bot','subscription'])], property);
|
551
552
|
|
553
|
+
app.use('/:projectid/openai_kbs', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRoleOrTypes('agent')], openai_kbs);
|
554
|
+
|
552
555
|
|
553
556
|
|
554
557
|
if (pubModulesManager) {
|
@@ -0,0 +1,30 @@
|
|
1
|
+
var mongoose = require('mongoose');
|
2
|
+
var Schema = mongoose.Schema;
|
3
|
+
var winston = require('../config/winston');
|
4
|
+
|
5
|
+
var OpenaiKbsSchema = new Schema({
|
6
|
+
name: {
|
7
|
+
type: String,
|
8
|
+
required: true
|
9
|
+
},
|
10
|
+
url: {
|
11
|
+
type: String,
|
12
|
+
required: true
|
13
|
+
},
|
14
|
+
id_project: {
|
15
|
+
type: String,
|
16
|
+
required: true,
|
17
|
+
index: true
|
18
|
+
},
|
19
|
+
gptkey: {
|
20
|
+
type: String,
|
21
|
+
required: true
|
22
|
+
},
|
23
|
+
createdAt: {
|
24
|
+
type: Date,
|
25
|
+
default: Date.now,
|
26
|
+
}
|
27
|
+
});
|
28
|
+
|
29
|
+
|
30
|
+
module.exports = mongoose.model('OpenaiKbs', OpenaiKbsSchema);
|
package/package.json
CHANGED
package/routes/email.js
CHANGED
@@ -303,7 +303,7 @@ if (process.env.ENABLE_TEST_EMAIL_ENDPOINT==true || process.env.ENABLE_TEST_EMAI
|
|
303
303
|
|
304
304
|
|
305
305
|
//TODO add cc
|
306
|
-
router.post('/send',
|
306
|
+
router.post('/internal/send',
|
307
307
|
async (req, res) => {
|
308
308
|
let to = req.body.to;
|
309
309
|
winston.debug("to: " + to);
|
@@ -325,6 +325,8 @@ router.post('/send',
|
|
325
325
|
let replyto = req.body.replyto;
|
326
326
|
winston.debug("replyto: " + replyto);
|
327
327
|
|
328
|
+
winston.info("Sending an email with text : " + text + " to " + to);
|
329
|
+
|
328
330
|
//sendEmailDirect(to, text, project, request_id, subject, tokenQueryString, sourcePage, payload)
|
329
331
|
emailService.sendEmailDirect(newto, text, req.project, request_id, subject, undefined, undefined, undefined, replyto);
|
330
332
|
|
@@ -332,4 +334,7 @@ router.post('/send',
|
|
332
334
|
|
333
335
|
});
|
334
336
|
|
337
|
+
|
338
|
+
|
339
|
+
|
335
340
|
module.exports = router;
|
package/routes/faq.js
CHANGED
@@ -168,10 +168,12 @@ router.post('/', function (req, res) {
|
|
168
168
|
if (req.body.actions) {
|
169
169
|
newFaq.actions = req.body.actions
|
170
170
|
}
|
171
|
-
|
172
171
|
if (req.body.attributes) {
|
173
172
|
newFaq.attributes = req.body.attributes
|
174
173
|
}
|
174
|
+
if (req.body.intent_id) {
|
175
|
+
newFaq.intent_id = req.body.intent_id;
|
176
|
+
}
|
175
177
|
|
176
178
|
newFaq.save(function (err, savedFaq) {
|
177
179
|
if (err) {
|
@@ -0,0 +1,58 @@
|
|
1
|
+
var express = require('express');
|
2
|
+
var OpenaiKbs = require('../models/openai_kbs');
|
3
|
+
var router = express.Router();
|
4
|
+
|
5
|
+
|
6
|
+
router.get('/', async (req, res) => {
|
7
|
+
|
8
|
+
let project_id = req.projectid;
|
9
|
+
|
10
|
+
OpenaiKbs.find({ id_project: project_id }, (err, kbs) => {
|
11
|
+
if (err) {
|
12
|
+
console.error("find all kbs error: ", err);
|
13
|
+
return res.status(500).send({ success: false, error: err });
|
14
|
+
} else {
|
15
|
+
return res.status(200).send(kbs);
|
16
|
+
}
|
17
|
+
})
|
18
|
+
})
|
19
|
+
|
20
|
+
router.post('/', async (req, res) => {
|
21
|
+
|
22
|
+
let body = req.body;
|
23
|
+
|
24
|
+
let new_kbs = new OpenaiKbs({
|
25
|
+
name: body.name,
|
26
|
+
url: body.url,
|
27
|
+
id_project: req.projectid,
|
28
|
+
gptkey: req.body.gptkey
|
29
|
+
})
|
30
|
+
|
31
|
+
new_kbs.save(function (err, savedKbs) {
|
32
|
+
if (err) {
|
33
|
+
console.error("save new kbs error: ", err);
|
34
|
+
return res.status(500).send({ success: false, error: err});
|
35
|
+
} else {
|
36
|
+
return res.status(200).send(savedKbs);
|
37
|
+
}
|
38
|
+
})
|
39
|
+
})
|
40
|
+
|
41
|
+
router.put('/', async (req, res) => {
|
42
|
+
// to be implemented
|
43
|
+
})
|
44
|
+
|
45
|
+
router.delete('/:kbs_id', async (req, res) => {
|
46
|
+
let kbs_id = req.params.kbs_id;
|
47
|
+
|
48
|
+
OpenaiKbs.findOneAndDelete( { _id: kbs_id }, (err, kbDeleted) => {
|
49
|
+
if (err) {
|
50
|
+
console.error("find one and delete kbs error: ", err);
|
51
|
+
return res.status(500).send({ success: false, error: err});
|
52
|
+
} else {
|
53
|
+
return res.status(200).send({ success: true, message: 'Knowledge Base deleted successfully', openai_kb: kbDeleted });
|
54
|
+
}
|
55
|
+
})
|
56
|
+
})
|
57
|
+
|
58
|
+
module.exports = router;
|
package/routes/request.js
CHANGED
@@ -6,6 +6,8 @@ var Schema = mongoose.Schema,
|
|
6
6
|
ObjectId = Schema.ObjectId;
|
7
7
|
var moment = require('moment');
|
8
8
|
var requestService = require('../services/requestService');
|
9
|
+
var emailService = require('../services/emailService');
|
10
|
+
|
9
11
|
var departmentService = require('../services/departmentService');
|
10
12
|
var winston = require('../config/winston');
|
11
13
|
const requestEvent = require('../event/requestEvent');
|
@@ -646,6 +648,62 @@ router.delete('/:requestid/notes/:noteid', function (req, res) {
|
|
646
648
|
|
647
649
|
|
648
650
|
|
651
|
+
//TODO add cc
|
652
|
+
router.post('/:requestid/email/send',
|
653
|
+
async (req, res) => {
|
654
|
+
|
655
|
+
|
656
|
+
let text = req.body.text;
|
657
|
+
winston.debug("text: " + text);
|
658
|
+
|
659
|
+
let request_id = req.params.requestid;
|
660
|
+
winston.debug("request_id: " + request_id);
|
661
|
+
|
662
|
+
let subject = req.body.subject;
|
663
|
+
winston.info("subject: " + subject);
|
664
|
+
|
665
|
+
winston.debug("req.project", req.project);
|
666
|
+
|
667
|
+
let replyto = req.body.replyto;
|
668
|
+
winston.debug("replyto: " + replyto);
|
669
|
+
|
670
|
+
|
671
|
+
let q = Request.findOne({request_id: request_id, id_project: req.projectid})
|
672
|
+
// .select("+snapshot.agents")
|
673
|
+
.populate('lead')
|
674
|
+
q.exec(function(err, request) {
|
675
|
+
if (err) {
|
676
|
+
winston.error("error getting request by id ", err);
|
677
|
+
return res.status(500).send({ success: false, msg: 'Error getting object.' });
|
678
|
+
}
|
679
|
+
if (!request) {
|
680
|
+
return res.status(404).send({ success: false, msg: 'Object not found.' });
|
681
|
+
}
|
682
|
+
|
683
|
+
|
684
|
+
|
685
|
+
winston.info("Sending an email with text : " + text + " to request_id " + request_id);
|
686
|
+
|
687
|
+
if (!request.lead.email) {
|
688
|
+
res.json({"no queued": true});
|
689
|
+
}
|
690
|
+
|
691
|
+
let newto = request.lead.email
|
692
|
+
winston.info("Sending an email newto " + newto);
|
693
|
+
|
694
|
+
//sendEmailDirect(to, text, project, request_id, subject, tokenQueryString, sourcePage, payload)
|
695
|
+
emailService.sendEmailDirect(newto, text, req.project, request_id, subject, undefined, undefined, undefined, replyto);
|
696
|
+
|
697
|
+
res.json({"queued": true});
|
698
|
+
|
699
|
+
|
700
|
+
});
|
701
|
+
|
702
|
+
|
703
|
+
|
704
|
+
|
705
|
+
});
|
706
|
+
|
649
707
|
|
650
708
|
|
651
709
|
|
@@ -1029,7 +1087,9 @@ router.get('/', function (req, res, next) {
|
|
1029
1087
|
winston.debug('REQUEST ROUTE - QUERY channel', query.channel);
|
1030
1088
|
}
|
1031
1089
|
|
1032
|
-
|
1090
|
+
if (req.query.priority) {
|
1091
|
+
query.priority = req.query.priority;
|
1092
|
+
}
|
1033
1093
|
|
1034
1094
|
|
1035
1095
|
var direction = -1; //-1 descending , 1 ascending
|
package/services/faqService.js
CHANGED
@@ -12,53 +12,53 @@ class FaqService {
|
|
12
12
|
var that = this;
|
13
13
|
return new Promise(function (resolve, reject) {
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
15
|
+
//winston.debug('FAQ-KB POST REQUEST BODY ', req.body);
|
16
|
+
var newFaq_kb = new Faq_kb({
|
17
|
+
name: name,
|
18
|
+
description: description,
|
19
|
+
url: url,
|
20
|
+
id_project: projectid,
|
21
|
+
webhook_url: webhook_url,
|
22
|
+
webhook_enabled: webhook_enabled,
|
23
|
+
type: type,
|
24
|
+
language: language,
|
25
|
+
public: false,
|
26
|
+
certified: false,
|
27
|
+
mainCategory: mainCategory,
|
28
|
+
intentsEngine: intentsEngine,
|
29
|
+
trashed: false,
|
30
|
+
createdBy: user_id,
|
31
|
+
updatedBy: user_id,
|
32
|
+
attributes: attributes
|
33
|
+
});
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
|
36
|
+
newFaq_kb.save(function (err, savedFaq_kb) {
|
37
|
+
if (err) {
|
38
|
+
winston.error('--- > ERROR ', err)
|
39
|
+
return reject('Error saving object.');
|
40
|
+
}
|
41
|
+
winston.debug('-> -> SAVED FAQFAQ KB ', savedFaq_kb.toObject())
|
42
|
+
|
43
|
+
botEvent.emit('faqbot.create', savedFaq_kb);
|
44
|
+
|
45
|
+
winston.debug('type ' + type)
|
46
|
+
|
47
|
+
if (type === "internal" || type === "tilebot") {
|
48
|
+
|
49
|
+
if (!template) {
|
50
|
+
template = "empty";
|
40
51
|
}
|
41
|
-
winston.debug('
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
if (type==="internal" || type==="tilebot") {
|
48
|
-
|
49
|
-
if (!template) {
|
50
|
-
template = "empty";
|
51
|
-
}
|
52
|
-
winston.debug('template '+ template);
|
53
|
-
that.createGreetingsAndOperationalsFaqs(savedFaq_kb._id, savedFaq_kb.createdBy, savedFaq_kb.id_project, template);
|
54
|
-
} else {
|
55
|
-
winston.debug('external bot: ', savedFaq_kb);
|
56
|
-
}
|
52
|
+
winston.debug('template ' + template);
|
53
|
+
that.createGreetingsAndOperationalsFaqs(savedFaq_kb._id, savedFaq_kb.createdBy, savedFaq_kb.id_project, template);
|
54
|
+
} else {
|
55
|
+
winston.debug('external bot: ', savedFaq_kb);
|
56
|
+
}
|
57
57
|
|
58
|
-
|
59
58
|
|
60
|
-
|
61
|
-
|
59
|
+
|
60
|
+
return resolve(savedFaq_kb);
|
61
|
+
});
|
62
62
|
});
|
63
63
|
}
|
64
64
|
|
@@ -69,98 +69,122 @@ class FaqService {
|
|
69
69
|
// aggiungi esempio tdAction con intent_id
|
70
70
|
|
71
71
|
// TODO non scatta i trigger sui rest hook. fare?
|
72
|
-
winston.debug('template: '+ template);
|
72
|
+
winston.debug('template: ' + template);
|
73
73
|
|
74
74
|
var faqsArray;
|
75
75
|
|
76
|
-
if (template==="example") {
|
76
|
+
if (template === "example") {
|
77
77
|
|
78
78
|
faqsArray = [
|
79
79
|
{ 'question': 'Hi', 'answer': 'Hi', 'topic': 'greetings' },
|
80
80
|
{ 'question': 'Hello', 'answer': 'Hello', 'topic': 'greetings' },
|
81
|
-
{ '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' },
|
82
|
-
{ 'question': '👨🏻🦰 I want an agent', 'answer': 'We are looking for an operator.. '+ActionsConstants.CHAT_ACTION_MESSAGE.AGENT, 'intent_display_name': 'agent_handoff', 'topic': 'internal' },
|
83
|
-
{ 'question': 'Close\nResolved', 'answer': ActionsConstants.CHAT_ACTION_MESSAGE.CLOSE, 'topic': 'internal' },
|
84
|
-
{ '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' },
|
81
|
+
{ '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' },
|
82
|
+
{ 'question': '👨🏻🦰 I want an agent', 'answer': 'We are looking for an operator.. ' + ActionsConstants.CHAT_ACTION_MESSAGE.AGENT, 'intent_display_name': 'agent_handoff', 'topic': 'internal' },
|
83
|
+
{ 'question': 'Close\nResolved', 'answer': ActionsConstants.CHAT_ACTION_MESSAGE.CLOSE, 'topic': 'internal' },
|
84
|
+
{ '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' },
|
85
85
|
{ '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
|
86
|
-
{ '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' },
|
87
|
-
{ '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' },
|
88
|
-
{ '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' },
|
89
|
-
{ 'question': 'Sample Video', 'answer': 'tdVideo:https://www.youtube.com/embed/EngW7tLk6R8\n* What can you do?\n* Back to start tdAction:start', 'topic': 'sample' },
|
90
|
-
{ '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' },
|
91
|
-
|
86
|
+
{ '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' },
|
87
|
+
{ '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' },
|
88
|
+
{ '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' },
|
89
|
+
{ 'question': 'Sample Video', 'answer': 'tdVideo:https://www.youtube.com/embed/EngW7tLk6R8\n* What can you do?\n* Back to start tdAction:start', 'topic': 'sample' },
|
90
|
+
{ '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' },
|
91
|
+
|
92
92
|
// { 'question': 'Sample Webhook', 'answer': 'tdWebhook:https://tiledesk-bot-webhook.tiledesk.repl.co', 'topic': 'sample' },
|
93
|
-
{ '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' },
|
94
|
-
{ 'question': 'Yes Action', 'answer': 'Great! Take a look here:\n* Tiledesk Pricing https://tiledesk.com/pricing-cloud/',
|
95
|
-
{ 'question': 'No Action', 'answer': 'All right! If you need anything, let us know.',
|
96
|
-
|
97
|
-
|
93
|
+
{ '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' },
|
94
|
+
{ 'question': 'Yes Action', 'answer': 'Great! Take a look here:\n* Tiledesk Pricing https://tiledesk.com/pricing-cloud/', 'intent_display_name': 'yes_action', 'topic': 'sample' },
|
95
|
+
{ 'question': 'No Action', 'answer': 'All right! If you need anything, let us know.', 'intent_display_name': 'no_action', 'topic': 'sample' },
|
96
|
+
|
97
|
+
|
98
98
|
// action button nn si può fare perche gli id cambiano
|
99
99
|
]
|
100
100
|
|
101
101
|
}
|
102
102
|
|
103
|
-
if (template==="blank") {
|
103
|
+
if (template === "blank") {
|
104
104
|
|
105
105
|
// faqsArray = [
|
106
106
|
// { 'question': '\\start', 'answer': 'Hello', 'intent_display_name': 'start', 'topic': 'internal' },
|
107
107
|
// { '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
|
108
108
|
// ]
|
109
|
-
faqsArray = [
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
109
|
+
faqsArray = [{
|
110
|
+
"webhook_enabled": false,
|
111
|
+
"enabled": true,
|
112
|
+
"actions": [{
|
113
|
+
"_tdActionType": "reply",
|
114
|
+
"text": "I didn't understand. Can you rephrase your question?",
|
115
|
+
"attributes": {
|
116
|
+
"commands": [{
|
117
|
+
"type": "wait",
|
118
|
+
"time": 500
|
119
|
+
},{
|
120
|
+
"type": "message",
|
121
|
+
"message": {
|
122
|
+
"type": "text",
|
123
|
+
"text": "I didn't understand. Can you rephrase your question?"
|
124
|
+
}
|
125
|
+
}]
|
126
|
+
}
|
127
|
+
}],
|
128
|
+
"intent_display_name": "defaultFallback",
|
129
|
+
"attributes": {
|
130
|
+
"position": {
|
131
|
+
"x": 714,
|
132
|
+
"y": 528
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}, {
|
136
|
+
"webhook_enabled": false,
|
137
|
+
"enabled": true,
|
138
|
+
"actions": [{
|
139
|
+
"_tdActionType": "intent",
|
140
|
+
"intentName": "#9d0b96b9-e036-4c2d-8504-1181b5c4be75"
|
141
|
+
}],
|
142
|
+
"question": "\\start",
|
143
|
+
"intent_display_name": "start",
|
144
|
+
"attributes": {
|
145
|
+
"position": {
|
146
|
+
"x": 172,
|
147
|
+
"y": 384
|
148
|
+
}
|
149
|
+
}
|
150
|
+
}, {
|
151
|
+
"webhook_enabled": false,
|
152
|
+
"enabled": true,
|
153
|
+
"actions": [{
|
154
|
+
"_tdActionType": "reply",
|
155
|
+
"attributes": {
|
156
|
+
"disableInputMessage": false,
|
157
|
+
"commands": [{
|
158
|
+
"type": "wait",
|
159
|
+
"time": 500
|
160
|
+
}, {
|
161
|
+
"type": "message",
|
162
|
+
"message": {
|
163
|
+
"type": "text",
|
164
|
+
"text": "Hi, how can I help you?"
|
165
|
+
}
|
166
|
+
}]
|
167
|
+
},
|
168
|
+
"text": "Hi, how can I help you?\r\n"
|
169
|
+
}],
|
170
|
+
"intent_display_name": "welcome",
|
171
|
+
"intent_id": "9d0b96b9-e036-4c2d-8504-1181b5c4be75",
|
172
|
+
"attributes": {
|
173
|
+
"position": {
|
174
|
+
"x": 714,
|
175
|
+
"y": 113
|
176
|
+
}
|
177
|
+
}
|
178
|
+
}]
|
155
179
|
|
156
180
|
}
|
157
181
|
|
158
182
|
|
159
|
-
if (template==="handoff") {
|
183
|
+
if (template === "handoff") {
|
160
184
|
|
161
|
-
faqsArray = [
|
162
|
-
{ 'question': '\\start', 'answer': 'Hello', 'intent_display_name': 'start', 'topic': 'internal' },
|
163
|
-
{ 'question': '👨🏻🦰 I want an agent', 'answer': 'We are looking for an operator.. '+ActionsConstants.CHAT_ACTION_MESSAGE.AGENT, 'intent_display_name': 'agent_handoff', 'topic': 'internal' },
|
185
|
+
faqsArray = [
|
186
|
+
{ 'question': '\\start', 'answer': 'Hello', 'intent_display_name': 'start', 'topic': 'internal' },
|
187
|
+
{ 'question': '👨🏻🦰 I want an agent', 'answer': 'We are looking for an operator.. ' + ActionsConstants.CHAT_ACTION_MESSAGE.AGENT, 'intent_display_name': 'agent_handoff', 'topic': 'internal' },
|
164
188
|
{ '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
|
165
189
|
]
|
166
190
|
|
@@ -169,18 +193,20 @@ class FaqService {
|
|
169
193
|
if (template === "empty") {
|
170
194
|
faqsArray = [];
|
171
195
|
}
|
172
|
-
|
173
|
-
|
196
|
+
|
197
|
+
|
174
198
|
faqsArray.forEach(faq => {
|
175
199
|
|
176
200
|
var newFaq = new Faq({
|
177
201
|
id_faq_kb: faq_kb_id,
|
202
|
+
intent_id: faq.intent_id,
|
178
203
|
question: faq.question,
|
179
204
|
answer: faq.answer,
|
180
205
|
actions: faq.actions,
|
181
206
|
reply: faq.reply,
|
182
207
|
intent_display_name: faq.intent_display_name,
|
183
208
|
language: "en",
|
209
|
+
attributes: faq.attributes,
|
184
210
|
id_project: projectid,
|
185
211
|
topic: faq.topic,
|
186
212
|
createdBy: created_by,
|
@@ -207,8 +233,8 @@ class FaqService {
|
|
207
233
|
winston.debug("(Service) GET ALL FAQ OF THE BOT ID (req.query): ", faq_kb_id);
|
208
234
|
|
209
235
|
return new Promise((resolve, reject) => {
|
210
|
-
|
211
|
-
Faq.find({ id_faq_kb: faq_kb_id}, (err, faqs) => {
|
236
|
+
|
237
|
+
Faq.find({ id_faq_kb: faq_kb_id }, (err, faqs) => {
|
212
238
|
if (err) {
|
213
239
|
reject(err);
|
214
240
|
}
|
package/test/faqRoute.js
CHANGED
@@ -53,7 +53,7 @@ describe('FaqKBRoute', () => {
|
|
53
53
|
chai.request(server)
|
54
54
|
.post('/' + savedProject._id + '/faq')
|
55
55
|
.auth(email, pwd)
|
56
|
-
.send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", attributes: { attr1: { one: "one", two: "two"}, attr2: {three: "three"}} })
|
56
|
+
.send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", attributes: { attr1: { one: "one", two: "two"}, attr2: {three: "three"}}, intent_id: 'custom-intent-id' }) // if intent_id is null the value will be the default one
|
57
57
|
.end((err, res) => {
|
58
58
|
//console.log("res", res);
|
59
59
|
console.log("res.body", res.body);
|
package/test/faqkbRoute.js
CHANGED
@@ -111,6 +111,48 @@ describe('FaqKBRoute', () => {
|
|
111
111
|
|
112
112
|
|
113
113
|
|
114
|
+
});
|
115
|
+
})
|
116
|
+
})
|
117
|
+
})
|
118
|
+
|
119
|
+
it('create with template blank', (done) => {
|
120
|
+
|
121
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
122
|
+
var pwd = "pwd";
|
123
|
+
|
124
|
+
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
125
|
+
projectService.create("test-faqkb-create", savedUser._id).then((savedProject) => {
|
126
|
+
|
127
|
+
chai.request(server)
|
128
|
+
.post('/' + savedProject._id + '/faq_kb')
|
129
|
+
.auth(email, pwd)
|
130
|
+
.send({ "name": "testbot", type: "internal", template: "blank" })
|
131
|
+
.end((err, res) => {
|
132
|
+
if (log) {
|
133
|
+
}
|
134
|
+
console.log("res.body", res.body);
|
135
|
+
res.should.have.status(200);
|
136
|
+
res.body.should.be.a('object');
|
137
|
+
expect(res.body.name).to.equal("testbot");
|
138
|
+
var id_faq_kb = res.body._id;
|
139
|
+
|
140
|
+
chai.request(server)
|
141
|
+
.get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
|
142
|
+
.auth(email, pwd)
|
143
|
+
.end((err, res) => {
|
144
|
+
if (log) {
|
145
|
+
}
|
146
|
+
console.log("faq_list: ", JSON.stringify(res.body, null, 2));
|
147
|
+
res.should.have.status(200);
|
148
|
+
res.body.should.be.an('array').that.is.not.empty;
|
149
|
+
|
150
|
+
done();
|
151
|
+
|
152
|
+
})
|
153
|
+
|
154
|
+
|
155
|
+
|
114
156
|
});
|
115
157
|
})
|
116
158
|
})
|
@@ -0,0 +1,75 @@
|
|
1
|
+
//During the test the env variable is set to test
|
2
|
+
process.env.NODE_ENV = 'test';
|
3
|
+
|
4
|
+
let log = false;
|
5
|
+
|
6
|
+
//Require the dev-dependencies
|
7
|
+
let chai = require('chai');
|
8
|
+
let chaiHttp = require('chai-http');
|
9
|
+
let server = require('../app');
|
10
|
+
let should = chai.should();
|
11
|
+
var fs = require('fs');
|
12
|
+
const path = require('path');
|
13
|
+
|
14
|
+
// chai.config.includeStack = true;
|
15
|
+
|
16
|
+
var expect = chai.expect;
|
17
|
+
var assert = chai.assert;
|
18
|
+
|
19
|
+
chai.use(chaiHttp);
|
20
|
+
|
21
|
+
describe('FaqKBRoute', () => {
|
22
|
+
|
23
|
+
describe('/create', () => {
|
24
|
+
|
25
|
+
it('home', (done) => {
|
26
|
+
|
27
|
+
})
|
28
|
+
|
29
|
+
it('create', (done) => {
|
30
|
+
|
31
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
32
|
+
var pwd = "pwd";
|
33
|
+
|
34
|
+
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
35
|
+
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
36
|
+
chai.request(server)
|
37
|
+
.post('/' + savedProject._id + '/faq_kb')
|
38
|
+
.auth(email, pwd)
|
39
|
+
.send({ "name": "testbot", type: "external", language: 'fr' })
|
40
|
+
.end((err, res) => {
|
41
|
+
if (log) {
|
42
|
+
console.log("res.body", res.body);
|
43
|
+
}
|
44
|
+
res.should.have.status(200);
|
45
|
+
res.body.should.be.a('object');
|
46
|
+
expect(res.body.name).to.equal("testbot");
|
47
|
+
expect(res.body.language).to.equal("fr");
|
48
|
+
|
49
|
+
chai.request(server)
|
50
|
+
.get('/' + savedProject._id + '/faq_kb/' + res.body._id)
|
51
|
+
.auth(email, pwd)
|
52
|
+
.end((err, res) => {
|
53
|
+
if (log) {
|
54
|
+
console.log("res.body", res.body);
|
55
|
+
}
|
56
|
+
res.should.have.status(200);
|
57
|
+
|
58
|
+
done();
|
59
|
+
});
|
60
|
+
});
|
61
|
+
|
62
|
+
|
63
|
+
});
|
64
|
+
});
|
65
|
+
|
66
|
+
}).timeout(20000);
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
});
|
72
|
+
|
73
|
+
});
|
74
|
+
|
75
|
+
|