@tiledesk/tiledesk-server 2.10.64 → 2.10.66
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 +6 -0
- package/package.json +1 -1
- package/routes/user-request.js +7 -5
- package/services/QuoteManager.js +40 -16
- package/test/userRequestRoute.js +125 -0
package/CHANGELOG.md
CHANGED
@@ -5,6 +5,12 @@
|
|
5
5
|
🚀 IN PRODUCTION 🚀
|
6
6
|
(https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
|
7
7
|
|
8
|
+
# 2.10.66
|
9
|
+
- Updated QuoteService with new plans
|
10
|
+
|
11
|
+
# 2.10.65
|
12
|
+
- fix issue con /rating called by chatbot
|
13
|
+
|
8
14
|
# 2.10.64
|
9
15
|
- updated tybot-connector to 0.3.4
|
10
16
|
- updated whatsapp-connector to 0.1.81
|
package/package.json
CHANGED
package/routes/user-request.js
CHANGED
@@ -12,7 +12,6 @@ router.patch('/:requestid/rating', function (req, res) {
|
|
12
12
|
winston.debug(req.body);
|
13
13
|
const update = {};
|
14
14
|
|
15
|
-
|
16
15
|
if (req.body.rating) {
|
17
16
|
update.rating = req.body.rating;
|
18
17
|
}
|
@@ -20,13 +19,16 @@ router.patch('/:requestid/rating', function (req, res) {
|
|
20
19
|
if (req.body.rating_message) {
|
21
20
|
update.rating_message = req.body.rating_message;
|
22
21
|
}
|
23
|
-
|
24
|
-
|
25
22
|
|
26
23
|
winston.debug("Request user patch update",update);
|
27
24
|
|
28
|
-
|
29
|
-
|
25
|
+
let query = {
|
26
|
+
request_id: req.params.requestid
|
27
|
+
}
|
28
|
+
|
29
|
+
if (req.projectuser) {
|
30
|
+
query.requester = req.projectuser.id
|
31
|
+
}
|
30
32
|
|
31
33
|
//cacheinvalidation
|
32
34
|
return Request.findOneAndUpdate(query, { $set: update }, { new: true, upsert: false })
|
package/services/QuoteManager.js
CHANGED
@@ -14,16 +14,23 @@ const emailEvent = require('../event/emailEvent');
|
|
14
14
|
// CUSTOM: { requests: 3000, messages: 0, tokens: 5000000, email: 200, chatbots: 20, kbs: 500}
|
15
15
|
// }
|
16
16
|
|
17
|
-
|
18
17
|
const PLANS_LIST = {
|
19
|
-
FREE_TRIAL: { requests: 200, messages: 0, tokens: 100000, voice_duration: 0, email: 200, chatbots: 20, namespace: 3, kbs: 50 }, // same as PREMIUM
|
20
|
-
SANDBOX: { requests: 200, messages: 0, tokens: 100000, voice_duration: 0,
|
21
|
-
BASIC: { requests: 800, messages: 0, tokens: 2000000, voice_duration: 0,
|
22
|
-
PREMIUM: { requests: 3000, messages: 0, tokens: 5000000, voice_duration: 0,
|
23
|
-
TEAM: { requests: 5000, messages: 0, tokens: 10000000, voice_duration: 0,
|
24
|
-
CUSTOM: { requests: 5000, messages: 0, tokens: 10000000, voice_duration: 120000, email: 200, chatbots: 50, namespace: 10, kbs: 1000 },
|
18
|
+
//FREE_TRIAL: { requests: 200, messages: 0, tokens: 100000, voice_duration: 0, email: 200, chatbots: 20, namespace: 3, kbs: 50 }, // same as PREMIUM
|
19
|
+
SANDBOX: { requests: 200, messages: 0, tokens: 100000, voice_duration: 0, email: 200, chatbots: 2, namespace: 1, kbs: 50 },
|
20
|
+
BASIC: { requests: 800, messages: 0, tokens: 2000000, voice_duration: 0, email: 200, chatbots: 5, namespace: 1, kbs: 150 },
|
21
|
+
PREMIUM: { requests: 3000, messages: 0, tokens: 5000000, voice_duration: 0, email: 200, chatbots: 20, namespace: 3, kbs: 300 },
|
22
|
+
TEAM: { requests: 5000, messages: 0, tokens: 10000000, voice_duration: 0, email: 200, chatbots: 50, namespace: 10, kbs: 1000 },
|
23
|
+
//CUSTOM: { requests: 5000, messages: 0, tokens: 10000000, voice_duration: 120000, email: 200, chatbots: 50, namespace: 10, kbs: 1000 },
|
24
|
+
// FROM MARCH 2025
|
25
|
+
FREE_TRIAL: { requests: 3000, messages: 0, tokens: 5000000, voice_duration: 120000, email: 200, chatbots: 5, namespace: 1, kbs: 50 }, // same as PRO
|
26
|
+
STARTER: { requests: 800, messages: 0, tokens: 2000000, voice_duration: 0, email: 200, chatbots: 5, namespace: 1, kbs: 150 },
|
27
|
+
PRO: { requests: 3000, messages: 0, tokens: 5000000, voice_duration: 0, email: 200, chatbots: 20, namespace: 3, kbs: 300 },
|
28
|
+
BUSINESS: { requests: 5000, messages: 0, tokens: 10000000, voice_duration: 0, email: 200, chatbots: 50, namespace: 10, kbs: 1000 },
|
29
|
+
CUSTOM: { requests: 5000, messages: 0, tokens: 10000000, voice_duration: 120000, email: 200, chatbots: 50, namespace: 10, kbs: 1000 }
|
25
30
|
}
|
26
31
|
|
32
|
+
|
33
|
+
|
27
34
|
const typesList = ['requests', 'messages', 'email', 'tokens', 'voice_duration', 'chatbots', 'kbs']
|
28
35
|
|
29
36
|
let quotes_enabled = true;
|
@@ -88,7 +95,7 @@ class QuoteManager {
|
|
88
95
|
winston.debug("QUOTES DISABLED - incrementTokenCount")
|
89
96
|
return key;
|
90
97
|
}
|
91
|
-
|
98
|
+
|
92
99
|
let tokens = data.tokens * data.multiplier;
|
93
100
|
await this.tdCache.incrbyfloat(key, tokens);
|
94
101
|
// await this.tdCache.incrby(key, tokens);
|
@@ -110,7 +117,7 @@ class QuoteManager {
|
|
110
117
|
if (request?.duration) {
|
111
118
|
let duration = Math.round(request.duration / 1000); // from ms to s
|
112
119
|
await this.tdCache.incrby(key, duration);
|
113
|
-
|
120
|
+
|
114
121
|
this.sendEmailIfQuotaExceeded(project, request, 'voice_duration', key);
|
115
122
|
}
|
116
123
|
}
|
@@ -261,7 +268,7 @@ class QuoteManager {
|
|
261
268
|
}
|
262
269
|
|
263
270
|
async checkQuoteForAlert(project, object, type) {
|
264
|
-
|
271
|
+
|
265
272
|
if (quotes_enabled === false) {
|
266
273
|
winston.verbose("QUOTES DISABLED - checkQuote for type " + type);
|
267
274
|
return (null, null);
|
@@ -283,7 +290,7 @@ class QuoteManager {
|
|
283
290
|
}
|
284
291
|
|
285
292
|
async sendEmailIfQuotaExceeded(project, object, type, key) {
|
286
|
-
|
293
|
+
|
287
294
|
let data = await this.checkQuoteForAlert(project, object, type);
|
288
295
|
let limits = data.limits;
|
289
296
|
let limit = data.limits[type];
|
@@ -312,7 +319,7 @@ class QuoteManager {
|
|
312
319
|
}
|
313
320
|
|
314
321
|
emailEvent.emit('email.send.quote.checkpoint', data);
|
315
|
-
await this.tdCache.set(nKey, 'true', {EX: 2592000}); //seconds in one month = 2592000
|
322
|
+
await this.tdCache.set(nKey, 'true', { EX: 2592000 }); //seconds in one month = 2592000
|
316
323
|
} else {
|
317
324
|
winston.verbose("Quota checkpoint reached email already sent.")
|
318
325
|
}
|
@@ -320,7 +327,7 @@ class QuoteManager {
|
|
320
327
|
}
|
321
328
|
|
322
329
|
async percentageCalculator(limit, quote) {
|
323
|
-
|
330
|
+
|
324
331
|
let p = (quote / limit) * 100;
|
325
332
|
|
326
333
|
if (p >= 100) { return 100; }
|
@@ -339,10 +346,10 @@ class QuoteManager {
|
|
339
346
|
let requests_key = await this.generateKey(obj, 'requests');
|
340
347
|
let tokens_key = await this.generateKey(obj, 'tokens');
|
341
348
|
let email_key = await this.generateKey(obj, 'email');
|
342
|
-
|
349
|
+
|
343
350
|
let checkpoints = ['50', '75', '95', '100']
|
344
351
|
|
345
|
-
checkpoints.forEach(
|
352
|
+
checkpoints.forEach(async (checkpoint) => {
|
346
353
|
let nrequests_key = requests_key + ":notify:" + checkpoint;
|
347
354
|
let ntokens_key = tokens_key + ":notify:" + checkpoint;
|
348
355
|
let nemail_key = email_key + ":notify:" + checkpoint;
|
@@ -390,7 +397,22 @@ class QuoteManager {
|
|
390
397
|
|
391
398
|
if (this.project.profile.type === 'payment') {
|
392
399
|
|
400
|
+
if (this.project.isActiveSubscription === false) {
|
401
|
+
limits = PLANS_LIST.SANDBOX;
|
402
|
+
return limits;
|
403
|
+
|
404
|
+
}
|
405
|
+
|
393
406
|
switch (plan) {
|
407
|
+
case 'Starter':
|
408
|
+
limits = PLANS_LIST.STARTER
|
409
|
+
break;
|
410
|
+
case 'Pro':
|
411
|
+
limits = PLANS_LIST.PRO
|
412
|
+
break;
|
413
|
+
case 'Business':
|
414
|
+
limits = PLANS_LIST.BUSINESS
|
415
|
+
break;
|
394
416
|
case 'Basic':
|
395
417
|
limits = PLANS_LIST.BASIC;
|
396
418
|
break;
|
@@ -415,6 +437,7 @@ class QuoteManager {
|
|
415
437
|
default:
|
416
438
|
limits = PLANS_LIST.FREE_TRIAL;
|
417
439
|
}
|
440
|
+
|
418
441
|
} else {
|
419
442
|
|
420
443
|
if (this.project.trialExpired === false) {
|
@@ -424,6 +447,7 @@ class QuoteManager {
|
|
424
447
|
}
|
425
448
|
|
426
449
|
}
|
450
|
+
|
427
451
|
if (this.project?.profile?.quotes) {
|
428
452
|
let profile_quotes = this.project?.profile?.quotes;
|
429
453
|
const merged_quotes = Object.assign({}, limits, profile_quotes);
|
@@ -454,7 +478,7 @@ class QuoteManager {
|
|
454
478
|
winston.debug("Subscription date from project createdAt: " + subscriptionDate.toISOString());
|
455
479
|
}
|
456
480
|
}
|
457
|
-
|
481
|
+
|
458
482
|
let now = moment();
|
459
483
|
winston.debug("now: ", now);
|
460
484
|
|
@@ -0,0 +1,125 @@
|
|
1
|
+
process.env.NODE_ENV = 'test';
|
2
|
+
|
3
|
+
let chai = require('chai');
|
4
|
+
let chaiHttp = require('chai-http');
|
5
|
+
let server = require('../app');
|
6
|
+
let should = chai.should();
|
7
|
+
|
8
|
+
chai.use(chaiHttp);
|
9
|
+
|
10
|
+
var expect = require('chai').expect;
|
11
|
+
var assert = require('chai').assert;
|
12
|
+
var config = require('../config/database');
|
13
|
+
|
14
|
+
var mongoose = require('mongoose');
|
15
|
+
var winston = require('../config/winston');
|
16
|
+
|
17
|
+
let log = false;
|
18
|
+
|
19
|
+
// var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
|
20
|
+
// if (!databaseUri) {
|
21
|
+
// console.log('DATABASE_URI not specified, falling back to localhost.');
|
22
|
+
// }
|
23
|
+
|
24
|
+
// mongoose.connect(databaseUri || config.database);
|
25
|
+
mongoose.connect(config.databasetest);
|
26
|
+
|
27
|
+
var userService = require('../services/userService');
|
28
|
+
const projectService = require('../services/projectService');
|
29
|
+
var leadService = require('../services/leadService');
|
30
|
+
var requestService = require('../services/requestService');
|
31
|
+
const faqService = require('../services/faqService');
|
32
|
+
var Bot = require("../models/faq_kb");
|
33
|
+
|
34
|
+
var jwt = require('jsonwebtoken');
|
35
|
+
const uuidv4 = require('uuid/v4');
|
36
|
+
|
37
|
+
|
38
|
+
describe('UserService()', function () {
|
39
|
+
|
40
|
+
it('request-rating', function (done) {
|
41
|
+
|
42
|
+
var email = "test-UserRequest-signup-" + Date.now() + "@email.com";
|
43
|
+
var pwd = "pwd";
|
44
|
+
|
45
|
+
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
46
|
+
var userid = savedUser.id;
|
47
|
+
|
48
|
+
projectService.createAndReturnProjectAndProjectUser("createWithId", savedUser.id).then(function (savedProjectAndPU) {
|
49
|
+
var savedProject = savedProjectAndPU.project;
|
50
|
+
|
51
|
+
faqService.create("testbot", null, savedProject._id, savedUser._id, "tilebot", null, null, null, "en", "blank").then(async function (savedFaq_kb) {
|
52
|
+
|
53
|
+
var signOptions = {
|
54
|
+
issuer: 'https://tiledesk.com',
|
55
|
+
subject: 'bot',
|
56
|
+
audience: 'https://tiledesk.com/bots/' + savedFaq_kb._id,
|
57
|
+
jwtid: uuidv4()
|
58
|
+
};
|
59
|
+
|
60
|
+
let botPayload = savedFaq_kb.toObject();
|
61
|
+
let botSecret = botPayload.secret;
|
62
|
+
|
63
|
+
var bot_token = jwt.sign(botPayload, botSecret, signOptions);
|
64
|
+
|
65
|
+
leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function (createdLead) {
|
66
|
+
var now = Date.now();
|
67
|
+
var request = {
|
68
|
+
request_id: "request_id-createObjSimple-" + now, project_user_id: savedProjectAndPU.project_user._id, lead_id: createdLead._id,
|
69
|
+
id_project: savedProject._id, first_text: "first_text",
|
70
|
+
lead: createdLead, requester: savedProjectAndPU.project_user
|
71
|
+
};
|
72
|
+
|
73
|
+
requestService.create(request).then(function (savedRequest) {
|
74
|
+
|
75
|
+
chai.request(server)
|
76
|
+
.patch('/' + savedProject._id + '/requests/' + savedRequest.request_id + "/rating")
|
77
|
+
.set('Authorization', "JWT " + bot_token)
|
78
|
+
.send({ rating: 4, rating_message: "Good" })
|
79
|
+
.end((err, res) => {
|
80
|
+
|
81
|
+
if (err) { console.error("err: ", err) };
|
82
|
+
if (log) { console.log("res.body: ", res.body) };
|
83
|
+
|
84
|
+
res.should.have.status(200);
|
85
|
+
res.body.should.be.a('object');
|
86
|
+
expect(res.body.rating).to.equal(4);
|
87
|
+
expect(res.body.rating_message).to.equal('Good');
|
88
|
+
|
89
|
+
done()
|
90
|
+
});
|
91
|
+
});
|
92
|
+
});
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
});
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
// console.log("savedProject: ", savedProject)
|
101
|
+
// leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function (createdLead) {
|
102
|
+
// var now = Date.now();
|
103
|
+
// var request = {
|
104
|
+
// request_id: "request_id-createObjSimple-" + now, project_user_id: savedProjectAndPU.project_user._id, lead_id: createdLead._id,
|
105
|
+
// id_project: savedProject._id, first_text: "first_text",
|
106
|
+
// lead: createdLead, requester: savedProjectAndPU.project_user
|
107
|
+
// };
|
108
|
+
|
109
|
+
// console.log("request: ", request)
|
110
|
+
|
111
|
+
|
112
|
+
// requestService.create(request).then(function (savedRequest) {
|
113
|
+
|
114
|
+
// console.log("savedRequest: ", savedRequest);
|
115
|
+
// done();
|
116
|
+
// });
|
117
|
+
// });
|
118
|
+
});
|
119
|
+
|
120
|
+
})
|
121
|
+
|
122
|
+
|
123
|
+
}).timeout(10000);
|
124
|
+
})
|
125
|
+
|