@tiledesk/tiledesk-server 2.3.53 → 2.3.55
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 +13 -3
- package/app.js +3 -0
- package/models/department.js +1 -1
- package/package.json +2 -2
- package/pubmodules/trigger/rulesTrigger.js +98 -1
- package/routes/department.js +1 -1
- package/routes/faq.js +1 -1
- package/routes/faq_kb.js +141 -39
- package/routes/request.js +1 -1
- package/services/chatbotService.js +101 -0
- package/test/chatbot-mock.js +127 -0
- package/test/example-json.txt +1 -1
- package/test/faqkbRoute.js +369 -47
- package/utils/sendEmailUtil.js +34 -0
package/test/faqkbRoute.js
CHANGED
|
@@ -6,6 +6,8 @@ var projectService = require('../services/projectService');
|
|
|
6
6
|
var userService = require('../services/userService');
|
|
7
7
|
var faqService = require('../services/faqService');
|
|
8
8
|
|
|
9
|
+
let chatbot_mock = require('./chatbot-mock');
|
|
10
|
+
let log = false;
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
//Require the dev-dependencies
|
|
@@ -43,8 +45,9 @@ describe('FaqKBRoute', () => {
|
|
|
43
45
|
.auth(email, pwd)
|
|
44
46
|
.send({ "name": "testbot", type: "external", language: 'fr' })
|
|
45
47
|
.end((err, res) => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
if (log) {
|
|
49
|
+
console.log("res.body", res.body);
|
|
50
|
+
}
|
|
48
51
|
res.should.have.status(200);
|
|
49
52
|
res.body.should.be.a('object');
|
|
50
53
|
expect(res.body.name).to.equal("testbot");
|
|
@@ -64,55 +67,241 @@ describe('FaqKBRoute', () => {
|
|
|
64
67
|
|
|
65
68
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
66
69
|
var pwd = "pwd";
|
|
67
|
-
|
|
70
|
+
|
|
68
71
|
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
|
69
72
|
projectService.create("test-faqkb-create", savedUser._id).then((savedProject) => {
|
|
70
|
-
|
|
73
|
+
|
|
71
74
|
chai.request(server)
|
|
72
|
-
.post('/'+ savedProject._id + '/faq_kb')
|
|
75
|
+
.post('/' + savedProject._id + '/faq_kb')
|
|
73
76
|
.auth(email, pwd)
|
|
74
|
-
.send({"name":"testbot", type: "internal", template: "example" })
|
|
77
|
+
.send({ "name": "testbot", type: "internal", template: "example" })
|
|
75
78
|
.end((err, res) => {
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
if (log) {
|
|
80
|
+
console.log("res.body", res.body);
|
|
81
|
+
}
|
|
78
82
|
res.should.have.status(200);
|
|
79
83
|
res.body.should.be.a('object');
|
|
80
|
-
expect(res.body.name).to.equal("testbot");
|
|
84
|
+
expect(res.body.name).to.equal("testbot");
|
|
81
85
|
var id_faq_kb = res.body._id;
|
|
82
|
-
|
|
86
|
+
|
|
83
87
|
chai.request(server)
|
|
84
88
|
.get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
|
|
85
89
|
.auth(email, pwd)
|
|
86
90
|
.end((err, res) => {
|
|
87
|
-
|
|
91
|
+
if (log) {
|
|
92
|
+
console.log("faq_list: ", res.body);
|
|
93
|
+
}
|
|
88
94
|
res.should.have.status(200);
|
|
89
95
|
res.body.should.be.an('array').that.is.not.empty;
|
|
90
|
-
|
|
96
|
+
|
|
91
97
|
done();
|
|
92
|
-
|
|
98
|
+
|
|
93
99
|
})
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
97
103
|
});
|
|
98
104
|
})
|
|
99
105
|
})
|
|
100
106
|
})
|
|
101
107
|
|
|
102
|
-
|
|
108
|
+
|
|
109
|
+
it('fork chatbot (private)', (done) => {
|
|
110
|
+
|
|
111
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
|
112
|
+
var pwd = "pwd";
|
|
113
|
+
|
|
114
|
+
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
115
|
+
projectService.create("current-project", savedUser._id).then(function (currentProject) {
|
|
116
|
+
projectService.create("landing-project", savedUser._id).then(function (landingProject) {
|
|
117
|
+
|
|
118
|
+
class chatbot_service {
|
|
119
|
+
async getBotById(id, published, api_url, chatbot_templates_api_url, token, project_id) {
|
|
120
|
+
return chatbot_mock.existing_chatbot_mock;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async createBot(api_url, token, chatbot, project_id) {
|
|
124
|
+
return chatbot_mock.empty_chatbot_mock
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async importFaqs(api_url, id_faq_kb, token, chatbot, project_id) {
|
|
128
|
+
return chatbot_mock.import_faqs_res_mock
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
server.set('chatbot_service', new chatbot_service());
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
chai.request(server)
|
|
136
|
+
.post('/' + currentProject._id + '/faq_kb')
|
|
137
|
+
.auth(email, pwd)
|
|
138
|
+
.send({ "name": "privateBot", type: "internal", language: 'en', public: "false", template: "blank" })
|
|
139
|
+
.end((err, res) => {
|
|
140
|
+
if (log) {
|
|
141
|
+
console.log("res.body: ", res.body);
|
|
142
|
+
}
|
|
143
|
+
res.should.have.status(200);
|
|
144
|
+
res.body.should.be.a('object');
|
|
145
|
+
expect(res.body.name).to.equal("privateBot");
|
|
146
|
+
expect(res.body.language).to.equal("en");
|
|
147
|
+
let id_faq_kb = res.body._id;
|
|
148
|
+
|
|
149
|
+
chai.request(server)
|
|
150
|
+
.post('/' + currentProject._id + '/faq_kb/fork/' + id_faq_kb + "?public=false&name=privateBotForked&projectid=" + landingProject._id)
|
|
151
|
+
.auth(email, pwd)
|
|
152
|
+
.set('Content-Type', 'application/json')
|
|
153
|
+
.end((err, res) => {
|
|
154
|
+
if (log) {
|
|
155
|
+
console.log("fork private chatbot res.body: ", res.body)
|
|
156
|
+
}
|
|
157
|
+
res.should.have.status(200);
|
|
158
|
+
res.should.have.be.a('object');
|
|
159
|
+
expect(res.body.bot_id).to.equal(chatbot_mock.empty_chatbot_mock._id)
|
|
160
|
+
|
|
161
|
+
done();
|
|
162
|
+
|
|
163
|
+
})
|
|
164
|
+
})
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
it('fork chatbot (public)', (done) => {
|
|
174
|
+
var email_user1 = "user1-signup-" + Date.now() + "@email.com";
|
|
175
|
+
var email_user2 = "user2-signup-" + Date.now() + "@email.com";
|
|
176
|
+
var pwd = "pwd";
|
|
177
|
+
|
|
178
|
+
userService.signup(email_user1, pwd, "User1 Firstname", "User1 lastname").then(function (user1) {
|
|
179
|
+
userService.signup(email_user2, pwd, "User2 Firstname", "User2 lastname").then(function (user2) {
|
|
180
|
+
projectService.create("current-project", user1._id).then(function (currentProject) {
|
|
181
|
+
projectService.create("landing-project", user2._id).then(function (landingProject) {
|
|
182
|
+
|
|
183
|
+
class chatbot_service {
|
|
184
|
+
async getBotById(id, published, api_url, chatbot_templates_api_url, token, project_id) {
|
|
185
|
+
return chatbot_mock.existing_chatbot_mock;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async createBot(api_url, token, chatbot, project_id) {
|
|
189
|
+
return chatbot_mock.empty_chatbot_mock
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async importFaqs(api_url, id_faq_kb, token, chatbot, project_id) {
|
|
193
|
+
return chatbot_mock.import_faqs_res_mock
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
server.set('chatbot_service', new chatbot_service());
|
|
198
|
+
|
|
199
|
+
chai.request(server)
|
|
200
|
+
.post('/' + currentProject._id + '/faq_kb')
|
|
201
|
+
.auth(email_user1, pwd)
|
|
202
|
+
.send({ "name": "publicBot", type: "internal", language: 'en', public: "true", template: "blank" })
|
|
203
|
+
.end((err, res) => {
|
|
204
|
+
if (log) {
|
|
205
|
+
console.log("res.body: ", res.body);
|
|
206
|
+
}
|
|
207
|
+
res.should.have.status(200);
|
|
208
|
+
res.body.should.be.a('object');
|
|
209
|
+
expect(res.body.name).to.equal("publicBot");
|
|
210
|
+
expect(res.body.language).to.equal("en");
|
|
211
|
+
let id_faq_kb = res.body._id;
|
|
212
|
+
|
|
213
|
+
chai.request(server)
|
|
214
|
+
.post('/' + landingProject._id + '/faq_kb/fork/' + id_faq_kb + '?public=true&projectid=' + landingProject._id)
|
|
215
|
+
.auth(email_user2, pwd)
|
|
216
|
+
.set('Content-Type', 'application/json')
|
|
217
|
+
.end((err, res) => {
|
|
218
|
+
if (log) {
|
|
219
|
+
console.log("fork public chatbot res.body: ", res.body)
|
|
220
|
+
}
|
|
221
|
+
res.should.have.status(200);
|
|
222
|
+
|
|
223
|
+
done();
|
|
224
|
+
})
|
|
225
|
+
})
|
|
226
|
+
})
|
|
227
|
+
})
|
|
228
|
+
})
|
|
229
|
+
})
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
it('import json (overwrite true)', (done) => {
|
|
103
234
|
|
|
104
235
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
105
236
|
var pwd = "pwd";
|
|
106
237
|
|
|
107
238
|
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
108
239
|
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
109
|
-
|
|
240
|
+
|
|
110
241
|
chai.request(server)
|
|
111
242
|
.post('/' + savedProject._id + '/faq_kb')
|
|
112
243
|
.auth(email, pwd)
|
|
113
|
-
.send({ "name": "testbot", type: "internal", language: 'fr' })
|
|
244
|
+
.send({ "name": "testbot", type: "internal", language: 'fr', template: "blank" })
|
|
245
|
+
.end((err, res) => {
|
|
246
|
+
if (log) {
|
|
247
|
+
console.log("res.body: ", res.body);
|
|
248
|
+
}
|
|
249
|
+
res.should.have.status(200);
|
|
250
|
+
res.body.should.be.a('object');
|
|
251
|
+
expect(res.body.name).to.equal("testbot");
|
|
252
|
+
expect(res.body.language).to.equal("fr");
|
|
253
|
+
let id_faq_kb = res.body._id;
|
|
254
|
+
|
|
255
|
+
chai.request(server)
|
|
256
|
+
.post('/' + savedProject._id + '/faq_kb/importjson/' + id_faq_kb + "?overwrite=true")
|
|
257
|
+
.auth(email, pwd)
|
|
258
|
+
.set('Content-Type', 'text/plain')
|
|
259
|
+
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-json.txt')), 'example-json.txt')
|
|
260
|
+
.end((err, res) => {
|
|
261
|
+
if (log) {
|
|
262
|
+
console.log("import json res: ", res.body);
|
|
263
|
+
}
|
|
264
|
+
res.should.have.status(200);
|
|
265
|
+
res.should.be.a('object');
|
|
266
|
+
expect(res.body.name).to.equal("examplebot");
|
|
267
|
+
expect(res.body.language).to.equal("en");
|
|
268
|
+
|
|
269
|
+
chai.request(server)
|
|
270
|
+
.get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
|
|
271
|
+
.auth(email, pwd)
|
|
272
|
+
.end((err, res) => {
|
|
273
|
+
if (log) {
|
|
274
|
+
console.log("faq_list: ", res.body);
|
|
275
|
+
}
|
|
276
|
+
res.should.have.status(200);
|
|
277
|
+
res.body.should.be.an('array').that.is.not.empty;
|
|
278
|
+
|
|
279
|
+
done();
|
|
280
|
+
|
|
281
|
+
})
|
|
282
|
+
})
|
|
283
|
+
})
|
|
284
|
+
})
|
|
285
|
+
})
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
it('import json (overwrite false)', (done) => {
|
|
290
|
+
|
|
291
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
|
292
|
+
var pwd = "pwd";
|
|
293
|
+
|
|
294
|
+
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
295
|
+
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
296
|
+
|
|
297
|
+
chai.request(server)
|
|
298
|
+
.post('/' + savedProject._id + '/faq_kb')
|
|
299
|
+
.auth(email, pwd)
|
|
300
|
+
.send({ "name": "testbot", type: "internal", language: 'fr', template: "blank" })
|
|
114
301
|
.end((err, res) => {
|
|
115
|
-
|
|
302
|
+
if (log) {
|
|
303
|
+
console.log("res.body: ", res.body);
|
|
304
|
+
}
|
|
116
305
|
res.should.have.status(200);
|
|
117
306
|
res.body.should.be.a('object');
|
|
118
307
|
expect(res.body.name).to.equal("testbot");
|
|
@@ -123,9 +312,11 @@ describe('FaqKBRoute', () => {
|
|
|
123
312
|
.post('/' + savedProject._id + '/faq_kb/importjson/' + id_faq_kb)
|
|
124
313
|
.auth(email, pwd)
|
|
125
314
|
.set('Content-Type', 'text/plain')
|
|
126
|
-
.attach('uploadFile',
|
|
315
|
+
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-json.txt')), 'example-json.txt')
|
|
127
316
|
.end((err, res) => {
|
|
128
|
-
|
|
317
|
+
if (log) {
|
|
318
|
+
console.log("import json res: ", res.body);
|
|
319
|
+
}
|
|
129
320
|
res.should.have.status(200);
|
|
130
321
|
res.should.be.a('object');
|
|
131
322
|
expect(res.body.name).to.equal("examplebot");
|
|
@@ -135,12 +326,14 @@ describe('FaqKBRoute', () => {
|
|
|
135
326
|
.get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
|
|
136
327
|
.auth(email, pwd)
|
|
137
328
|
.end((err, res) => {
|
|
138
|
-
|
|
329
|
+
if (log) {
|
|
330
|
+
console.log("faq_list: ", res.body);
|
|
331
|
+
}
|
|
139
332
|
res.should.have.status(200);
|
|
140
333
|
res.body.should.be.an('array').that.is.not.empty;
|
|
141
|
-
|
|
334
|
+
|
|
142
335
|
done();
|
|
143
|
-
|
|
336
|
+
|
|
144
337
|
})
|
|
145
338
|
})
|
|
146
339
|
})
|
|
@@ -148,20 +341,132 @@ describe('FaqKBRoute', () => {
|
|
|
148
341
|
})
|
|
149
342
|
})
|
|
150
343
|
|
|
151
|
-
it('import json (
|
|
344
|
+
it('import json (simple)', (done) => {
|
|
152
345
|
|
|
153
346
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
154
347
|
var pwd = "pwd";
|
|
155
348
|
|
|
156
349
|
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
157
350
|
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
158
|
-
|
|
351
|
+
|
|
159
352
|
chai.request(server)
|
|
160
353
|
.post('/' + savedProject._id + '/faq_kb')
|
|
161
354
|
.auth(email, pwd)
|
|
162
355
|
.send({ "name": "testbot", type: "internal", language: 'fr' })
|
|
163
356
|
.end((err, res) => {
|
|
164
|
-
|
|
357
|
+
if (log) {
|
|
358
|
+
console.log("res.body: ", res.body);
|
|
359
|
+
}
|
|
360
|
+
res.should.have.status(200);
|
|
361
|
+
res.body.should.be.a('object');
|
|
362
|
+
expect(res.body.name).to.equal("testbot");
|
|
363
|
+
expect(res.body.language).to.equal("fr");
|
|
364
|
+
let id_faq_kb = res.body._id;
|
|
365
|
+
|
|
366
|
+
chai.request(server)
|
|
367
|
+
.post('/' + savedProject._id + '/faq_kb/importjson/' + id_faq_kb + '?intentsOnly=true&overwrite=true')
|
|
368
|
+
.auth(email, pwd)
|
|
369
|
+
.set('Content-Type', 'text/plain')
|
|
370
|
+
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-json-intents.txt')), 'example-json-intents.txt')
|
|
371
|
+
.end((err, res) => {
|
|
372
|
+
if (log) {
|
|
373
|
+
console.log("import (intents only) json res: ", res.body);
|
|
374
|
+
}
|
|
375
|
+
res.should.have.status(200);
|
|
376
|
+
//res.should.be.a('object');
|
|
377
|
+
//expect(res.body.success).to.equal(true);
|
|
378
|
+
|
|
379
|
+
chai.request(server)
|
|
380
|
+
.get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
|
|
381
|
+
.auth(email, pwd)
|
|
382
|
+
.end((err, res) => {
|
|
383
|
+
if (log) {
|
|
384
|
+
console.log("faq_list: ", res.body);
|
|
385
|
+
}
|
|
386
|
+
res.should.have.status(200);
|
|
387
|
+
res.body.should.be.an('array').that.is.not.empty;
|
|
388
|
+
|
|
389
|
+
done();
|
|
390
|
+
|
|
391
|
+
})
|
|
392
|
+
})
|
|
393
|
+
})
|
|
394
|
+
})
|
|
395
|
+
})
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
it('import json (intents only) (overwrite true)', (done) => {
|
|
400
|
+
|
|
401
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
|
402
|
+
var pwd = "pwd";
|
|
403
|
+
|
|
404
|
+
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
405
|
+
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
406
|
+
|
|
407
|
+
chai.request(server)
|
|
408
|
+
.post('/' + savedProject._id + '/faq_kb')
|
|
409
|
+
.auth(email, pwd)
|
|
410
|
+
.send({ "name": "testbot", type: "internal", language: 'fr', template: 'blank' })
|
|
411
|
+
.end((err, res) => {
|
|
412
|
+
if (log) {
|
|
413
|
+
console.log("res.body: ", res.body);
|
|
414
|
+
}
|
|
415
|
+
res.should.have.status(200);
|
|
416
|
+
res.body.should.be.a('object');
|
|
417
|
+
expect(res.body.name).to.equal("testbot");
|
|
418
|
+
expect(res.body.language).to.equal("fr");
|
|
419
|
+
let id_faq_kb = res.body._id;
|
|
420
|
+
|
|
421
|
+
chai.request(server)
|
|
422
|
+
.post('/' + savedProject._id + '/faq_kb/importjson/' + id_faq_kb + '?intentsOnly=true&overwrite=true')
|
|
423
|
+
.auth(email, pwd)
|
|
424
|
+
.set('Content-Type', 'text/plain')
|
|
425
|
+
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-json-intents.txt')), 'example-json-intents.txt')
|
|
426
|
+
.end((err, res) => {
|
|
427
|
+
if (log) {
|
|
428
|
+
console.log("import (intents only) json res: ", res.body);
|
|
429
|
+
}
|
|
430
|
+
res.should.have.status(200);
|
|
431
|
+
//res.should.be.a('object');
|
|
432
|
+
//expect(res.body.success).to.equal(true);
|
|
433
|
+
|
|
434
|
+
chai.request(server)
|
|
435
|
+
.get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
|
|
436
|
+
.auth(email, pwd)
|
|
437
|
+
.end((err, res) => {
|
|
438
|
+
if (log) {
|
|
439
|
+
console.log("faq_list: ", res.body);
|
|
440
|
+
}
|
|
441
|
+
res.should.have.status(200);
|
|
442
|
+
res.body.should.be.an('array').that.is.not.empty;
|
|
443
|
+
|
|
444
|
+
done();
|
|
445
|
+
|
|
446
|
+
})
|
|
447
|
+
})
|
|
448
|
+
})
|
|
449
|
+
})
|
|
450
|
+
})
|
|
451
|
+
})
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
it('import json (intents only) (overwrite false)', (done) => {
|
|
455
|
+
|
|
456
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
|
457
|
+
var pwd = "pwd";
|
|
458
|
+
|
|
459
|
+
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
460
|
+
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
461
|
+
|
|
462
|
+
chai.request(server)
|
|
463
|
+
.post('/' + savedProject._id + '/faq_kb')
|
|
464
|
+
.auth(email, pwd)
|
|
465
|
+
.send({ "name": "testbot", type: "internal", language: 'fr', template: 'blank' })
|
|
466
|
+
.end((err, res) => {
|
|
467
|
+
if (log) {
|
|
468
|
+
console.log("res.body: ", res.body);
|
|
469
|
+
}
|
|
165
470
|
res.should.have.status(200);
|
|
166
471
|
res.body.should.be.a('object');
|
|
167
472
|
expect(res.body.name).to.equal("testbot");
|
|
@@ -172,9 +477,11 @@ describe('FaqKBRoute', () => {
|
|
|
172
477
|
.post('/' + savedProject._id + '/faq_kb/importjson/' + id_faq_kb + '?intentsOnly=true')
|
|
173
478
|
.auth(email, pwd)
|
|
174
479
|
.set('Content-Type', 'text/plain')
|
|
175
|
-
.attach('uploadFile',
|
|
480
|
+
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-json-intents.txt')), 'example-json-intents.txt')
|
|
176
481
|
.end((err, res) => {
|
|
177
|
-
|
|
482
|
+
if (log) {
|
|
483
|
+
console.log("import (intents only) json res: ", res.body);
|
|
484
|
+
}
|
|
178
485
|
res.should.have.status(200);
|
|
179
486
|
//res.should.be.a('object');
|
|
180
487
|
//expect(res.body.success).to.equal(true);
|
|
@@ -183,12 +490,14 @@ describe('FaqKBRoute', () => {
|
|
|
183
490
|
.get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
|
|
184
491
|
.auth(email, pwd)
|
|
185
492
|
.end((err, res) => {
|
|
186
|
-
|
|
493
|
+
if (log) {
|
|
494
|
+
console.log("faq_list: ", res.body);
|
|
495
|
+
}
|
|
187
496
|
res.should.have.status(200);
|
|
188
497
|
res.body.should.be.an('array').that.is.not.empty;
|
|
189
|
-
|
|
498
|
+
|
|
190
499
|
done();
|
|
191
|
-
|
|
500
|
+
|
|
192
501
|
})
|
|
193
502
|
})
|
|
194
503
|
})
|
|
@@ -207,26 +516,31 @@ describe('FaqKBRoute', () => {
|
|
|
207
516
|
|
|
208
517
|
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
209
518
|
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
210
|
-
|
|
519
|
+
|
|
211
520
|
chai.request(server)
|
|
212
521
|
.post('/' + savedProject._id + '/faq_kb')
|
|
213
522
|
.auth(email, pwd)
|
|
214
523
|
.send({ "name": "testbot", type: "internal", template: "example", language: 'fr' })
|
|
215
524
|
.end((err, res) => {
|
|
216
|
-
|
|
217
|
-
|
|
525
|
+
if (log) {
|
|
526
|
+
console.log("res.body: ", res.body);
|
|
527
|
+
}
|
|
218
528
|
res.should.have.status(200);
|
|
219
529
|
res.body.should.be.a('object');
|
|
220
530
|
expect(res.body.name).to.equal("testbot");
|
|
221
531
|
expect(res.body.language).to.equal("fr");
|
|
222
532
|
let id_faq_kb = res.body._id;
|
|
223
|
-
|
|
533
|
+
if (log) {
|
|
534
|
+
console.log("res.body._id: ", res.body._id)
|
|
535
|
+
}
|
|
224
536
|
|
|
225
537
|
chai.request(server)
|
|
226
538
|
.get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
|
|
227
539
|
.auth(email, pwd)
|
|
228
540
|
.end((err, res) => {
|
|
229
|
-
|
|
541
|
+
if (log) {
|
|
542
|
+
console.log("faq_list: ", res.body);
|
|
543
|
+
}
|
|
230
544
|
res.should.have.status(200);
|
|
231
545
|
res.body.should.be.an('array').that.is.not.empty;
|
|
232
546
|
|
|
@@ -234,7 +548,9 @@ describe('FaqKBRoute', () => {
|
|
|
234
548
|
.get('/' + savedProject._id + '/faq_kb/exportjson/' + id_faq_kb)
|
|
235
549
|
.auth(email, pwd)
|
|
236
550
|
.end((err, res) => {
|
|
237
|
-
|
|
551
|
+
if (log) {
|
|
552
|
+
console.log("export json res: ", res.body);
|
|
553
|
+
}
|
|
238
554
|
res.should.have.status(200);
|
|
239
555
|
//res.body.should.be.a('string');
|
|
240
556
|
|
|
@@ -247,6 +563,7 @@ describe('FaqKBRoute', () => {
|
|
|
247
563
|
|
|
248
564
|
}).timeout(20000);
|
|
249
565
|
|
|
566
|
+
|
|
250
567
|
it('export json (intents only)', (done) => {
|
|
251
568
|
|
|
252
569
|
|
|
@@ -257,26 +574,32 @@ describe('FaqKBRoute', () => {
|
|
|
257
574
|
|
|
258
575
|
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
259
576
|
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
260
|
-
|
|
577
|
+
|
|
261
578
|
chai.request(server)
|
|
262
579
|
.post('/' + savedProject._id + '/faq_kb')
|
|
263
580
|
.auth(email, pwd)
|
|
264
581
|
.send({ "name": "testbot", type: "internal", template: "example", language: 'fr' })
|
|
265
582
|
.end((err, res) => {
|
|
266
583
|
//console.log("res", res);
|
|
267
|
-
|
|
584
|
+
if (log) {
|
|
585
|
+
console.log("res.body: ", res.body);
|
|
586
|
+
}
|
|
268
587
|
res.should.have.status(200);
|
|
269
588
|
res.body.should.be.a('object');
|
|
270
589
|
expect(res.body.name).to.equal("testbot");
|
|
271
590
|
expect(res.body.language).to.equal("fr");
|
|
272
591
|
let id_faq_kb = res.body._id;
|
|
273
|
-
|
|
592
|
+
if (log) {
|
|
593
|
+
console.log("res.body._id: ", res.body._id)
|
|
594
|
+
}
|
|
274
595
|
|
|
275
596
|
chai.request(server)
|
|
276
597
|
.get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
|
|
277
598
|
.auth(email, pwd)
|
|
278
599
|
.end((err, res) => {
|
|
279
|
-
|
|
600
|
+
if (log) {
|
|
601
|
+
console.log("faq_list: ", res.body);
|
|
602
|
+
}
|
|
280
603
|
res.should.have.status(200);
|
|
281
604
|
res.body.should.be.an('array').that.is.not.empty;
|
|
282
605
|
|
|
@@ -284,7 +607,9 @@ describe('FaqKBRoute', () => {
|
|
|
284
607
|
.get('/' + savedProject._id + '/faq_kb/exportjson/' + id_faq_kb + "?intentsOnly=true")
|
|
285
608
|
.auth(email, pwd)
|
|
286
609
|
.end((err, res) => {
|
|
287
|
-
|
|
610
|
+
if (log) {
|
|
611
|
+
console.log("export json res: ", res.body);
|
|
612
|
+
}
|
|
288
613
|
res.should.have.status(200);
|
|
289
614
|
//res.body.should.be.a('string');
|
|
290
615
|
|
|
@@ -351,9 +676,6 @@ describe('FaqKBRoute', () => {
|
|
|
351
676
|
}).timeout(20000);
|
|
352
677
|
|
|
353
678
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
679
|
});
|
|
358
680
|
|
|
359
681
|
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var winston = require('../config/winston');
|
|
2
|
+
const emailService = require("../services/emailService");
|
|
3
|
+
const Project = require("../models/project");
|
|
4
|
+
var handlebars = require('handlebars');
|
|
5
|
+
|
|
6
|
+
class SendEmailUtil {
|
|
7
|
+
async sendEmailDirect(to, text, id_project, recipient, subject, message) {
|
|
8
|
+
|
|
9
|
+
let project = await Project.findById(id_project);
|
|
10
|
+
winston.debug("project", project);
|
|
11
|
+
|
|
12
|
+
winston.debug("text: " + text);
|
|
13
|
+
winston.debug("recipient:"+ recipient);
|
|
14
|
+
winston.debug("to:" + to);
|
|
15
|
+
|
|
16
|
+
var template = handlebars.compile(text);
|
|
17
|
+
|
|
18
|
+
var replacements = {
|
|
19
|
+
message: message,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
var finaltext = template(replacements);
|
|
23
|
+
winston.debug("finaltext:" + finaltext);
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// sendEmailDirect(to, text, project, request_id, subject, tokenQueryString, sourcePage) {
|
|
27
|
+
emailService.sendEmailDirect(to, finaltext, project, recipient, subject, undefined, undefined);
|
|
28
|
+
// emailService.sendEmailDirect(to, text, project, recipient, subject, undefined, undefined);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var sendEmailUtil = new SendEmailUtil();
|
|
33
|
+
|
|
34
|
+
module.exports = sendEmailUtil;
|