@tiledesk/tiledesk-server 2.10.66 → 2.10.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 +9 -0
- package/app.js +4 -1
- package/models/chatbotTypes.js +6 -0
- package/models/faq_kb.js +7 -0
- package/models/webhook.js +46 -0
- package/package.json +2 -2
- package/pubmodules/trigger/start.js +2 -1
- package/routes/copilot.js +80 -0
- package/routes/faq_kb.js +3 -2
- package/routes/webhook.js +85 -0
- package/routes/webhooks.js +156 -0
- package/services/QuoteManager.js +0 -1
- package/services/faqService.js +170 -66
- package/services/webhookService.js +71 -0
- package/test/faqService.js +8 -5
- package/test/kbRoute.js +92 -113
- package/test/quoteManager.js +4 -2
- package/test/requestService.js +4 -3
- package/test/userRequestRoute.js +2 -1
- package/test/webhookRoute.js +376 -0
- package/test-int/bot.js +6 -5
- package/utils/httpUtil.js +51 -19
package/test/kbRoute.js
CHANGED
@@ -666,7 +666,7 @@ describe('KbRoute', () => {
|
|
666
666
|
|
667
667
|
if (err) { console.error("err: ", err); }
|
668
668
|
if (log) { console.log("res.body: ", res.body) }
|
669
|
-
|
669
|
+
|
670
670
|
res.should.have.status(200);
|
671
671
|
expect(res.body.length).to.equal(1)
|
672
672
|
expect(res.body[0].scrape_type).to.equal(3)
|
@@ -1562,71 +1562,73 @@ describe('KbRoute', () => {
|
|
1562
1562
|
/**
|
1563
1563
|
* Get all namespaces of a project.
|
1564
1564
|
* If there isn't namespaces for a project_id, the default namespace is created and returned.
|
1565
|
+
* WARNING: not working due to namspace creation limit (on trial plan)
|
1565
1566
|
*/
|
1566
|
-
it('create-and-get-namespaces', (done) => {
|
1567
|
-
|
1568
|
-
var email = "test-signup-" + Date.now() + "@email.com";
|
1569
|
-
var pwd = "pwd";
|
1567
|
+
// it('create-and-get-namespaces', (done) => {
|
1570
1568
|
|
1571
|
-
|
1572
|
-
|
1573
|
-
|
1574
|
-
// Get all namespaces. Create default namespace and return.
|
1575
|
-
chai.request(server)
|
1576
|
-
.get('/' + savedProject._id + '/kb/namespace/all')
|
1577
|
-
.auth(email, pwd)
|
1578
|
-
.end((err, res) => {
|
1569
|
+
// var email = "test-signup-" + Date.now() + "@email.com";
|
1570
|
+
// var pwd = "pwd";
|
1579
1571
|
|
1580
|
-
|
1581
|
-
|
1572
|
+
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1573
|
+
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
1582
1574
|
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1588
|
-
expect(res.body[0].name).to.equal("Default");
|
1575
|
+
// // Get all namespaces. Create default namespace and return.
|
1576
|
+
// chai.request(server)
|
1577
|
+
// .get('/' + savedProject._id + '/kb/namespace/all')
|
1578
|
+
// .auth(email, pwd)
|
1579
|
+
// .end((err, res) => {
|
1589
1580
|
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1581
|
+
// if (err) { console.error("err: ", err); }
|
1582
|
+
// if (log) { console.log("get all namespaces res.body: ", res.body); }
|
1583
|
+
// console.log("get all namespaces res.body: ", res.body);
|
1584
|
+
// res.should.have.status(200);
|
1585
|
+
// res.body.should.be.a('array');
|
1586
|
+
// expect(res.body.length).to.equal(1);
|
1587
|
+
// should.not.exist(res.body[0]._id);
|
1588
|
+
// expect(res.body[0].id).to.equal(savedProject._id.toString());
|
1589
|
+
// expect(res.body[0].name).to.equal("Default");
|
1596
1590
|
|
1597
|
-
|
1598
|
-
|
1591
|
+
// // Create another namespace
|
1592
|
+
// chai.request(server)
|
1593
|
+
// .post('/' + savedProject._id + '/kb/namespace')
|
1594
|
+
// .auth(email, pwd)
|
1595
|
+
// .send({ name: "MyCustomNamespace" })
|
1596
|
+
// .end((err, res) => {
|
1599
1597
|
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1598
|
+
// if (err) { console.error("err: ", err) }
|
1599
|
+
// if (log) { console.log("create new namespace res.body: ", res.body) }
|
1600
|
+
// console.log("create new namespace res.body: ", res.body)
|
1601
|
+
// res.should.have.status(200);
|
1602
|
+
// res.body.should.be.a('object');
|
1603
|
+
// should.not.exist(res.body._id)
|
1604
|
+
// should.exist(res.body.id)
|
1605
|
+
// expect(res.body.name).to.equal('MyCustomNamespace');
|
1605
1606
|
|
1606
|
-
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1607
|
+
// // Get again all namespace. A new default namespace should not be created.
|
1608
|
+
// chai.request(server)
|
1609
|
+
// .get('/' + savedProject._id + '/kb/namespace/all')
|
1610
|
+
// .auth(email, pwd)
|
1611
|
+
// .end((err, res) => {
|
1611
1612
|
|
1612
|
-
|
1613
|
-
|
1613
|
+
// if (err) { console.error("err: ", err); }
|
1614
|
+
// if (log) { console.log("get all namespaces res.body: ", res.body); }
|
1615
|
+
// console.log("get all namespaces res.body: ", res.body);
|
1614
1616
|
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1617
|
+
// res.should.have.status(200);
|
1618
|
+
// res.body.should.be.a('array');
|
1619
|
+
// expect(res.body.length).to.equal(2);
|
1620
|
+
// should.not.exist(res.body[0]._id);
|
1621
|
+
// should.not.exist(res.body[1]._id);
|
1622
|
+
// should.exist(res.body[0].id);
|
1623
|
+
// should.exist(res.body[1].id);
|
1622
1624
|
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
})
|
1625
|
+
// done();
|
1626
|
+
// })
|
1627
|
+
// })
|
1628
|
+
// })
|
1629
|
+
// });
|
1630
|
+
// });
|
1631
|
+
// })
|
1630
1632
|
|
1631
1633
|
it('create-namespaces-with-engine', (done) => {
|
1632
1634
|
|
@@ -1636,65 +1638,42 @@ describe('KbRoute', () => {
|
|
1636
1638
|
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1637
1639
|
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
1638
1640
|
|
1639
|
-
// Get all namespaces. Create default namespace and return.
|
1640
1641
|
chai.request(server)
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1677
|
-
// Get again all namespace. A new default namespace should not be created.
|
1678
|
-
chai.request(server)
|
1679
|
-
.get('/' + savedProject._id + '/kb/namespace/all')
|
1680
|
-
.auth(email, pwd)
|
1681
|
-
.end((err, res) => {
|
1682
|
-
|
1683
|
-
if (err) { console.error("err: ", err); }
|
1684
|
-
if (log) { console.log("get all namespaces res.body: ", res.body); }
|
1685
|
-
|
1686
|
-
res.should.have.status(200);
|
1687
|
-
res.body.should.be.a('array');
|
1688
|
-
expect(res.body.length).to.equal(2);
|
1689
|
-
should.not.exist(res.body[0]._id);
|
1690
|
-
should.not.exist(res.body[1]._id);
|
1691
|
-
should.exist(res.body[0].id);
|
1692
|
-
should.exist(res.body[1].id);
|
1693
|
-
|
1694
|
-
done();
|
1695
|
-
})
|
1696
|
-
})
|
1697
|
-
})
|
1642
|
+
.post('/' + savedProject._id + '/kb/namespace')
|
1643
|
+
.auth(email, pwd)
|
1644
|
+
.send({ name: "MyCustomNamespace" })
|
1645
|
+
.end((err, res) => {
|
1646
|
+
|
1647
|
+
if (err) { console.error("err: ", err) }
|
1648
|
+
if (log) { console.log("create new namespace res.body: ", res.body) }
|
1649
|
+
|
1650
|
+
res.should.have.status(200);
|
1651
|
+
res.body.should.be.a('object');
|
1652
|
+
should.not.exist(res.body._id)
|
1653
|
+
should.exist(res.body.id)
|
1654
|
+
expect(res.body.name).to.equal('MyCustomNamespace');
|
1655
|
+
should.exist(res.body.engine)
|
1656
|
+
expect(res.body.engine.name).to.equal('pinecone');
|
1657
|
+
expect(res.body.engine.type).to.equal('pod');
|
1658
|
+
|
1659
|
+
// Get again all namespace. A new default namespace should not be created.
|
1660
|
+
chai.request(server)
|
1661
|
+
.get('/' + savedProject._id + '/kb/namespace/all')
|
1662
|
+
.auth(email, pwd)
|
1663
|
+
.end((err, res) => {
|
1664
|
+
|
1665
|
+
if (err) { console.error("err: ", err); }
|
1666
|
+
if (log) { console.log("get all namespaces res.body: ", res.body); }
|
1667
|
+
|
1668
|
+
res.should.have.status(200);
|
1669
|
+
res.body.should.be.a('array');
|
1670
|
+
expect(res.body.length).to.equal(1);
|
1671
|
+
should.not.exist(res.body[0]._id);
|
1672
|
+
should.exist(res.body[0].id);
|
1673
|
+
|
1674
|
+
done();
|
1675
|
+
})
|
1676
|
+
})
|
1698
1677
|
});
|
1699
1678
|
});
|
1700
1679
|
})
|
package/test/quoteManager.js
CHANGED
@@ -30,8 +30,9 @@ let log = false;
|
|
30
30
|
// CONNECT REDIS - CHECK IT
|
31
31
|
const { TdCache } = require('../utils/TdCache');
|
32
32
|
let tdCache = new TdCache({
|
33
|
-
host: '127.0.0.1',
|
34
|
-
port: '6379'
|
33
|
+
host: process.env.CACHE_REDIS_HOST || '127.0.0.1',
|
34
|
+
port: process.env.CACHE_REDIS_PORT || '6379',
|
35
|
+
password: process.env.CACHE_REDIS_PASSWORD || undefined
|
35
36
|
});
|
36
37
|
|
37
38
|
tdCache.connect();
|
@@ -191,6 +192,7 @@ describe('QuoteManager', function () {
|
|
191
192
|
}).timeout(10000)
|
192
193
|
|
193
194
|
it('incrementRequestsCount', async function () {
|
195
|
+
|
194
196
|
let mockProject = projectMock.mockProjectBasicPlan;
|
195
197
|
let mockRequest = requestMock.requestMock;
|
196
198
|
|
package/test/requestService.js
CHANGED
@@ -42,9 +42,10 @@ const projectMock = require('./mock/projectMock');
|
|
42
42
|
// CONNECT REDIS - CHECK IT
|
43
43
|
const { TdCache } = require('../utils/TdCache');
|
44
44
|
let tdCache = new TdCache({
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
host: process.env.CACHE_REDIS_HOST || '127.0.0.1',
|
46
|
+
port: process.env.CACHE_REDIS_PORT || '6379',
|
47
|
+
password: process.env.CACHE_REDIS_PASSWORD || undefined
|
48
|
+
});
|
48
49
|
|
49
50
|
tdCache.connect();
|
50
51
|
|
package/test/userRequestRoute.js
CHANGED
@@ -33,6 +33,7 @@ var Bot = require("../models/faq_kb");
|
|
33
33
|
|
34
34
|
var jwt = require('jsonwebtoken');
|
35
35
|
const uuidv4 = require('uuid/v4');
|
36
|
+
const chatbotTypes = require('../models/chatbotTypes');
|
36
37
|
|
37
38
|
|
38
39
|
describe('UserService()', function () {
|
@@ -48,7 +49,7 @@ describe('UserService()', function () {
|
|
48
49
|
projectService.createAndReturnProjectAndProjectUser("createWithId", savedUser.id).then(function (savedProjectAndPU) {
|
49
50
|
var savedProject = savedProjectAndPU.project;
|
50
51
|
|
51
|
-
faqService.create("testbot", null, savedProject._id, savedUser._id, "tilebot", null, null, null, "en", "blank").then(async function (savedFaq_kb) {
|
52
|
+
faqService.create("testbot", null, savedProject._id, savedUser._id, "tilebot", chatbotTypes.CHATBOT, null, null, null, "en", "blank").then(async function (savedFaq_kb) {
|
52
53
|
|
53
54
|
var signOptions = {
|
54
55
|
issuer: 'https://tiledesk.com',
|