@tiledesk/tiledesk-server 2.3.55 → 2.3.57

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,11 +1,14 @@
1
1
 
2
2
 
3
- 💥 TILEDESK SERVER v2.3.55 💥
3
+ 💥 TILEDESK SERVER v2.3.56 💥
4
4
  🚀 TAGGED AND PUBLISHED ON NPM 🚀
5
5
  🚀 IN PRODUCTION 🚀
6
- (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.55)
6
+ (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.56)
7
7
 
8
- # 2.3.55 -> PROD
8
+ # 2.3.56
9
+ - Tybot updated to 0.1.30
10
+
11
+ # 2.3.55
9
12
  - Tybot updated to 0.1.28
10
13
 
11
14
  # 2.3.54
package/app.js CHANGED
@@ -139,6 +139,9 @@ subscriptionNotifier.start();
139
139
 
140
140
  var botSubscriptionNotifier = require('./services/BotSubscriptionNotifier');
141
141
  botSubscriptionNotifier.start();
142
+
143
+ var trainingService = require('./services/trainingService');
144
+ trainingService.start();
142
145
 
143
146
  // job_here
144
147
 
@@ -172,8 +175,8 @@ var IPFilter = require('./middleware/ipFilter');
172
175
 
173
176
  // job_here
174
177
  var BanUserNotifier = require('./services/banUserNotifier');
175
- const { ChatbotService } = require('./services/chatbotService');
176
178
  BanUserNotifier.listen();
179
+ const { ChatbotService } = require('./services/chatbotService');
177
180
 
178
181
  var modulesManager = undefined;
