@tiledesk/tiledesk-server 2.4.28 → 2.4.30

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 CHANGED
@@ -7,6 +7,9 @@
7
7
 
8
8
 
9
9
 
10
+ # 2.4.28
11
+ - smartAssignment default value condition for channels
12
+
10
13
  # 2.4.27
11
14
  - tiledesk/tiledesk-tybot-connector:0.1.83
12
15
 
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.28",
4
+ "version": "2.4.30",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -45,7 +45,7 @@
45
45
  "@tiledesk/tiledesk-messenger-connector": "0.1.9",
46
46
  "@tiledesk/tiledesk-rasa-connector": "^1.0.10",
47
47
  "@tiledesk/tiledesk-tybot-connector": "^0.1.83",
48
- "@tiledesk/tiledesk-whatsapp-connector": "^0.1.49",
48
+ "@tiledesk/tiledesk-whatsapp-connector": "^0.1.50",
49
49
  "amqplib": "^0.5.5",
50
50
  "app-root-path": "^3.0.0",
51
51
  "bcrypt-nodejs": "0.0.3",
@@ -16,6 +16,8 @@ constructor() {
16
16
  this.queryAfterTimeout = parseInt(process.env.CLOSE_BOT_UNRESPONSIVE_REQUESTS_AFTER_TIMEOUT) || 2 * 24 * 60 * 60 * 1000; //two days ago //172800000 two days // 86400000 a day
17
17
  this.queryLimit = parseInt(process.env.CLOSE_BOT_UNRESPONSIVE_REQUESTS_QUERY_LIMIT) || 10;
18
18
  this.queryProject = process.env.CLOSE_BOT_UNRESPONSIVE_REQUESTS_QUERY_FILTER_ONLY_PROJECT; //example in PRE: {"$in":["5fc224ce05416200342af18a","5fb3e3cb0150a00034ab77d5"]}
19
+ this.delayBeforeClosing = parseInt(process.env.CLOSE_BOT_UNRESPONSIVE_REQUESTS_DELAY) || 1000;
20
+ // winston.info("delayBeforeClosing: "+ this.delayBeforeClosing);
19
21
 
20
22
  if (this.queryProject) {
21
23
  winston.info("CloseBotUnresponsiveRequestTask filter only by projects enabled: " + this.queryProject );
@@ -62,10 +64,12 @@ scheduleUnresponsiveRequests() {
62
64
 
63
65
 
64
66
  findUnresponsiveRequests() {
65
-
67
+ var that = this;
68
+
66
69
  // db.getCollection('requests').find({"hasBot":true, "status": { "$lt": 1000 }, "createdAt": { "$lte" :new ISODate("2020-11-28T20:15:31Z")} }).count()
67
70
 
68
71
 
72
+ // TODO escludi i ticket offline
69
73
  var query = {hasBot:true, status: { $lt: 1000 }, createdAt: { $lte :new Date(Date.now() - this.queryAfterTimeout ).toISOString()} };
70
74
 
71
75
  if (this.queryProject) {
@@ -73,6 +77,7 @@ findUnresponsiveRequests() {
73
77
  }
74
78
 
75
79
 
80
+ // TODO dovrei fare una query escludendo tutti gli id_project su cui è disabilitato oppure dovrei salvare un attribute in ogni singola request
76
81
 
77
82
  winston.debug("CloseBotUnresponsiveRequestTask query",query);
78
83
 
@@ -84,6 +89,9 @@ findUnresponsiveRequests() {
84
89
  winston.error("CloseBotUnresponsiveRequestTask error getting unresponsive requests ", err);
85
90
  return 0;
86
91
  }
92
+
93
+ // winston.info("delayBeforeClosing: "+ that.delayBeforeClosing);
94
+
87
95
  if (!requests || (requests && requests.length==0)) {
88
96
  winston.verbose("CloseBotUnresponsiveRequestTask no unresponsive requests found ");
89
97
  return 0;
@@ -91,24 +99,32 @@ findUnresponsiveRequests() {
91
99
 
92
100
  winston.info("CloseBotUnresponsiveRequestTask: found " + requests.length + " unresponsive requests");
93
101
  winston.debug("CloseBotUnresponsiveRequestTask: found unresponsive requests ", requests);
94
-
95
- requests.forEach(request => {
96
102
 
97
- winston.debug("********unresponsive request ", request);
98
-
99
- // closeRequestByRequestId(request_id, id_project, skipStatsUpdate, notify, closed_by)
100
- const closed_by = "_bot_unresponsive";
101
- return requestService.closeRequestByRequestId(request.request_id, request.id_project, false, false, closed_by).then(function(updatedStatusRequest) {
102
- winston.info("CloseBotUnresponsiveRequestTask: Request closed with request_id: " + request.request_id);
103
- // winston.info("Request closed",updatedStatusRequest);
104
- }).catch(function(err) {
105
- if (process.env.HIDE_CLOSE_REQUEST_ERRORS == true || process.env.HIDE_CLOSE_REQUEST_ERRORS == "true" ) {
106
-
107
- } else {
108
- winston.error("CloseBotUnresponsiveRequestTask: Error closing the request with request_id: " + request.request_id, err);
109
- }
110
-
111
- })
103
+ let i = 0;
104
+ let delay = this.delayBeforeClosing*i;
105
+ // winston.info("delay" + delay);
106
+
107
+ requests.forEach(request => {
108
+ i++;
109
+ setTimeout(function(){
110
+
111
+ // TODO aggiungi uno sleep
112
+ winston.debug("********unresponsive request ", request);
113
+
114
+ // closeRequestByRequestId(request_id, id_project, skipStatsUpdate, notify, closed_by)
115
+ const closed_by = "_bot_unresponsive";
116
+ return requestService.closeRequestByRequestId(request.request_id, request.id_project, false, false, closed_by).then(function(updatedStatusRequest) {
117
+ winston.info("CloseBotUnresponsiveRequestTask: Request closed with request_id: " + request.request_id);
118
+ // winston.info("Request closed",updatedStatusRequest);
119
+ }).catch(function(err) {
120
+ if (process.env.HIDE_CLOSE_REQUEST_ERRORS == true || process.env.HIDE_CLOSE_REQUEST_ERRORS == "true" ) {
121
+
122
+ } else {
123
+ winston.error("CloseBotUnresponsiveRequestTask: Error closing the request with request_id: " + request.request_id, err);
124
+ }
125
+
126
+ })
127
+ }, delay)
112
128
 
113
129
  });
114
130