@tiledesk/tiledesk-server 2.4.82 → 2.4.83

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,11 @@
5
5
  🚀 IN PRODUCTION 🚀
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
+ # 2.4.83
9
+ - Improved whatsapp log services
10
+ - Updated whatsapp-connector to 0.1.57
11
+ - Updated whatsapp-jobworker to 0.0.7
12
+
8
13
  # 2.4.82
9
14
  - Added whatsapp log services
10
15
 
package/app.js CHANGED
@@ -462,7 +462,7 @@ app.use('/files', files);
462
462
  app.use('/urls', urls);
463
463
  app.use('/users', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], users);
464
464
  app.use('/users_util', usersUtil);
465
- app.use('/logs', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], logs);
465
+ // app.use('/logs', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], logs);
466
466
  app.use('/requests_util', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], requestUtilRoot);
467
467
 
468
468
  // TODO security issues
@@ -562,6 +562,8 @@ app.use('/:projectid/segments',[passport.authenticate(['basic', 'jwt'], { sessio
562
562
  app.use('/:projectid/openai', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRoleOrTypes('agent')], openai);
563
563
  app.use('/:projectid/kbsettings', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRoleOrTypes('agent', ['bot','subscription'])], kbsettings);
564
564
 
565
+ app.use('/:projectid/logs', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRole('admin')], logs);
566
+
565
567
 
566
568
 
567
569
 
@@ -0,0 +1,37 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const TransactionSchema = mongoose.Schema({
4
+ transaction_id: {
5
+ type: String,
6
+ required: true
7
+ },
8
+ id_project: {
9
+ type: String,
10
+ required: true
11
+ },
12
+ template_name: {
13
+ type: String,
14
+ required: true
15
+ },
16
+ status: {
17
+ type: String,
18
+ required: false
19
+ },
20
+ channel: {
21
+ type: String,
22
+ required: false
23
+ },
24
+ createdAt: {
25
+ type: Date,
26
+ default: Date.now
27
+ },
28
+ updatedAt: {
29
+ type: Date,
30
+ default: Date.now,
31
+ }
32
+ })
33
+
34
+
35
+ const Transaction = mongoose.model("Transactions", TransactionSchema);
36
+
37
+ module.exports = { Transaction };
@@ -1,6 +1,10 @@
1
1
  const mongoose = require('mongoose');
2
2
 
3
3
  const MessageLogSchema = mongoose.Schema({
4
+ id_project: {
5
+ type: String,
6
+ required: true
7
+ },
4
8
  json_message: {
5
9
  type: Object,
6
10
  required: 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.4.82",
4
+ "version": "2.4.83",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -46,8 +46,8 @@
46
46
  "@tiledesk/tiledesk-rasa-connector": "^1.0.10",
47
47
  "@tiledesk/tiledesk-telegram-connector": "^0.1.10",
48
48
  "@tiledesk/tiledesk-tybot-connector": "^0.2.30",
49
- "@tiledesk/tiledesk-whatsapp-connector": "^0.1.56",
50
- "@tiledesk/tiledesk-whatsapp-jobworker": "^0.0.4",
49
+ "@tiledesk/tiledesk-whatsapp-connector": "^0.1.57",
50
+ "@tiledesk/tiledesk-whatsapp-jobworker": "^0.0.7",
51
51
  "amqplib": "^0.5.5",
52
52
  "app-root-path": "^3.0.0",
53
53
  "bcrypt-nodejs": "0.0.3",
package/routes/logs.js CHANGED
@@ -2,6 +2,7 @@ var express = require('express');
2
2
  var router = express.Router();
3
3
  var winston = require('../config/winston');
4
4
  const { MessageLog } = require('../models/whatsappLog');
5
+ const { Transaction } = require('../models/transaction');
5
6
 
6
7
 
7
8
 
@@ -17,16 +18,32 @@ router.post('/', function (req, res, next) {
17
18
  });
18
19
 
19
20
  router.get('/whatsapp', async (req, res) => {
20
- res.stats(200).send({ success: true });
21
+
22
+ let project_id = req.projectid;
23
+
24
+ Transaction.find({ id_project: project_id }, (err, transactions) => {
25
+ if (err) {
26
+ winston.error("Error find transactions for project_id: " + project_id);
27
+ return res.status(400).send({ success: false, message: "Unable to find transaction for project_id " + project_id });
28
+ }
29
+
30
+ winston.verbose("Transactions: ", transactions);
31
+
32
+ res.status(200).send(transactions);
33
+ })
34
+
35
+ // res.stats(200).send({ success: true });
21
36
  })
22
37
 
23
38
 
24
39
  router.get('/whatsapp/:transaction_id', async (req, res) => {
25
40
 
41
+ let project_id = req.projectid;
42
+
26
43
  let transaction_id = req.params.transaction_id;
27
44
  winston.info("Get logs for whatsapp transaction_id " + transaction_id);;
28
45
 
29
- MessageLog.find({ transaction_id: transaction_id }).lean().exec((err, logs) => {
46
+ MessageLog.find({ id_project: project_id, transaction_id: transaction_id }).lean().exec((err, logs) => {
30
47
  if (err) {
31
48
  winston.error("Error find logs for transaction_id " + transaction_id);
32
49
  return res.status(400).send({ success: false, message: "Unable to find logs for transaction_id " + transaction_id })
@@ -37,7 +54,7 @@ router.get('/whatsapp/:transaction_id', async (req, res) => {
37
54
  let clearLogs = logs.map(({_id, __v, ...keepAttrs}) => keepAttrs)
38
55
  winston.verbose("clearLogs: ", clearLogs)
39
56
 
40
- res.status(200).send(logs);
57
+ res.status(200).send(clearLogs);
41
58
  })
42
59
 
43
60
  })
@@ -47,6 +64,7 @@ router.post('/whatsapp', async (req, res) => {
47
64
  winston.info("save following log: ", req.body);
48
65
 
49
66
  let log = new MessageLog({
67
+ id_project: req.body.id_project,
50
68
  json_message: req.body.json_message,
51
69
  transaction_id: req.body.transaction_id,
52
70
  message_id: req.body.message_id,
package/test/logsRoute.js CHANGED
@@ -16,10 +16,10 @@ let should = chai.should();
16
16
  var expect = chai.expect;
17
17
  var assert = chai.assert;
18
18
 
19
- let example_log = {
19
+ let mock_log = {
20
20
  json_message: {
21
21
  messaging_product: "whatsapp",
22
- to: "+393484506627",
22
+ to: "+393484511111",
23
23
  type: "template",
24
24
  template: {
25
25
  name: "codice_sconto",
@@ -39,6 +39,7 @@ let example_log = {
39
39
  ]
40
40
  }
41
41
  },
42
+ id_project: null,
42
43
  transaction_id: null,
43
44
  message_id: "wamid.HBgMMzkzNDg0NTA2NjI3FQIAERgSQTRDNzRDOTM3NzA5Mjk3NzJFAA==",
44
45
  status: "read",
@@ -59,21 +60,23 @@ describe('LogsRoute', () => {
59
60
  userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
60
61
  projectService.create("test1", savedUser._id).then(function (savedProject) {
61
62
 
62
- example_log.transaction_id = "automation-request-" + savedProject._id;
63
- console.log("example_log.transaction_id: ", example_log.transaction_id);
63
+ mock_log.id_project = savedProject._id;
64
+ mock_log.transaction_id = "automation-request-" + savedProject._id;
65
+ console.log("mock_log.transaction_id: ", mock_log.transaction_id);
64
66
 
65
67
  chai.request(server)
66
- .post('/logs/whatsapp')
68
+ .post('/' + savedProject._id + '/logs/whatsapp')
67
69
  .auth(email, pwd)
68
- .send(example_log)
70
+ .send(mock_log)
69
71
  .end((err, res) => {
70
72
  console.log("err: ", err);
71
- console.log("res.body: ", res.body);
73
+ // console.log("res.body: ", res.body);
74
+ console.log("Added example log")
72
75
  res.should.have.status(200);
73
76
  res.body.should.be.a('object');
74
77
 
75
78
  chai.request(server)
76
- .get('/logs/whatsapp/' + example_log.transaction_id)
79
+ .get('/' + savedProject._id + '/logs/whatsapp/' + mock_log.transaction_id)
77
80
  .auth(email, pwd)
78
81
  .end((err, res) => {
79
82
  console.log("err: ", err);