@tiledesk/tiledesk-server 2.3.115 → 2.3.117
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +5 -5
- package/routes/faq_kb.js +155 -107
- package/test/example-json-rules.txt +82 -0
- package/test/example-json.txt +1 -1
- package/test/faqkbRoute.js +56 -10
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@tiledesk/tiledesk-server",
|
3
3
|
"description": "The Tiledesk server module",
|
4
|
-
"version": "2.3.
|
4
|
+
"version": "2.3.117",
|
5
5
|
"scripts": {
|
6
6
|
"start": "node ./bin/www",
|
7
7
|
"pretest": "mongodb-runner start",
|
@@ -39,13 +39,13 @@
|
|
39
39
|
"@tiledesk/tiledesk-apps": "^1.0.16",
|
40
40
|
"@tiledesk/tiledesk-chat21-app": "^1.1.7",
|
41
41
|
"@tiledesk/tiledesk-chatbot-util": "^0.8.33",
|
42
|
-
"@tiledesk/tiledesk-dialogflow-connector": "^1.8.
|
42
|
+
"@tiledesk/tiledesk-dialogflow-connector": "^1.8.4",
|
43
43
|
"@tiledesk/tiledesk-json-rules-engine": "^4.0.3",
|
44
44
|
"@tiledesk/tiledesk-kaleyra-proxy": "^0.1.7",
|
45
|
-
"@tiledesk/tiledesk-
|
45
|
+
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.42",
|
46
|
+
"@tiledesk/tiledesk-messenger-connector": "0.1.2",
|
46
47
|
"@tiledesk/tiledesk-rasa-connector": "^1.0.10",
|
47
|
-
"@tiledesk/tiledesk-tybot-connector": "^0.1.
|
48
|
-
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.41",
|
48
|
+
"@tiledesk/tiledesk-tybot-connector": "^0.1.70",
|
49
49
|
"amqplib": "^0.5.5",
|
50
50
|
"app-root-path": "^3.0.0",
|
51
51
|
"bcrypt-nodejs": "0.0.3",
|
package/routes/faq_kb.js
CHANGED
@@ -529,7 +529,7 @@ router.post('/fork/:id_faq_kb', async (req, res) => {
|
|
529
529
|
router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), async (req, res) => {
|
530
530
|
|
531
531
|
let id_faq_kb = req.params.id_faq_kb;
|
532
|
-
winston.debug('import on id_faq_kb: '
|
532
|
+
winston.debug('import on id_faq_kb: ' + id_faq_kb);
|
533
533
|
|
534
534
|
let json_string;
|
535
535
|
let json;
|
@@ -603,66 +603,94 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), async (req, r
|
|
603
603
|
} else {
|
604
604
|
|
605
605
|
if (req.query.create && req.query.create == 'true') {
|
606
|
+
|
607
|
+
|
606
608
|
faqService.create(json.name, undefined, req.projectid, req.user.id, "tilebot", json.description, json.webhook_url, json.webhook_enabled, json.language, undefined, undefined, undefined, json.attributes).then( async (savedFaq_kb) => {
|
607
609
|
winston.debug("saved (and imported) faq kb: ", savedFaq_kb);
|
608
|
-
|
609
|
-
|
610
|
-
|
610
|
+
|
611
|
+
// edit attributes.rules
|
612
|
+
let attributes = json.attributes;
|
613
|
+
if (attributes &&
|
614
|
+
attributes.rules &&
|
615
|
+
attributes.rules.length > 0) {
|
611
616
|
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
actions: intent.actions
|
626
|
-
}
|
627
|
-
|
628
|
-
// TO DELETE: no used when req.query.create = 'true'
|
629
|
-
if (req.query.overwrite == "true") {
|
630
|
-
Faq.findOneAndUpdate({ id_faq_kb: id_faq_kb, intent_display_name: intent.intent_display_name }, new_faq, { new: true, upsert: true, rawResult: true }, (err, savingResult) => {
|
617
|
+
await attributes.rules.forEach((rule) => {
|
618
|
+
if (rule.do &&
|
619
|
+
rule.do[0] &&
|
620
|
+
rule.do[0].message &&
|
621
|
+
rule.do[0].message.participants &&
|
622
|
+
rule.do[0].message.participants[0]) {
|
623
|
+
rule.do[0].message.participants[0] = "bot_" + savedFaq_kb._id
|
624
|
+
winston.debug("attributes rule new participant: ", rule.do[0].message.participants[0])
|
625
|
+
}
|
626
|
+
})
|
627
|
+
}
|
628
|
+
let chatbot_edited = { attributes: attributes };
|
629
|
+
Faq_kb.findByIdAndUpdate(savedFaq_kb._id, chatbot_edited, { new: true }, (err, savedEditedFaq_kb) => {
|
631
630
|
if (err) {
|
632
|
-
winston.error("
|
633
|
-
} else {
|
634
|
-
|
635
|
-
if (savingResult.lastErrorObject.updatedExisting == true) {
|
636
|
-
winston.debug("updated existing intent")
|
637
|
-
faqBotEvent.emit('faq.update', savingResult.value);
|
638
|
-
} else {
|
639
|
-
winston.debug("new intent created")
|
640
|
-
faqBotEvent.emit('faq.create', savingResult.value);
|
641
|
-
}
|
642
|
-
|
631
|
+
winston.error("error during saving edited faq_kb: ", err)
|
643
632
|
}
|
633
|
+
botEvent.emit('faqbot.create', savedFaq_kb);
|
644
634
|
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
635
|
+
if (json.intents) {
|
636
|
+
|
637
|
+
json.intents.forEach((intent) => {
|
638
|
+
|
639
|
+
let new_faq = {
|
640
|
+
id_faq_kb: savedFaq_kb._id,
|
641
|
+
id_project: req.projectid,
|
642
|
+
createdBy: req.user.id,
|
643
|
+
intent_display_name: intent.intent_display_name,
|
644
|
+
intent_id: intent.intent_id,
|
645
|
+
question: intent.question,
|
646
|
+
answer: intent.answer,
|
647
|
+
reply: intent.reply,
|
648
|
+
form: intent.form,
|
649
|
+
enabled: intent.enabled,
|
650
|
+
webhook_enabled: intent.webhook_enabled,
|
651
|
+
language: intent.language,
|
652
|
+
actions: intent.actions
|
653
|
+
}
|
654
|
+
|
655
|
+
// TO DELETE: no used when req.query.create = 'true'
|
656
|
+
if (req.query.overwrite == "true") {
|
657
|
+
Faq.findOneAndUpdate({ id_faq_kb: id_faq_kb, intent_display_name: intent.intent_display_name }, new_faq, { new: true, upsert: true, rawResult: true }, (err, savingResult) => {
|
658
|
+
if (err) {
|
659
|
+
winston.error("findOneAndUpdate (upsert) FAQ ERROR ", err);
|
660
|
+
} else {
|
661
|
+
|
662
|
+
if (savingResult.lastErrorObject.updatedExisting == true) {
|
663
|
+
winston.debug("updated existing intent")
|
664
|
+
faqBotEvent.emit('faq.update', savingResult.value);
|
665
|
+
} else {
|
666
|
+
winston.debug("new intent created")
|
667
|
+
faqBotEvent.emit('faq.create', savingResult.value);
|
668
|
+
}
|
669
|
+
|
670
|
+
}
|
671
|
+
|
672
|
+
})
|
673
|
+
// don't overwrite duplicated intents
|
674
|
+
} else {
|
675
|
+
Faq.create(new_faq, (err, savedFaq) => {
|
676
|
+
if (err) {
|
677
|
+
winston.debug("create new FAQ ERROR ", err);
|
678
|
+
if (err.code == 11000) {
|
679
|
+
winston.error("Duplicate intent_display_name.");
|
680
|
+
winston.debug("Skip duplicated intent_display_name");
|
681
|
+
} else {
|
682
|
+
winston.debug("new intent created")
|
683
|
+
faqBotEvent.emit('faq.create', savedFaq);
|
684
|
+
}
|
685
|
+
}
|
686
|
+
})
|
687
|
+
}
|
688
|
+
|
689
|
+
})
|
659
690
|
}
|
691
|
+
faqBotEvent.emit('faq_train.importedall', savedEditedFaq_kb._id);
|
692
|
+
return res.status(200).send(savedEditedFaq_kb);
|
660
693
|
})
|
661
|
-
}
|
662
|
-
|
663
|
-
})
|
664
|
-
faqBotEvent.emit('faq_train.importedall', savedFaq_kb._id);
|
665
|
-
return res.status(200).send(savedFaq_kb);
|
666
694
|
|
667
695
|
}).catch((err) => {
|
668
696
|
winston.error("error saving faq_kb: ", err);
|
@@ -671,7 +699,7 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), async (req, r
|
|
671
699
|
|
672
700
|
} else {
|
673
701
|
|
674
|
-
Faq_kb.findById(id_faq_kb, (err, faq_kb) => {
|
702
|
+
Faq_kb.findById(id_faq_kb, async (err, faq_kb) => {
|
675
703
|
if (err) {
|
676
704
|
winston.error("GET FAQ-KB ERROR", err);
|
677
705
|
return res.status(500).send({ success: false, msg: "Error getting bot." });
|
@@ -698,74 +726,93 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), async (req, r
|
|
698
726
|
if (json.description) {
|
699
727
|
faq_kb.description = json.description;
|
700
728
|
}
|
729
|
+
|
701
730
|
if (json.attributes) {
|
702
|
-
|
731
|
+
let attributes = json.attributes;
|
732
|
+
if (attributes.rules &&
|
733
|
+
attributes.rules.length > 0) {
|
734
|
+
await attributes.rules.forEach((rule) => {
|
735
|
+
if (rule.do &&
|
736
|
+
rule.do[0] &&
|
737
|
+
rule.do[0].message &&
|
738
|
+
rule.do[0].message.participants &&
|
739
|
+
rule.do[0].message.participants[0]) {
|
740
|
+
rule.do[0].message.participants[0] = "bot_" + faq_kb._id
|
741
|
+
winston.debug("attributes rule new participant: " + rule.do[0].message.participants[0])
|
742
|
+
}
|
743
|
+
})
|
744
|
+
faq_kb.attributes = json.attributes;
|
745
|
+
}
|
703
746
|
}
|
704
747
|
// if (json.intentsEngine) {
|
705
748
|
// faq_kb.intentsEngine = json.intentsEngine;
|
706
749
|
// }
|
707
750
|
|
751
|
+
|
708
752
|
Faq_kb.findByIdAndUpdate(id_faq_kb, faq_kb, { new: true }, async (err, updatedFaq_kb) => {
|
709
753
|
if (err) {
|
710
754
|
return res.status(500).send({ success: false, msg: "Error updating bot." });
|
711
755
|
}
|
712
756
|
|
713
757
|
botEvent.emit('faqbot.update', updatedFaq_kb);
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
if (savingResult.lastErrorObject.updatedExisting == true) {
|
741
|
-
winston.info("updated existing intent")
|
742
|
-
faqBotEvent.emit('faq.update', savingResult.value);
|
758
|
+
|
759
|
+
if (json.intents) {
|
760
|
+
await json.intents.forEach((intent) => {
|
761
|
+
|
762
|
+
let new_faq = {
|
763
|
+
id_faq_kb: updatedFaq_kb._id,
|
764
|
+
id_project: req.projectid,
|
765
|
+
createdBy: req.user.id,
|
766
|
+
intent_display_name: intent.intent_display_name,
|
767
|
+
intent_id: intent.intent_id,
|
768
|
+
question: intent.question,
|
769
|
+
answer: intent.answer,
|
770
|
+
reply: intent.reply,
|
771
|
+
form: intent.form,
|
772
|
+
enabled: intent.enabled,
|
773
|
+
webhook_enabled: intent.webhook_enabled,
|
774
|
+
language: intent.language,
|
775
|
+
actions: intent.actions
|
776
|
+
}
|
777
|
+
|
778
|
+
// overwrite duplicated intents
|
779
|
+
if (req.query.overwrite == "true") {
|
780
|
+
Faq.findOneAndUpdate({ id_faq_kb: id_faq_kb, intent_display_name: intent.intent_display_name }, new_faq, { new: true, upsert: true, rawResult: true }, (err, savingResult) => {
|
781
|
+
if (err) {
|
782
|
+
winston.error("findOneAndUpdate (upsert) FAQ ERROR ", err);
|
743
783
|
} else {
|
744
|
-
|
745
|
-
|
784
|
+
|
785
|
+
if (savingResult.lastErrorObject.updatedExisting == true) {
|
786
|
+
winston.info("updated existing intent")
|
787
|
+
faqBotEvent.emit('faq.update', savingResult.value);
|
788
|
+
} else {
|
789
|
+
winston.info("new intent created")
|
790
|
+
faqBotEvent.emit('faq.create', savingResult.value);
|
791
|
+
}
|
792
|
+
|
746
793
|
}
|
747
|
-
|
748
|
-
}
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
faqBotEvent.emit('faq.create', savedFaq);
|
794
|
+
|
795
|
+
})
|
796
|
+
|
797
|
+
// don't overwrite duplicated intents
|
798
|
+
} else {
|
799
|
+
Faq.create(new_faq, (err, savedFaq) => {
|
800
|
+
if (err) {
|
801
|
+
winston.debug("create new FAQ ERROR ", err);
|
802
|
+
if (err.code == 11000) {
|
803
|
+
winston.error("Duplicate intent_display_name.");
|
804
|
+
winston.info("Skip duplicated intent_display_name");
|
805
|
+
} else {
|
806
|
+
winston.info("new intent created")
|
807
|
+
faqBotEvent.emit('faq.create', savedFaq);
|
808
|
+
}
|
763
809
|
}
|
764
|
-
}
|
765
|
-
}
|
766
|
-
|
767
|
-
|
768
|
-
|
810
|
+
})
|
811
|
+
}
|
812
|
+
|
813
|
+
})
|
814
|
+
|
815
|
+
}
|
769
816
|
faqBotEvent.emit('faq_train.importedall', id_faq_kb);
|
770
817
|
return res.send(updatedFaq_kb);
|
771
818
|
|
@@ -802,6 +849,7 @@ router.get('/exportjson/:id_faq_kb', (req, res) => {
|
|
802
849
|
language: faq_kb.language,
|
803
850
|
name: faq_kb.name,
|
804
851
|
type: faq_kb.type,
|
852
|
+
description: faq_kb.description,
|
805
853
|
attributes: faq_kb.attributes,
|
806
854
|
intents: intents
|
807
855
|
}
|
@@ -0,0 +1,82 @@
|
|
1
|
+
{
|
2
|
+
"webhook_enabled" : false,
|
3
|
+
"type" : "tilebot",
|
4
|
+
"secret" : "0c9021c8-3b62-47ce-98f2-cbc7b47639d1",
|
5
|
+
"language" : "en",
|
6
|
+
"public" : true,
|
7
|
+
"certified" : false,
|
8
|
+
"intentsEngine" : "none",
|
9
|
+
"tags" : [
|
10
|
+
"quiz",
|
11
|
+
"onboarding",
|
12
|
+
"whatsapp",
|
13
|
+
"chatbot",
|
14
|
+
"english",
|
15
|
+
"buttons"
|
16
|
+
],
|
17
|
+
"score" : 0,
|
18
|
+
"name" : "examplebot",
|
19
|
+
"id_project" : "64218dfecdb804001380b9ba",
|
20
|
+
"trashed" : false,
|
21
|
+
"createdBy" : "63a05d755f117f0013541383",
|
22
|
+
"attributes" : {
|
23
|
+
"variables" : {
|
24
|
+
"total" : "total",
|
25
|
+
"score" : "score",
|
26
|
+
"userFullname" : "userFullname"
|
27
|
+
},
|
28
|
+
"rules" : [
|
29
|
+
{
|
30
|
+
"uid" : "6f7f1206-0433-4ea5-a1f5-d688334fe147",
|
31
|
+
"name" : "go2",
|
32
|
+
"description" : "",
|
33
|
+
"when" : {
|
34
|
+
"regexOption" : "any",
|
35
|
+
"text" : "",
|
36
|
+
"urlMatches" : "^.*$",
|
37
|
+
"triggerEvery" : -1
|
38
|
+
},
|
39
|
+
"do" : [
|
40
|
+
{
|
41
|
+
"message" : {
|
42
|
+
"text" : "/proactive2",
|
43
|
+
"participants" : [
|
44
|
+
"bot_64232b3f2e14140013a9a623"
|
45
|
+
],
|
46
|
+
"attributes" : {
|
47
|
+
"subtype" : "info"
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
]
|
52
|
+
},
|
53
|
+
{
|
54
|
+
"uid" : "4aa55b98-8450-4f59-b82e-06b794ed3edf",
|
55
|
+
"name" : "go",
|
56
|
+
"description" : "",
|
57
|
+
"when" : {
|
58
|
+
"regexOption" : "ends",
|
59
|
+
"text" : "ppp",
|
60
|
+
"urlMatches" : "^.*(ppp)$",
|
61
|
+
"triggerEvery" : -1
|
62
|
+
},
|
63
|
+
"do" : [
|
64
|
+
{
|
65
|
+
"message" : {
|
66
|
+
"text" : "/proactive",
|
67
|
+
"participants" : [
|
68
|
+
"bot_64232b3f2e14140013a9a623"
|
69
|
+
],
|
70
|
+
"attributes" : {
|
71
|
+
"subtype" : "info"
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
]
|
76
|
+
}
|
77
|
+
]
|
78
|
+
},
|
79
|
+
"__v" : 0,
|
80
|
+
"url" : "http://localhost:3000/modules/tilebot/ext/6425b5c495fcdb0012beb9b9",
|
81
|
+
"description" : "A simple Javascript test submitted with a Chatbot 🤓\n\nYou can use this test to create and submit a simple test to your audience. This test makes wide use of \"attributes\" and \"conditions\" (aka the \"flow\"). We also created a rule to proactively engage your visitors to open and complete the test. We also used \"forms\" to ask your visitor's data (please mind that privacy concerns are left to you).\n\nIt also works on Whatsapp!\n\nFeel free to import and modify this test as you prefer.\n\nLet us know if you have some questions about this template writing a message to andrea@tiledesk.com"
|
82
|
+
}
|
package/test/example-json.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"webhook_enabled":false,"language":"en","name":"examplebot","intentsEngine":"tiledesk-ai","intents":[{"webhook_enabled":false,"enabled":true,"question":"\\start","answer":"Hi","intent_display_name":"start","language":"en"},{"webhook_enabled":false,"enabled":true,"question":"question1","answer":"question1","intent_display_name":"question1","language":"en"},{"webhook_enabled":false,"enabled":true,"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","language":"en"}]}
|
1
|
+
{"webhook_enabled":false,"language":"en","name":"examplebot","intentsEngine":"tiledesk-ai","attributes" : {"variables" : {"total" : "total","score" : "score","userFullname" : "userFullname"},"rules" : [{"uid" : "6f7f1206-0433-4ea5-a1f5-d688334fe147","name" : "go2","description" : "","when" : {"regexOption" : "any","text" : "","urlMatches" : "^.*$","triggerEvery" : -1},"do" : [ {"message" : {"text" : "/proactive2","participants" : [ "bot_64232b3f2e14140013a9a623"],"attributes" : {"subtype" : "info"}}}]}, {"uid" : "4aa55b98-8450-4f59-b82e-06b794ed3edf","name" : "go","description" : "","when" : {"regexOption" : "ends","text" : "ppp","urlMatches" : "^.*(ppp)$","triggerEvery" : -1},"do":[{"message" : {"text" : "/proactive","participants" : ["bot_64232b3f2e14140013a9a623"],"attributes" : {"subtype" : "info"}}}]}]},"intents":[{"webhook_enabled":false,"enabled":true,"question":"\\start","answer":"Hi","intent_display_name":"start","language":"en"},{"webhook_enabled":false,"enabled":true,"question":"question1","answer":"question1","intent_display_name":"question1","language":"en"},{"webhook_enabled":false,"enabled":true,"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","language":"en"}]}
|
package/test/faqkbRoute.js
CHANGED
@@ -58,7 +58,9 @@ describe('FaqKBRoute', () => {
|
|
58
58
|
.get('/' + savedProject._id + '/faq_kb/' + res.body._id)
|
59
59
|
.auth(email, pwd)
|
60
60
|
.end((err, res) => {
|
61
|
-
|
61
|
+
if (log) {
|
62
|
+
console.log("res.body", res.body);
|
63
|
+
}
|
62
64
|
res.should.have.status(200);
|
63
65
|
|
64
66
|
done();
|
@@ -189,8 +191,9 @@ describe('FaqKBRoute', () => {
|
|
189
191
|
projectService.create("current-project", user1._id).then(function (currentProject) {
|
190
192
|
projectService.create("landing-project", user2._id).then(function (landingProject) {
|
191
193
|
|
192
|
-
|
193
|
-
|
194
|
+
if (log) {
|
195
|
+
console.log("mock: ", chatbot_mock.existing_chatbot_mock);
|
196
|
+
}
|
194
197
|
|
195
198
|
class chatbot_service {
|
196
199
|
async getBotById(id, published, api_url, chatbot_templates_api_url, token, project_id) {
|
@@ -241,7 +244,7 @@ describe('FaqKBRoute', () => {
|
|
241
244
|
})
|
242
245
|
})
|
243
246
|
|
244
|
-
it('create bot and import json', (done) => {
|
247
|
+
it('create bot and import json qwerty', (done) => {
|
245
248
|
|
246
249
|
var email = "test-signup-" + Date.now() + "@email.com";
|
247
250
|
var pwd = "pwd";
|
@@ -253,10 +256,10 @@ describe('FaqKBRoute', () => {
|
|
253
256
|
.post('/' + savedProject._id + '/faq_kb/importjson/' + null + "?create=true")
|
254
257
|
.auth(email, pwd)
|
255
258
|
.set('Content-Type', 'text/plain')
|
256
|
-
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example.
|
259
|
+
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-json-rules.txt')), 'example-json-rules')
|
257
260
|
.end((err, res) => {
|
258
261
|
if (log) {
|
259
|
-
console.log("import json res: ", res.body);
|
262
|
+
console.log("import json res: ", JSON.stringify(res.body, null, 2));
|
260
263
|
}
|
261
264
|
res.should.have.status(200);
|
262
265
|
res.should.be.a('object');
|
@@ -273,7 +276,7 @@ describe('FaqKBRoute', () => {
|
|
273
276
|
console.log("faq_list: ", res.body);
|
274
277
|
}
|
275
278
|
res.should.have.status(200);
|
276
|
-
res.body.should.be.an('array').that.is.not.empty;
|
279
|
+
//res.body.should.be.an('array').that.is.not.empty;
|
277
280
|
|
278
281
|
done();
|
279
282
|
|
@@ -285,6 +288,49 @@ describe('FaqKBRoute', () => {
|
|
285
288
|
|
286
289
|
})
|
287
290
|
|
291
|
+
it('import json in an existing bot qwerty2', (done) => {
|
292
|
+
|
293
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
294
|
+
var pwd = "pwd";
|
295
|
+
|
296
|
+
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then(((savedUser) => {
|
297
|
+
projectService.create('test-faqkb-create', savedUser._id).then((savedProject) => {
|
298
|
+
|
299
|
+
chai.request(server)
|
300
|
+
.post('/' + savedProject._id + '/faq_kb')
|
301
|
+
.auth(email, pwd)
|
302
|
+
.send({ "name": "testbot", type: "tilebot", language: "en", template: "blank "})
|
303
|
+
.end((err, res) => {
|
304
|
+
if (log) {
|
305
|
+
console.log("res.body: ", res.body);
|
306
|
+
}
|
307
|
+
res.should.have.status(200);
|
308
|
+
res.body.should.be.a('object');
|
309
|
+
expect(res.body.name).to.equal("testbot");
|
310
|
+
expect(res.body.language).to.equal("en");
|
311
|
+
let id_faq_kb = res.body._id;
|
312
|
+
|
313
|
+
chai.request(server)
|
314
|
+
.post('/' + savedProject._id + '/faq_kb/importjson/' + id_faq_kb)
|
315
|
+
.auth(email, pwd)
|
316
|
+
.set('Content-Type', 'text/plain')
|
317
|
+
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-json-rules.txt')), 'example-json-rules')
|
318
|
+
.end((err, res) => {
|
319
|
+
if (log) {
|
320
|
+
console.log("import json res: ", JSON.stringify(res.body, null, 2));
|
321
|
+
}
|
322
|
+
res.should.have.status(200);
|
323
|
+
//res.should.be.a('object');
|
324
|
+
//expect(res.body.name).to.equal("examplebot");
|
325
|
+
//expect(res.body.language).to.equal("en");
|
326
|
+
|
327
|
+
done();
|
328
|
+
})
|
329
|
+
})
|
330
|
+
})
|
331
|
+
}))
|
332
|
+
})
|
333
|
+
|
288
334
|
|
289
335
|
it('import json (overwrite true)', (done) => {
|
290
336
|
|
@@ -703,8 +749,6 @@ describe('FaqKBRoute', () => {
|
|
703
749
|
});
|
704
750
|
|
705
751
|
newFaq.save(function (err, savedFaq) {
|
706
|
-
console.log("err", err);
|
707
|
-
console.log("savedFaq", savedFaq);
|
708
752
|
expect(savedBot.name).to.equal("testbot");
|
709
753
|
expect(savedBot.secret).to.not.equal(null);
|
710
754
|
|
@@ -714,7 +758,9 @@ describe('FaqKBRoute', () => {
|
|
714
758
|
.send({ "id_faq_kb": savedBot._id })
|
715
759
|
.end((err, res) => {
|
716
760
|
//console.log("res", res);
|
717
|
-
|
761
|
+
if (log) {
|
762
|
+
console.log("res.body", res.body);
|
763
|
+
}
|
718
764
|
res.should.have.status(200);
|
719
765
|
res.body.should.be.a('object');
|
720
766
|
expect(res.body.train.nlu.intent).to.equal(savedBot.intent_display_name);
|