@tiledesk/tiledesk-server 2.2.14 → 2.2.15
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 +11 -0
- package/app.js +2 -1
- package/package.json +1 -1
- package/public/samples/bot/external/searcher/parse +10 -0
- package/routes/auth.js +5 -1
- package/routes/faq.js +49 -26
- package/routes/faq_kb.js +102 -0
- package/services/faqBotHandler.js +142 -16
- package/services/faqBotSupport copy.js +453 -0
- package/services/faqService.js +1 -0
- package/services/messageService.js +1 -1
- package/test/faqRoute.js +112 -4
- package/test/faqkbRoute.js +57 -1
- package/test-int/bot copy.js +2074 -0
- package/test-int/bot.js +95 -1
- package/utils/httpUtil.js +42 -0
package/test-int/bot.js
CHANGED
@@ -372,6 +372,7 @@ describe('bot', () => {
|
|
372
372
|
|
373
373
|
|
374
374
|
|
375
|
+
|
375
376
|
// mocha test-int/bot.js --grep 'createSimpleFulltext'
|
376
377
|
it('createSimpleFulltext', (done) => {
|
377
378
|
|
@@ -383,7 +384,100 @@ describe('bot', () => {
|
|
383
384
|
userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
|
384
385
|
projectService.create("test-bot", savedUser._id).then(function(savedProject) {
|
385
386
|
// create(name, url, projectid, user_id, type)
|
386
|
-
faqService.create("testbot",
|
387
|
+
faqService.create("testbot", undefined, savedProject._id, savedUser._id, "internal").then(function(savedBot) {
|
388
|
+
|
389
|
+
var newFaq = new Faq({
|
390
|
+
id_faq_kb: savedBot._id,
|
391
|
+
question: 'question number one',
|
392
|
+
answer: 'answer',
|
393
|
+
id_project: savedProject._id,
|
394
|
+
createdBy: savedUser._id,
|
395
|
+
updatedBy: savedUser._id
|
396
|
+
});
|
397
|
+
|
398
|
+
newFaq.save(function (err, savedFaq) {
|
399
|
+
|
400
|
+
|
401
|
+
Department.findOneAndUpdate({id_project: savedProject._id, default:true}, {id_bot:savedBot._id}, function (err, updatedDepartment) {
|
402
|
+
|
403
|
+
chai.request(server)
|
404
|
+
.post('/'+ savedProject._id + '/subscriptions')
|
405
|
+
.auth(email, pwd)
|
406
|
+
.set('content-type', 'application/json')
|
407
|
+
.send({"event":"message.create", "target":"http://localhost:3010/"})
|
408
|
+
.end((err, res) => {
|
409
|
+
console.log("res.body", JSON.stringify(res.body));
|
410
|
+
// console.dir("res.body 1", res.body);
|
411
|
+
console.log("res.headers", res.headers);
|
412
|
+
res.should.have.status(200);
|
413
|
+
res.body.should.be.a('object');
|
414
|
+
expect(res.body.event).to.equal("message.create");
|
415
|
+
var secret = res.body.secret;
|
416
|
+
expect(secret).to.not.equal(null);
|
417
|
+
expect(res.headers["x-hook-secret"]).to.equal(secret);
|
418
|
+
|
419
|
+
|
420
|
+
let messageReceived = 0;
|
421
|
+
var serverClient = express();
|
422
|
+
serverClient.use(bodyParser.json());
|
423
|
+
serverClient.post('/', function (req, res) {
|
424
|
+
console.log('serverClient req', JSON.stringify(req.body));
|
425
|
+
console.log("serverClient.headers", JSON.stringify(req.headers));
|
426
|
+
messageReceived = messageReceived+1;
|
427
|
+
expect(req.body.hook.event).to.equal("message.create");
|
428
|
+
expect(req.body.payload.request.request_id).to.equal("request_id-subscription-message-sending");
|
429
|
+
expect(req.body.payload.request.department).to.not.equal(null);
|
430
|
+
expect(req.body.payload.request.department.bot).to.not.equal(null);
|
431
|
+
expect(req.body.payload.request.department.bot.name).to.equal("testbot");
|
432
|
+
|
433
|
+
expect(req.headers["x-hook-secret"]).to.equal(secret);
|
434
|
+
res.send('POST request to the homepage');
|
435
|
+
expect(req.body.payload.text).to.equal("answer");
|
436
|
+
// console.log("savedFaq",savedFaq);
|
437
|
+
expect(req.body.payload.sender).to.equal("bot_"+savedBot.id);
|
438
|
+
expect(req.body.payload.recipient).to.equal("request_id-subscription-message-sending");
|
439
|
+
// expect(req.body.payload.attributes._answer._id.toString()).to.equal(savedFaq._id.toString());
|
440
|
+
expect(req.body.payload.attributes._answerid.toString()).to.equal(savedFaq._id.toString());
|
441
|
+
done();
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
|
446
|
+
});
|
447
|
+
var listener = serverClient.listen(3010, '0.0.0.0', function(){ console.log('Node js Express started', listener.address());});
|
448
|
+
|
449
|
+
|
450
|
+
leadService.createIfNotExists("leadfullname-subscription-message-sending", "andrea.leo@-subscription-message-sending.it", savedProject._id).then(function(createdLead) {
|
451
|
+
requestService.createWithId("request_id-subscription-message-sending", createdLead._id, savedProject._id, "first_text").then(function(savedRequest) {
|
452
|
+
messageService.create(savedUser._id, "test sender", savedRequest.request_id, "question",
|
453
|
+
savedProject._id, savedUser._id).then(function(savedMessage){
|
454
|
+
expect(savedMessage.text).to.equal("question");
|
455
|
+
// expect(savedMessage.sender).to.equal("question");
|
456
|
+
});
|
457
|
+
});
|
458
|
+
});
|
459
|
+
});
|
460
|
+
});
|
461
|
+
});
|
462
|
+
});
|
463
|
+
|
464
|
+
});
|
465
|
+
});
|
466
|
+
}).timeout(20000);
|
467
|
+
|
468
|
+
|
469
|
+
// mocha test-int/bot.js --grep 'createSimpleExternalSearcherBot'
|
470
|
+
it('createSimpleExternalSearcherBot', (done) => {
|
471
|
+
|
472
|
+
var email = "test-bot-" + Date.now() + "@email.com";
|
473
|
+
var pwd = "pwd";
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
|
478
|
+
projectService.create("test-bot", savedUser._id).then(function(savedProject) {
|
479
|
+
// create(name, url, projectid, user_id, type)
|
480
|
+
faqService.create("testbot", "http://localhost:3001/samples/bot/external/searcher", savedProject._id, savedUser._id, "internal").then(function(savedBot) {
|
387
481
|
|
388
482
|
var newFaq = new Faq({
|
389
483
|
id_faq_kb: savedBot._id,
|
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
'use strict';
|
3
|
+
|
4
|
+
var request = require('retry-request', {
|
5
|
+
request: require('request')
|
6
|
+
});
|
7
|
+
|
8
|
+
|
9
|
+
class HttpUtil {
|
10
|
+
|
11
|
+
call(url, headers, json, method) {
|
12
|
+
return new Promise(function (resolve, reject) {
|
13
|
+
request({
|
14
|
+
url: url,
|
15
|
+
headers: headers,
|
16
|
+
json: json,
|
17
|
+
method: method
|
18
|
+
}, function(err, result, json){
|
19
|
+
//console.log("SENT notify for bot with url " + url + " with err " + err);
|
20
|
+
if (err) {
|
21
|
+
//console.log("Error sending notify for bot with url " + url + " with err " + err);
|
22
|
+
return reject(err);
|
23
|
+
}
|
24
|
+
return resolve(json);
|
25
|
+
});
|
26
|
+
});
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
|
31
|
+
var httpUtil = new HttpUtil();
|
32
|
+
|
33
|
+
/*
|
34
|
+
async function ciao() {
|
35
|
+
var res = await httpUtil.call("https://webhook.site/bd710929-9b43-4065-88db-78ee17f84aec", undefined, {c:1}, "POST")
|
36
|
+
console.log("res", res);
|
37
|
+
|
38
|
+
}
|
39
|
+
ciao();
|
40
|
+
*/
|
41
|
+
|
42
|
+
module.exports = httpUtil;
|