179
182
  try {
package/models/faq.js CHANGED
@@ -9,23 +9,23 @@ var defaultFullTextLanguage = process.env.DEFAULT_FULLTEXT_INDEX_LANGUAGE || "no
9
9
  var FaqSchema = new Schema({
10
10
  id_faq_kb: {
11
11
  type: String,
12
- index: true
12
+ index: true
13
13
  },
14
- intent_id: {
14
+ intent_id: {
15
15
  type: String,
16
16
  required: false,
17
- index:true,
18
- default: function() {
17
+ index: true,
18
+ default: function () {
19
19
  return uuidv4();
20
- }
20
+ }
21
21
  },
22
22
  intent_display_name: { //documentare
23
23
  type: String,
24
- required: false,
25
- index:true,
26
- default: function() {
24
+ required: false,
25
+ index: true,
26
+ default: function () {
27
27
  return nanoid(6);
28
- }
28
+ }
29
29
  },
30
30
  question: {
31
31
  type: String,
@@ -74,11 +74,11 @@ var FaqSchema = new Schema({
74
74
  index: true
75
75
  },
76
76
 
77
- // "stats":{
78
- // "conversation_count":2,
79
- // "all_done_count":0,
80
- // "wait_for_team_count":2
81
- // }
77
+ // "stats":{
78
+ // "conversation_count":2,
79
+ // "all_done_count":0,
80
+ // "wait_for_team_count":2
81
+ // }
82
82
 
83
83
  createdBy: {
84
84
  type: String,
@@ -88,7 +88,7 @@ var FaqSchema = new Schema({
88
88
  type: Object,
89
89
  required: false
90
90
  }
91
- },{
91
+ }, {
92
92
  timestamps: true,
93
93
  toJSON: { virtuals: true } //used to polulate messages in toJSON// https://mongoosejs.com/docs/populate.html
94
94
  }
@@ -102,26 +102,60 @@ FaqSchema.virtual('faq_kb', {
102
102
  //options: { sort: { name: -1 }, limit: 5 } // Query options, see http://bit.ly/mongoose-query-options
103
103
  });
104
104
 
105
- FaqSchema.index({ id_project: 1, id_faq_kb: 1, question: 1 });
105
+ FaqSchema.index({ id_project: 1, id_faq_kb: 1, question: 1 });
106
106
 
107
107
  // https://docs.mongodb.com/manual/core/index-text/
108
108
  // https://docs.mongodb.com/manual/tutorial/specify-language-for-text-index/
109
109
  // https://docs.mongodb.com/manual/reference/text-search-languages/#text-search-languages
110
110
 
111
-
112
- FaqSchema.index({question: 'text'},
113
- {"name":"faq_fulltext","default_language": defaultFullTextLanguage,"language_override": "language"}); // schema level
111
+ // In testing...
112
+ // FaqSchema.index({ question: "text", answer: "text" }, { weights: { question: 5, answer: 3 } })
113
+
114
+ // FaqSchema.statics = {
115
+ // searchPartial: function (q, callback) {
116
+ // return this.find({
117
+ // $or: [
118
+ // { "question": new RegExp(q, "gi") },
119
+ // { "answer": new RegExp(q, "gi") },
120
+ // ]
121
+ // }, callback)
122
+ // },
123
+
124
+ // searchFull: function (q, callback) {
125
+ // return this.find({
126
+ // $text: { $search: q, $caseSensitive: false }
127
+ // }, callback)
128
+ // },
129
+
130
+ // searchFull: function (q, callback) {
131
+ // return this.find({
132
+ // $text: { $search: q, $caseSensitive: false }
133
+ // }, callback)
134
+ // },
135
+
136
+ // search: function (q, callback) {
137
+ // this.searchFull(q, (err, data) => {
138
+ // if (err) return callback(err, data);
139
+ // if (!err && data.length) return callback(err, data);
140
+ // if (!err && data.length === 0) return this.searchPartial(q, callback);
141
+ // });
142
+ // },
143
+
144
+ // }
145
+
146
+ FaqSchema.index({ question: 'text' },
147
+ { "name": "faq_fulltext", "default_language": defaultFullTextLanguage, "language_override": "language" }); // schema level
114
148
 
115
149
  // FaqSchema.index({question: 'text', answer: 'text'},
116
- // {"name":"faq_fulltext","default_language": defaultFullTextLanguage,"language_override": "language", weights: {question: 10,answer: 1}}); // schema level
150
+ // {"name":"faq_fulltext","default_language": defaultFqullTextLanguage,"language_override": "language", weights: {question: 10,answer: 1}}); // schema level
117
151
 
118
152
 
119
- FaqSchema.index({ id_project: 1, id_faq_kb: 1, intent_display_name: 1 }, { unique: true });
153
+ FaqSchema.index({ id_project: 1, id_faq_kb: 1, intent_display_name: 1 }, { unique: true });
120
154
 
121
155
 
122
- var faq = mongoose.model('faq', FaqSchema);
156
+ var faq = mongoose.model('faq', FaqSchema);
123
157
 
124
- faq.on('index', function(error) {
158
+ faq.on('index', function (error) {
125
159
  // "_id index cannot be sparse"
126
160
  winston.debug('index', error);
127
161
  });
package/models/faq_kb.js CHANGED
@@ -70,6 +70,20 @@ var Faq_kbSchema = new Schema({
70
70
  type: Boolean,
71
71
  required: false,
72
72
  default: false
73
+ },
74
+ certified: {
75
+ type: Boolean,
76
+ required: false,
77
+ default: false
78
+ },
79
+ mainCategory: {
80
+ type: String,
81
+ required: false
82
+ },
83
+ intentsEngine: {
84
+ type: String,
85
+ required: false,
86
+ default: 'none'
73
87
  }
74
88
  },{
75
89
  timestamps: true
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.55",
4
+ "version": "2.3.57",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -42,7 +42,7 @@
42
42
  "@tiledesk/tiledesk-chatbot-util": "^0.8.33",
43
43
  "@tiledesk/tiledesk-json-rules-engine": "^4.0.3",
44
44
  "@tiledesk/tiledesk-rasa-connector": "^1.0.10",
45
- "@tiledesk/tiledesk-tybot-connector": "^0.1.28",
45
+ "@tiledesk/tiledesk-tybot-connector": "^0.1.30",
46
46
  "@tiledesk/tiledesk-dialogflow-connector": "^1.7.4",
47
47
  "app-root-path": "^3.0.0",
48
48
  "bcrypt-nodejs": "0.0.3",
package/routes/faq.js CHANGED
@@ -194,8 +194,6 @@ router.put('/:faqid', function (req, res) {
194
194
  if (req.body.form!=undefined) {
195
195
  update.form = req.body.form;
196
196
  }
197
-
198
-
199
197
 
200
198
  Faq.findByIdAndUpdate(req.params.faqid, update, { new: true, upsert: true }, function (err, updatedFaq) {
201
199
  if (err) {
@@ -329,7 +327,11 @@ router.get('/', function (req, res, next) {
329
327
  // return Faq.find(query, {score: { $meta: "textScore" } })
330
328
  // .sort( { score: { $meta: "textScore" } } ) //https://docs.mongodb.com/manual/reference/operator/query/text/#sort-by-text-search-score
331
329
 
332
-
330
+ // in testing...
331
+ // return Faq.search('a closer', (err, result) => {
332
+ // console.log("result: ", result);
333
+ // })
334
+
333
335
  return Faq.find(query).
334
336
  skip(skip).limit(limit).
335
337
  populate({path:'faq_kb'})//, match: { trashed: { $in: [null, false] } }}).
package/routes/faq_kb.js CHANGED
@@ -15,11 +15,10 @@ var configGlobal = require('../config/global');
15
15
 
16
16
  var chatbot_templates_api_url = "https://chatbot-templates.herokuapp.com/chatbots/public/templates"
17
17
 
18
-
19
18
  router.post('/', function (req, res) {
20
19
  winston.info('create BOT ', req.body);
21
20
  //create(name, url, projectid, user_id, type, description, webhook_url, webhook_enabled, language, template)
22
- faqService.create(req.body.name, req.body.url, req.projectid, req.user.id, req.body.type, req.body.description, undefined, undefined, req.body.language, req.body.template).then(function (savedFaq_kb) {
21
+ faqService.create(req.body.name, req.body.url, req.projectid, req.user.id, req.body.type, req.body.description, undefined, undefined, req.body.language, req.body.template, req.body.mainCategory, req.body.intentsEngine).then(function (savedFaq_kb) {
23
22
  res.json(savedFaq_kb);
24
23
  });
25
24
 
@@ -232,13 +231,24 @@ router.put('/:faq_kbid', function (req, res) {
232
231
  if (req.body.webhook_enabled != undefined) {
233
232
  update.webhook_enabled = req.body.webhook_enabled;
234
233
  }
235
-
236
234
  if (req.body.type != undefined) {
237
235
  update.type = req.body.type;
238
236
  }
239
237
  if (req.body.trashed != undefined) {
240
238
  update.trashed = req.body.trashed;
241
239
  }
240
+ if (req.body.public != undefined) {
241
+ update.public = req.body.public;
242
+ }
243
+ if (req.body.certified != undefined) {
244
+ update.certified = req.body.certified;
245
+ }
246
+ if (req.body.mainCategory != undefined) {
247
+ update.mainCategory = req.body.mainCategory;
248
+ }
249
+ if (req.body.intentsEngine != undefined) {
250
+ update.intentsEngine = req.body.intentsEngine;
251
+ }
242
252
 
243
253
  Faq_kb.findByIdAndUpdate(req.params.faq_kbid, update, { new: true, upsert: true }, function (err, updatedFaq_kb) {
244
254
  if (err) {
@@ -356,9 +366,6 @@ router.post('/fork/:id_faq_kb', async (req, res) => {
356
366
  let landing_project_id = req.query.projectid;
357
367
  winston.info("landing project id " + landing_project_id)
358
368
 
359
- let new_bot_name = req.query.name;
360
- winston.info("new bot name: " + new_bot_name);
361
-
362
369
  let public = req.query.public;
363
370
  winston.info("public " + public);
364
371
 
@@ -373,8 +380,6 @@ router.post('/fork/:id_faq_kb', async (req, res) => {
373
380
  return res.status(500).send({ success: false, message: "Unable to get chatbot" });
374
381
  }
375
382
 
376
- //chatbot.name = new_bot_name;
377
-
378
383
  let savedChatbot = await cs.createBot(api_url, token, chatbot, landing_project_id);
379
384
  winston.info("savedChatbot: ", savedChatbot)
380
385
 
@@ -42,7 +42,7 @@ class ChatbotService {
42
42
  },
43
43
  method: 'GET'
44
44
  }).then((resbody) => {
45
- winston.info("(CHATBOT SERVICE) forking public chatbot " + resbody.data);
45
+ winston.info("(CHATBOT SERVICE) forking public chatbot " + resbody.data.name);
46
46
  let chatbot = resbody.data;
47
47
  return chatbot
48
48
  }).catch((err) => {
@@ -8,7 +8,7 @@ const ActionsConstants = require('../models/actionsConstants');
8
8
  class FaqService {
9
9
 
10
10
 
11
- create(name, url, projectid, user_id, type, description, webhook_url, webhook_enabled, language, template) {
11
+ create(name, url, projectid, user_id, type, description, webhook_url, webhook_enabled, language, template, mainCategory, intentsEngine) {
12
12
  var that = this;
13
13
  return new Promise(function (resolve, reject) {
14
14
 
@@ -23,6 +23,9 @@ class FaqService {
23
23
  type: type,
24
24
  language: language,
25
25
  public: false,
26
+ certified: false,
27
+ mainCategory: mainCategory,
28
+ intentsEngine: intentsEngine,
26
29
  trashed: false,
27
30
  createdBy: user_id,
28
31
  updatedBy: user_id
@@ -0,0 +1,106 @@
1
+ const faqBotEvent = require('../event/faqBotEvent');
2
+ const Faq_kb = require('../models/faq_kb');
3
+ const Faq = require('../models/faq');
4
+ var winston = require('../config/winston');
5
+ const axios = require("axios").default;
6
+
7
+
8
+ let chatbot_training_api_url = "http://34.65.210.38/model/train"
9
+
10
+ class TrainingService {
11
+
12
+
13
+
14
+ train(eventName, faq) {
15
+
16
+ Faq_kb.findById(faq.id_faq_kb, (err, faq_kb) => {
17
+ winston.debug("faq_kb: ", faq_kb)
18
+
19
+ if (!faq_kb.intentsEngine) {
20
+ winston.info("intentsEngine: off")
21
+ return null;
22
+ }
23
+
24
+ winston.info("intentsEngine: on")
25
+ Faq.find({ id_faq_kb: faq.id_faq_kb }, (err, faqs) => {
26
+
27
+ if (err) {
28
+ winston.error("[Training] find all error: ", err);
29
+ } else {
30
+
31
+ let json = {
32
+ "configuration": {
33
+ "language": faq_kb.language,
34
+ "pipeline": [""]
35
+ },
36
+ "model": faq_kb._id,
37
+ "nlu": []
38
+ }
39
+
40
+ faqs.forEach((f) => {
41
+ if (f.enabled == true) {
42
+ let intent = {
43
+ "intent": f.intent_display_name,
44
+ "examples": []
45
+ }
46
+ let questions = f.question.split("\n");
47
+ intent.examples = questions;
48
+ json.nlu.push(intent);
49
+ }
50
+ })
51
+
52
+ winston.debug("training json: \n" + JSON.stringify(json, null, 2));
53
+
54
+ axios({
55
+ url: chatbot_training_api_url,
56
+ headers: {
57
+ 'Content-Type': 'application/json'
58
+ },
59
+ data: json,
60
+ method: 'POST'
61
+ }).then((resbody) => {
62
+ winston.info("[Training] resbody: ", resbody.data);
63
+ return true;
64
+ }).catch((err) => {
65
+ winston.error("[Training] error: ", err.response.data);
66
+ })
67
+ }
68
+ })
69
+
70
+ })
71
+
72
+
73
+
74
+ }
75
+
76
+ start() {
77
+ winston.info('TrainingService start');
78
+
79
+ faqBotEvent.on('faq.create', (faq) => {
80
+ setImmediate(() => {
81
+ trainingService.train('faq.create', faq);
82
+ })
83
+ })
84
+
85
+ faqBotEvent.on('faq.update', (faq) => {
86
+ winston.debug("--> event faq: ", faq);
87
+ setImmediate(() => {
88
+ trainingService.train('faq.update', faq);
89
+ })
90
+ })
91
+
92
+ faqBotEvent.on('faq.delete', (faq) => {
93
+ console.log("--> event faq: ", faq);
94
+ setImmediate(() => {
95
+ trainingService.train('faq.delete', faq);
96
+ })
97
+ })
98
+
99
+
100
+ }
101
+
102
+ }
103
+
104
+ var trainingService = new TrainingService();
105
+
106
+ module.exports = trainingService;
package/test/faqRoute.js CHANGED
@@ -19,28 +19,30 @@ const path = require('path');
19
19
  var expect = chai.expect;
20
20
  var assert = chai.assert;
21
21
 
22
+ let log = true;
23
+
22
24
  chai.use(chaiHttp);
23
25
 
24
26
  describe('FaqKBRoute', () => {
25
27
 
26
- describe('/create', () => {
27
-
28
- it('create', (done) => {
29
-
30
- // this.timeout();
28
+ describe('/create', () => {
29
+
30
+ it('create', (done) => {
31
+
32
+ // this.timeout();
31
33
 
32
- var email = "test-signup-" + Date.now() + "@email.com";
33
- var pwd = "pwd";
34
+ var email = "test-signup-" + Date.now() + "@email.com";
35
+ var pwd = "pwd";
34
36
 
35
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
36
- projectService.create("test-faqkb-create", savedUser._id).then(function(savedProject) {
37
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
38
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
37
39
  chai.request(server)
38
- .post('/'+ savedProject._id + '/faq_kb')
40
+ .post('/' + savedProject._id + '/faq_kb')
39
41
  .auth(email, pwd)
40
- .send({"name":"testbot", type: "internal"})
42
+ .send({ "name": "testbot", type: "internal" })
41
43
  .end((err, res) => {
42
44
  //console.log("res", res);
43
- console.log("res.body", res.body);
45
+ console.log("res.body", res.body);
44
46
  res.should.have.status(200);
45
47
  res.body.should.be.a('object');
46
48
  expect(res.body.name).to.equal("testbot");
@@ -48,380 +50,418 @@ describe('FaqKBRoute', () => {
48
50
  expect(res.body.public).to.equal(false);
49
51
  var id_faq_kb = res.body._id;
50
52
 
51
- chai.request(server)
52
- .post('/'+ savedProject._id + '/faq')
53
+ chai.request(server)
54
+ .post('/' + savedProject._id + '/faq')
53
55
  .auth(email, pwd)
54
- .send({id_faq_kb: id_faq_kb, question: "question1", answer: "answer1"})
56
+ .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1" })
55
57
  .end((err, res) => {
56
58
  //console.log("res", res);
57
- console.log("res.body", res.body);
59
+ console.log("res.body", res.body);
58
60
  res.should.have.status(200);
59
61
  res.body.should.be.a('object');
60
- expect(res.body.id_faq_kb).to.equal(id_faq_kb);
61
- expect(res.body.question).to.equal("question1");
62
- expect(res.body.answer).to.equal("answer1");
63
- expect(res.body.intent_display_name).to.not.equal(undefined);
64
- expect(res.body.webhook_enabled).to.equal(false);
65
-
62
+ expect(res.body.id_faq_kb).to.equal(id_faq_kb);
63
+ expect(res.body.question).to.equal("question1");
64
+ expect(res.body.answer).to.equal("answer1");
65
+ expect(res.body.intent_display_name).to.not.equal(undefined);
66
+ expect(res.body.webhook_enabled).to.equal(false);
67
+
66
68
  done();
67
69
  });
68
70
 
69
71
  });
70
72
 
71
-
73
+
72
74
  });
73
75
  });
74
-
75
- });
76
76
 
77
- it('create with form (createFaqKb function)', (done) => {
78
-
79
-
80
- // this.timeout();
81
-
82
- var email = "test-signup-" + Date.now() + "@email.com";
83
- var pwd = "pwd";
84
- let example_form = {
85
- fields: [
86
- {
87
- name: "userFullname",
88
- type: "text",
89
- label: "What is your name?"
90
- },
91
- {
92
- name: "userEmail",
93
- type: "text",
94
- regex: "/^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'+/0-9=?A-Z^_`a-z{|}~]+(.[-!#$%&'+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$/",
95
- label: "Your email?",
96
- errorLabel: "This email address is invalid\n\nCan you insert a correct email address?"
97
- }
98
- ]
99
- }
100
-
101
- userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
102
- projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
103
-
104
- chai.request(server)
105
- .post('/' + savedProject._id + '/faq_kb')
106
- .auth(email, pwd)
107
- .send({ "name": "testbot", type: "external", language: 'fr' })
108
- .end((err, res) => {
109
- //console.log("res", res);
110
- console.log("res.body", res.body);
111
- res.should.have.status(200);
112
- res.body.should.be.a('object');
113
- expect(res.body.name).to.equal("testbot");
114
- expect(res.body.language).to.equal("fr");
115
- var id_faq_kb = res.body._id;
116
-
117
- chai.request(server)
118
- .post('/'+ savedProject._id + '/faq')
119
- .auth(email, pwd)
120
- .send({id_faq_kb: id_faq_kb, form: example_form})
121
- .end((err, res) => {
122
- //console.log("res", res);
123
- console.log("res.body", res.body);
124
- res.should.have.status(200);
125
- res.body.should.be.a('object');
126
- expect(res.body.id_faq_kb).to.equal(id_faq_kb);
127
- expect(res.body.form).to.exist;
128
- res.body.form.should.be.a('object');
129
- expect(res.body.intent_display_name).to.not.equal(undefined);
130
- expect(res.body.webhook_enabled).to.equal(false);
131
-
132
- done();
133
- });
134
- });
77
+ });
135
78
 
79
+ it('create with form (createFaqKb function)', (done) => {
136
80
 
81
+
82
+ // this.timeout();
83
+
84
+ var email = "test-signup-" + Date.now() + "@email.com";
85
+ var pwd = "pwd";
86
+ let example_form = {
87
+ fields: [
88
+ {
89
+ name: "userFullname",
90
+ type: "text",
91
+ label: "What is your name?"
92
+ },
93
+ {
94
+ name: "userEmail",
95
+ type: "text",
96
+ regex: "/^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'+/0-9=?A-Z^_`a-z{|}~]+(.[-!#$%&'+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$/",
97
+ label: "Your email?",
98
+ errorLabel: "This email address is invalid\n\nCan you insert a correct email address?"
99
+ }
100
+ ]
101
+ }
102
+
103
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
104
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
105
+
106
+ chai.request(server)
107
+ .post('/' + savedProject._id + '/faq_kb')
108
+ .auth(email, pwd)
109
+ .send({ "name": "testbot", type: "external", language: 'fr' })
110
+ .end((err, res) => {
111
+ //console.log("res", res);
112
+ console.log("res.body", res.body);
113
+ res.should.have.status(200);
114
+ res.body.should.be.a('object');
115
+ expect(res.body.name).to.equal("testbot");
116
+ expect(res.body.language).to.equal("fr");
117
+ var id_faq_kb = res.body._id;
118
+
119
+ chai.request(server)
120
+ .post('/' + savedProject._id + '/faq')
121
+ .auth(email, pwd)
122
+ .send({ id_faq_kb: id_faq_kb, form: example_form })
123
+ .end((err, res) => {
124
+ //console.log("res", res);
125
+ console.log("res.body", res.body);
126
+ res.should.have.status(200);
127
+ res.body.should.be.a('object');
128
+ expect(res.body.id_faq_kb).to.equal(id_faq_kb);
129
+ expect(res.body.form).to.exist;
130
+ res.body.form.should.be.a('object');
131
+ expect(res.body.intent_display_name).to.not.equal(undefined);
132
+ expect(res.body.webhook_enabled).to.equal(false);
133
+
134
+ done();
135
+ });
136
+ });
137
+
138
+
139
+ });
140
+ });
141
+
142
+ }).timeout(20000);
143
+
144
+
145
+
146
+ it('createWithLanguage', (done) => {
147
+
148
+
149
+ // this.timeout();
150
+
151
+ var email = "test-signup-" + Date.now() + "@email.com";
152
+ var pwd = "pwd";
153
+
154
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
155
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
156
+ chai.request(server)
157
+ .post('/' + savedProject._id + '/faq_kb')
158
+ .auth(email, pwd)
159
+ .send({ "name": "testbot", type: "internal", template: "example", language: "it" })
160
+ .end((err, res) => {
161
+ //console.log("res", res);
162
+ console.log("res.body", res.body);
163
+ res.should.have.status(200);
164
+ res.body.should.be.a('object');
165
+ expect(res.body.name).to.equal("testbot");
166
+ expect(res.body.language).to.equal("it");
167
+ var id_faq_kb = res.body._id;
168
+
169
+ chai.request(server)
170
+ .post('/' + savedProject._id + '/faq')
171
+ .auth(email, pwd)
172
+ .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1" })
173
+ .end((err, res) => {
174
+ //console.log("res", res);
175
+ console.log("res.body", res.body);
176
+ res.should.have.status(200);
177
+ res.body.should.be.a('object');
178
+ expect(res.body.id_faq_kb).to.equal(id_faq_kb);
179
+ expect(res.body.question).to.equal("question1");
180
+ expect(res.body.answer).to.equal("answer1");
181
+ expect(res.body.intent_display_name).to.not.equal(undefined);
182
+ expect(res.body.webhook_enabled).to.equal(false);
183
+ expect(res.body.language).to.equal("it");
184
+ done();
185
+ });
186
+
187
+ });
188
+
189
+
190
+ });
137
191
  });
138
- });
139
192
 
140
- }).timeout(20000);
141
-
142
-
143
-
144
- it('createWithLanguage', (done) => {
145
-
146
-
147
- // this.timeout();
148
-
149
- var email = "test-signup-" + Date.now() + "@email.com";
150
- var pwd = "pwd";
151
-
152
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
153
- projectService.create("test-faqkb-create", savedUser._id).then(function(savedProject) {
154
- chai.request(server)
155
- .post('/'+ savedProject._id + '/faq_kb')
156
- .auth(email, pwd)
157
- .send({"name":"testbot", type: "internal", template: "example", language: "it"})
158
- .end((err, res) => {
159
- //console.log("res", res);
160
- console.log("res.body", res.body);
161
- res.should.have.status(200);
162
- res.body.should.be.a('object');
163
- expect(res.body.name).to.equal("testbot");
164
- expect(res.body.language).to.equal("it");
165
- var id_faq_kb = res.body._id;
166
-
167
- chai.request(server)
168
- .post('/'+ savedProject._id + '/faq')
169
- .auth(email, pwd)
170
- .send({id_faq_kb: id_faq_kb, question: "question1", answer: "answer1"})
171
- .end((err, res) => {
172
- //console.log("res", res);
173
- console.log("res.body", res.body);
174
- res.should.have.status(200);
175
- res.body.should.be.a('object');
176
- expect(res.body.id_faq_kb).to.equal(id_faq_kb);
177
- expect(res.body.question).to.equal("question1");
178
- expect(res.body.answer).to.equal("answer1");
179
- expect(res.body.intent_display_name).to.not.equal(undefined);
180
- expect(res.body.webhook_enabled).to.equal(false);
181
- expect(res.body.language).to.equal("it");
182
- done();
183
- });
184
-
185
- });
186
-
187
-
188
- });
189
- });
190
-
191
193
  });
192
-
193
-
194
194
 
195
195
 
196
196
 
197
197
 
198
- it('createWithIntentDisplayNameAndWebhookEnalbed', (done) => {
199
198
 
200
-
201
- // this.timeout();
202
-
203
- var email = "test-signup-" + Date.now() + "@email.com";
204
- var pwd = "pwd";
205
-
206
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
207
- projectService.create("test-faqkb-create", savedUser._id).then(function(savedProject) {
208
-
199
+
200
+ it('createWithIntentDisplayNameAndWebhookEnalbed', (done) => {
201
+
202
+
203
+ // this.timeout();
204
+
205
+ var email = "test-signup-" + Date.now() + "@email.com";
206
+ var pwd = "pwd";
207
+
208
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
209
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
210
+
209
211
  chai.request(server)
210
- .post('/'+ savedProject._id + '/faq_kb')
212
+ .post('/' + savedProject._id + '/faq_kb')
211
213
  .auth(email, pwd)
212
- .send({"name":"testbot", type: "internal", template: "example",})
214
+ .send({ "name": "testbot", type: "internal", template: "example", })
213
215
  .end((err, res) => {
214
216
  //console.log("res", res);
215
- console.log("res.body", res.body);
217
+ console.log("res.body", res.body);
216
218
  res.should.have.status(200);
217
219
  res.body.should.be.a('object');
218
- expect(res.body.name).to.equal("testbot");
220
+ expect(res.body.name).to.equal("testbot");
219
221
  var id_faq_kb = res.body._id;
220
222
 
221
- chai.request(server)
222
- .post('/'+ savedProject._id + '/faq')
223
+ chai.request(server)
224
+ .post('/' + savedProject._id + '/faq')
223
225
  .auth(email, pwd)
224
- .send({id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", webhook_enabled:true, intent_display_name: "intent_display_name1"})
226
+ .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", webhook_enabled: true, intent_display_name: "intent_display_name1" })
225
227
  .end((err, res) => {
226
228
  //console.log("res", res);
227
- console.log("res.body", res.body);
229
+ console.log("res.body", res.body);
228
230
  res.should.have.status(200);
229
231
  res.body.should.be.a('object');
230
- expect(res.body.id_faq_kb).to.equal(id_faq_kb);
231
- expect(res.body.question).to.equal("question1");
232
- expect(res.body.answer).to.equal("answer1");
233
- expect(res.body.intent_display_name).to.equal("intent_display_name1");
234
- expect(res.body.webhook_enabled).to.equal(true);
232
+ expect(res.body.id_faq_kb).to.equal(id_faq_kb);
233
+ expect(res.body.question).to.equal("question1");
234
+ expect(res.body.answer).to.equal("answer1");
235
+ expect(res.body.intent_display_name).to.equal("intent_display_name1");
236
+ expect(res.body.webhook_enabled).to.equal(true);
235
237
 
236
238
  done();
237
239
  });
238
240
 
239
241
  });
240
-
241
-
242
- });
243
- });
244
-
242
+
243
+
244
+ });
245
+ });
246
+
245
247
  });
246
-
247
-
248
+
249
+
248
250
 
249
251
 
250
252
 
251
253
  it('update', (done) => {
252
254
 
253
-
255
+
254
256
  // this.timeout();
255
-
256
- var email = "test-signup-" + Date.now() + "@email.com";
257
- var pwd = "pwd";
258
-
259
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
260
- projectService.create("test-faqkb-create", savedUser._id).then(function(savedProject) {
257
+
258
+ var email = "test-signup-" + Date.now() + "@email.com";
259
+ var pwd = "pwd";
260
+
261
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
262
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
263
+ chai.request(server)
264
+ .post('/' + savedProject._id + '/faq_kb')
265
+ .auth(email, pwd)
266
+ .send({ "name": "testbot", type: "internal" })
267
+ .end((err, res) => {
268
+ //console.log("res", res);
269
+ console.log("res.body", res.body);
270
+ res.should.have.status(200);
271
+ res.body.should.be.a('object');
272
+ expect(res.body.name).to.equal("testbot");
273
+ var id_faq_kb = res.body._id;
274
+
261
275
  chai.request(server)
262
- .post('/'+ savedProject._id + '/faq_kb')
276
+ .post('/' + savedProject._id + '/faq')
263
277
  .auth(email, pwd)
264
- .send({"name":"testbot", type: "internal"})
278
+ .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1" })
265
279
  .end((err, res) => {
266
280
  //console.log("res", res);
267
- console.log("res.body", res.body);
281
+ console.log("res.body", res.body);
268
282
  res.should.have.status(200);
269
283
  res.body.should.be.a('object');
270
- expect(res.body.name).to.equal("testbot");
271
- var id_faq_kb = res.body._id;
272
-
273
- chai.request(server)
274
- .post('/'+ savedProject._id + '/faq')
284
+ expect(res.body.id_faq_kb).to.equal(id_faq_kb);
285
+ expect(res.body.question).to.equal("question1");
286
+ expect(res.body.answer).to.equal("answer1");
287
+ expect(res.body.intent_display_name).to.not.equal(undefined);
288
+ expect(res.body.webhook_enabled).to.equal(false);
289
+
290
+ chai.request(server)
291
+ .put('/' + savedProject._id + '/faq/' + res.body._id)
275
292
  .auth(email, pwd)
276
- .send({id_faq_kb: id_faq_kb, question: "question1", answer: "answer1"})
293
+ .send({ id_faq_kb: id_faq_kb, question: "question2", answer: "answer2", webhook_enabled: true })
277
294
  .end((err, res) => {
278
295
  //console.log("res", res);
279
- console.log("res.body", res.body);
296
+ console.log("res.body", res.body);
280
297
  res.should.have.status(200);
281
298
  res.body.should.be.a('object');
282
- expect(res.body.id_faq_kb).to.equal(id_faq_kb);
283
- expect(res.body.question).to.equal("question1");
284
- expect(res.body.answer).to.equal("answer1");
285
- expect(res.body.intent_display_name).to.not.equal(undefined);
286
- expect(res.body.webhook_enabled).to.equal(false);
287
-
288
- chai.request(server)
289
- .put('/'+ savedProject._id + '/faq/'+res.body._id)
290
- .auth(email, pwd)
291
- .send({id_faq_kb: id_faq_kb, question: "question2", answer: "answer2", webhook_enabled:true})
292
- .end((err, res) => {
293
- //console.log("res", res);
294
- console.log("res.body", res.body);
295
- res.should.have.status(200);
296
- res.body.should.be.a('object');
297
- expect(res.body.id_faq_kb).to.equal(id_faq_kb);
298
- expect(res.body.question).to.equal("question2");
299
- expect(res.body.answer).to.equal("answer2");
300
- expect(res.body.intent_display_name).to.not.equal(undefined);
301
- expect(res.body.webhook_enabled).to.equal(true);
302
-
303
- done();
304
- });
299
+ expect(res.body.id_faq_kb).to.equal(id_faq_kb);
300
+ expect(res.body.question).to.equal("question2");
301
+ expect(res.body.answer).to.equal("answer2");
302
+ expect(res.body.intent_display_name).to.not.equal(undefined);
303
+ expect(res.body.webhook_enabled).to.equal(true);
305
304
 
305
+ done();
306
306
  });
307
-
307
+
308
308
  });
309
-
310
-
311
- });
309
+
312
310
  });
313
-
311
+
312
+
313
+ });
314
314
  });
315
315
 
316
-
316
+ });
317
+
318
+
317
319
  it('uploadcsv', (done) => {
318
320
 
319
-
321
+
320
322
  // this.timeout();
321
-
322
- var email = "test-signup-" + Date.now() + "@email.com";
323
- var pwd = "pwd";
324
-
325
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
326
- projectService.create("test-uploadcsv", savedUser._id).then(function(savedProject) {
327
-
328
- chai.request(server)
329
- .post('/'+ savedProject._id + '/faq_kb')
323
+
324
+ var email = "test-signup-" + Date.now() + "@email.com";
325
+ var pwd = "pwd";
326
+
327
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
328
+ projectService.create("test-uploadcsv", savedUser._id).then(function (savedProject) {
329
+
330
+ chai.request(server)
331
+ .post('/' + savedProject._id + '/faq_kb')
330
332
  .auth(email, pwd)
331
- .send({"name":"testbot", type: "internal"})
333
+ .send({ "name": "testbot", type: "internal" })
332
334
  .end((err, res) => {
333
335
  //console.log("res", res);
334
- console.log("res.body", res.body);
336
+ console.log("res.body", res.body);
335
337
  res.should.have.status(200);
336
338
  res.body.should.be.a('object');
337
- expect(res.body.name).to.equal("testbot");
339
+ expect(res.body.name).to.equal("testbot");
338
340
  var id_faq_kb = res.body._id;
339
341
 
340
342
  chai.request(server)
341
- .post('/'+ savedProject._id + '/faq/uploadcsv')
343
+ .post('/' + savedProject._id + '/faq/uploadcsv')
342
344
  .auth(email, pwd)
343
345
  .set('Content-Type', 'text/csv')
344
- .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-faqs.csv')), 'example-faqs.csv')
346
+ .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-faqs.csv')), 'example-faqs.csv')
345
347
  .field('id_faq_kb', id_faq_kb)
346
348
  .field('delimiter', ';')
347
349
  // .send({id_faq_kb: id_faq_kb})
348
350
  .end((err, res) => {
349
- console.log("err", err);
350
- console.log("res.body", res.body);
351
+ console.log("err", err);
352
+ console.log("res.body", res.body);
351
353
  res.should.have.status(200);
352
354
  res.body.should.be.a('object');
353
-
355
+
354
356
  done();
355
357
  });
356
-
357
- });
358
-
359
- });
358
+
360
359
  });
361
-
360
+
361
+ });
362
362
  });
363
-
363
+
364
+ });
365
+
366
+
364
367
 
365
368
 
366
369
 
367
370
 
368
371
 
369
-
370
372
  it('uploadcsvWithLanguage', (done) => {
371
373
 
372
-
374
+
373
375
  // this.timeout();
374
-
375
- var email = "test-signup-" + Date.now() + "@email.com";
376
- var pwd = "pwd";
377
-
378
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
379
- projectService.create("test-uploadcsv", savedUser._id).then(function(savedProject) {
380
-
381
- chai.request(server)
382
- .post('/'+ savedProject._id + '/faq_kb')
376
+
377
+ var email = "test-signup-" + Date.now() + "@email.com";
378
+ var pwd = "pwd";
379
+
380
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
381
+ projectService.create("test-uploadcsv", savedUser._id).then(function (savedProject) {
382
+
383
+ chai.request(server)
384
+ .post('/' + savedProject._id + '/faq_kb')
383
385
  .auth(email, pwd)
384
- .send({"name":"testbot", type: "internal", language: "it"})
386
+ .send({ "name": "testbot", type: "internal", language: "it" })
385
387
  .end((err, res) => {
386
388
  //console.log("res", res);
387
- console.log("res.body", res.body);
389
+ console.log("res.body", res.body);
388
390
  res.should.have.status(200);
389
391
  res.body.should.be.a('object');
390
- expect(res.body.name).to.equal("testbot");
391
- expect(res.body.language).to.equal("it");
392
+ expect(res.body.name).to.equal("testbot");
393
+ expect(res.body.language).to.equal("it");
392
394
  var id_faq_kb = res.body._id;
393
395
 
394
396
  chai.request(server)
395
- .post('/'+ savedProject._id + '/faq/uploadcsv')
397
+ .post('/' + savedProject._id + '/faq/uploadcsv')
396
398
  .auth(email, pwd)
397
399
  .set('Content-Type', 'text/csv')
398
- .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-faqs.csv')), 'example-faqs.csv')
400
+ .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-faqs.csv')), 'example-faqs.csv')
399
401
  .field('id_faq_kb', id_faq_kb)
400
402
  .field('delimiter', ';')
401
403
  // .send({id_faq_kb: id_faq_kb})
402
404
  .end((err, res) => {
403
- console.log("err", err);
404
- console.log("res.body", res.body);
405
+ console.log("err", err);
406
+ console.log("res.body", res.body);
405
407
  res.should.have.status(200);
406
408
  res.body.should.be.a('object');
407
-
409
+
408
410
  done();
409
411
  });
410
-
411
- });
412
-
413
- });
412
+
414
413
  });
415
-
414
+
415
+ });
416
416
  });
417
-
418
-
419
-
420
-
417
+
418
+ });
421
419
 
422
420
 
421
+ it('searchFaqs', (done) => {
423
422
 
424
- });
423
+ var email = "test-signup-" + Date.now() + "@email.com";
424
+ var pwd = "pwd";
425
+
426
+ userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
427
+ projectService.create("test-search-faqs", savedUser._id).then((savedProject) => {
428
+
429
+ chai.request(server)
430
+ .post('/' + savedProject._id + '/faq_kb')
431
+ .auth(email, pwd)
432
+ .send({ "name": "testbot", type: "internal", template: "example" })
433
+ .end((err, res) => {
434
+ if (log) {
435
+ console.log("res.body", res.body);
436
+ }
437
+ res.should.have.status(200);
438
+ res.body.should.be.a('object');
439
+ expect(res.body.name).to.equal("testbot");
440
+ var id_faq_kb = res.body._id;
441
+
442
+
443
+ chai.request(server)
444
+ //.get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
445
+ .get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb + "&page=0&limit=25&text=looking")
446
+ .auth(email, pwd)
447
+ .end((err, res) => {
448
+ if (log) {
449
+ console.log("found these faqs: \n", res.body);
450
+ }
451
+ res.should.have.status(200);
452
+ res.body.should.be.an('array');
453
+
454
+
455
+ done();
456
+
457
+ })
458
+ })
459
+ })
460
+ })
461
+ });
462
+
463
+
464
+ });
425
465
 
426
466
  });
427
467
 
@@ -147,7 +147,7 @@ describe('FaqKBRoute', () => {
147
147
  let id_faq_kb = res.body._id;
148
148
 
149
149
  chai.request(server)
150
- .post('/' + currentProject._id + '/faq_kb/fork/' + id_faq_kb + "?public=false&name=privateBotForked&projectid=" + landingProject._id)
150
+ .post('/' + currentProject._id + '/faq_kb/fork/' + id_faq_kb + "?public=false&projectid=" + landingProject._id)
151
151
  .auth(email, pwd)
152
152
  .set('Content-Type', 'application/json')
153
153
  .end((err, res) => {
@@ -180,6 +180,9 @@ describe('FaqKBRoute', () => {
180
180
  projectService.create("current-project", user1._id).then(function (currentProject) {
181
181
  projectService.create("landing-project", user2._id).then(function (landingProject) {
182
182
 
183
+ console.log("\n[TEST]")
184
+ console.log("mock: ", chatbot_mock.existing_chatbot_mock);
185
+
183
186
  class chatbot_service {
184
187
  async getBotById(id, published, api_url, chatbot_templates_api_url, token, project_id) {
185
188
  return chatbot_mock.existing_chatbot_mock;