@tiledesk/tiledesk-server 2.4.15 → 2.4.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,7 +25,7 @@ if (process.env.SYNC_JOIN_LEAVE_GROUP_EVENT === true || process.env.SYNC_JOIN_LE
25
25
  }
26
26
  winston.info("Chat21 Sync JoinAndLeave Support Group Event: " + syncJoinAndLeaveGroupEvent);
27
27
 
28
- var allowReopenChat = false;
28
+ var allowReopenChat = false; //It's work only with firebase chat engine
29
29
  if (process.env.ALLOW_REOPEN_CHAT === true || process.env.ALLOW_REOPEN_CHAT ==="true") {
30
30
  allowReopenChat = true;
31
31
  }
@@ -305,10 +305,11 @@ router.post('/', function (req, res) {
305
305
 
306
306
  // return requestService.incrementMessagesCountByRequestId(request.request_id, request.id_project).then(function(savedRequest) {
307
307
  // winston.debug("savedRequest.participants.indexOf(message.sender)", savedRequest.participants.indexOf(message.sender));
308
-
308
+ winston.info("before updateWaitingTimeByRequestId*******",request.participants, message.sender);
309
+ winston.info("updateWaitingTimeByRequestId******* message: "+ message.sender);
309
310
  // TODO it doesn't work for internal requests bacause participanets == message.sender⁄
310
311
  if (request.participants && request.participants.indexOf(message.sender) > -1) { //update waiitng time if write an agent (member of participants)
311
- winston.debug("updateWaitingTimeByRequestId*******");
312
+ winston.info("updateWaitingTimeByRequestId*******");
312
313
  return requestService.updateWaitingTimeByRequestId(request.request_id, request.id_project, false).then(function(upRequest) {
313
314
  return res.json(upRequest);
314
315
  });
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.15",
4
+ "version": "2.4.17",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -286,6 +286,32 @@
286
286
  })
287
287
  });
288
288
 
289
+ function invalidatRequestSimple(client, project_id, rid, request_id) {
290
+ var key = project_id+":requests:id:"+rid+":simple";
291
+ winston.verbose("Deleting cache for widgets with key: " + key);
292
+ client.del(key, function (err, reply) {
293
+ winston.debug("Deleted cache for invalidatRequestSimple",reply);
294
+ winston.verbose("Deleted cache for invalidatRequestSimple",{err:err});
295
+ });
296
+
297
+ key = "requests:request_id:"+request_id+":simple"; //without project for chat21 webhook
298
+ winston.verbose("Creating cache for request.create.simple for invalidatRequestSimple without project with key : " + key);
299
+ client.del(key, function (err, reply) {
300
+ winston.debug("Deleted cache for invalidatRequestSimple",reply);
301
+ winston.verbose("Deleted cache for invalidatRequestSimple",{err:err});
302
+ });
303
+
304
+ key = project_id+":requests:request_id:"+request_id+":simple";
305
+ winston.verbose("Creating cache for request.create.simple for invalidatRequestSimple with key: " + key);
306
+ client.del(key, function (err, reply) {
307
+ winston.debug("Deleted cache for invalidatRequestSimple",reply);
308
+ winston.verbose("Deleted cache for invalidatRequestSimple",{err:err});
309
+ });
310
+
311
+
312
+ }
313
+
314
+
289
315
  requestEvent.on("request.create", function(request) {
290
316
  setImmediate(() => {
291
317
  var key = request.id_project+":requests:id:"+request.id;
@@ -310,6 +336,7 @@
310
336
  winston.debug("Deleted cache for request.create",reply);
311
337
  winston.verbose("Deleted cache for request.create",{err:err});
312
338
  });
339
+
313
340
  });
314
341
  });
315
342
 
@@ -338,6 +365,9 @@
338
365
  winston.debug("Deleted cache for request.update",reply);
339
366
  winston.verbose("Deleted cache for request.update",{err:err});
340
367
  });
368
+
369
+ invalidatRequestSimple(client, request.id_project, request.id, request.request_id)
370
+
341
371
  });
342
372
  });
343
373
 
@@ -365,6 +395,9 @@
365
395
  winston.debug("Deleted cache for request.close",reply);
366
396
  winston.verbose("Deleted cache for request.close",{err:err});
367
397
  });
398
+
399
+ invalidatRequestSimple(client, request.id_project, request.id, request.request_id)
400
+
368
401
  });
369
402
  });
370
403
 
@@ -727,7 +760,7 @@
727
760
  }
728
761
 
729
762
  function invalidateWidgets(client, project_id) {
730
- key = project_id+":widgets";
763
+ let key = project_id+":widgets";
731
764
  winston.verbose("Deleting cache for widgets with key: " + key);
732
765
  client.del(key, function (err, reply) {
733
766
  winston.debug("Deleted cache for widgets",reply);
@@ -15,7 +15,20 @@ var url = process.env.CLOUDAMQP_URL + "?heartbeat=60" || "amqp://localhost";
15
15
  // attento devi aggiornare configMap di PRE E PROD
16
16
  // var url = process.env.AMQP_URL + "?heartbeat=60" || "amqp://localhost?heartbeat=60";
17
17
 
18
- var exchange = 'amq.topic';
18
+ var durable = false;
19
+ if (process.env.ENABLE_DURABLE_QUEUE == true || process.env.ENABLE_DURABLE_QUEUE == "true") {
20
+ durable = true;
21
+ }
22
+
23
+ var persistent = false;
24
+ if (process.env.ENABLE_PERSISTENT_QUEUE == true || process.env.ENABLE_PERSISTENT_QUEUE == "true") {
25
+ persistent = true;
26
+ }
27
+
28
+ var exchange = process.env.QUEUE_EXCHANGE_TOPIC || 'amq.topic';
29
+
30
+ winston.info("Durable queue: " + durable + " Persistent queue: " + persistent + " Exchange topic: " + exchange);
31
+
19
32
 
20
33
  function start() {
21
34
  amqp.connect(url, function(err, conn) {
@@ -83,8 +96,8 @@ function startPublisher() {
83
96
  // method to publish a message, will queue messages internally if the connection is down and resend later
84
97
  function publish(exchange, routingKey, content) {
85
98
  try {
86
- pubChannel.publish(exchange, routingKey, content, {},
87
- // pubChannel.publish(exchange, routingKey, content, { persistent: true },
99
+ pubChannel.publish(exchange, routingKey, content, { persistent: persistent },
100
+ // pubChannel.publish(exchange, routingKey, content, { persistent: true },
88
101
 
89
102
  function(err, ok) {
90
103
  if (err) {
@@ -112,9 +125,12 @@ function startWorker() {
112
125
  });
113
126
  ch.prefetch(10);//leggila da env
114
127
  ch.assertExchange(exchange, 'topic', {
115
- durable: true
128
+ durable: durable
129
+ // durable: true
116
130
  });
117
- ch.assertQueue("jobs", { durable: true }, function(err, _ok) {
131
+
132
+ ch.assertQueue("jobs", { durable: durable }, function(err, _ok) {
133
+ // ch.assertQueue("jobs", { durable: true }, function(err, _ok) {
118
134
  if (closeOnErr(err)) return;
119
135
  ch.bindQueue(_ok.queue, exchange, "request_create", {}, function(err3, oka) {
120
136
  winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: request_create");
@@ -234,7 +250,7 @@ function work(msg, cb) {
234
250
  }
235
251
 
236
252
  if (topic === 'faqbot_update') {
237
- winston.info("reconnect here topic faqbot_update:" + topic);
253
+ winston.debug("reconnect here topic faqbot_update:" + topic);
238
254
  // requestEvent.emit('request.update.queue', msg.content);
239
255
  botEvent.emit('faqbot.update.queue', JSON.parse(message_string));
240
256
  }
@@ -268,6 +268,6 @@ if (process.env.QUEUE_ENABLED === "true") {
268
268
  botEvent.queueEnabled = true;
269
269
  listen();
270
270
  start();
271
- winston.info("Queue Fanout enabled. endpint: " + url );
271
+ winston.info("Queue Fanout enabled. endpoint: " + url );
272
272
  }
273
273
 
package/routes/lead.js CHANGED
@@ -148,6 +148,56 @@ router.patch('/:leadid/attributes', function (req, res) {
148
148
  });
149
149
 
150
150
 
151
+ //.post and .patch for /properties are equals
152
+
153
+ router.post('/:leadid/properties', function (req, res) {
154
+ var data = req.body;
155
+
156
+ // TODO use service method
157
+
158
+ Lead.findById(req.params.leadid, function (err, lead) {
159
+ if (err) {
160
+ winston.error('--- > ERROR ', err);
161
+ return res.status(500).send({ success: false, msg: 'Error updating object.' });
162
+ }
163
+
164
+ if (!lead) {
165
+ return res.status(404).send({ success: false, msg: 'Object not found.' });
166
+ }
167
+
168
+ if (!lead.properties) {
169
+ winston.debug("empty properties")
170
+ lead.properties = {};
171
+ }
172
+
173
+ winston.debug(" lead properties", lead.properties)
174
+
175
+ Object.keys(data).forEach(function(key) {
176
+ var val = data[key];
177
+ winston.debug("data attributes "+key+" " +val)
178
+ lead.properties[key] = val;
179
+ });
180
+
181
+ winston.debug(" lead properties", lead.properties)
182
+
183
+ // https://stackoverflow.com/questions/24054552/mongoose-not-saving-nested-object
184
+ lead.markModified('properties');
185
+
186
+ //cacheinvalidation
187
+ lead.save(function (err, savedLead) {
188
+ if (err) {
189
+ winston.error("error saving lead properties",err)
190
+ return res.status(500).send({ success: false, msg: 'Error getting object.' });
191
+ }
192
+ winston.verbose(" saved lead properties",savedLead.toObject())
193
+ leadEvent.emit('lead.update', savedLead);
194
+
195
+ res.json(savedLead);
196
+ });
197
+ });
198
+
199
+ });
200
+
151
201
 
152
202
  router.patch('/:leadid/properties', function (req, res) {
153
203
  var data = req.body;
@@ -75,7 +75,7 @@ class ChatbotService {
75
75
 
76
76
  async createBot(api_url, token, chatbot, project_id) {
77
77
 
78
- winston.info("(CHATBOT SERVICE) createBot");
78
+ winston.debug("(CHATBOT SERVICE) createBot");
79
79
 
80
80
  return await axios({
81
81
  url: api_url + '/' + project_id + '/faq_kb/',
@@ -277,7 +277,7 @@
277
277
  <span>Powered by </span>
278
278
  <span style="display: flex;"><img
279
279
  src="https://tiledesk.com/wp-content/uploads/2023/05/tiledesk-solo_logo_new_gray.png" width="15"
280
- height="15" style="margin-left: 6px;" /></span>
280
+ height="15" style="margin-left: 6px; margin-top: 2px;" /></span>
281
281
  <span style="font-weight: bold; margin-left: 2px;">Tiledesk</span>
282
282
  </div>
283
283
 
@@ -269,7 +269,7 @@
269
269
  <span>Powered by </span>
270
270
  <span style="display: flex;"><img
271
271
  src="https://tiledesk.com/wp-content/uploads/2023/05/tiledesk-solo_logo_new_gray.png"
272
- width="15" height="15" style="margin-left: 6px;" /></span>
272
+ width="15" height="15" style="margin-left: 6px; margin-top: 2px;" /></span>
273
273
  <span style="font-weight: bold; margin-left: 2px;">Tiledesk</span>
274
274
  </div>
275
275
 
@@ -191,7 +191,7 @@
191
191
  <span>Powered by </span>
192
192
  <span style="display: flex;"><img
193
193
  src="https://tiledesk.com/wp-content/uploads/2023/05/tiledesk-solo_logo_new_gray.png" width="15"
194
- height="15" style="margin-left: 6px;" /></span>
194
+ height="15" style="margin-left: 6px; margin-top: 2px;" /></span>
195
195
  <span style="font-weight: bold; margin-left: 2px;">Tiledesk</span>
196
196
  </div>
197
197
 
@@ -190,12 +190,12 @@
190
190
  <hr style="width:94%;height:1px;border:none;background-color: #cacaca;">
191
191
 
192
192
  <div style="display: flex; padding: 20px 18px; color: #888888; align-items: center;">
193
- <span>Powered by </span>
194
- <span style="display: flex;"><img
195
- src="https://tiledesk.com/wp-content/uploads/2023/05/tiledesk-solo_logo_new_gray.png" width="15"
196
- height="15" style="margin-left: 6px;" /></span>
197
- <span style="font-weight: bold; margin-left: 2px;">Tiledesk</span>
198
- </div>
193
+ <span>Powered by </span>
194
+ <span style="display: flex;"><img
195
+ src="https://tiledesk.com/wp-content/uploads/2023/05/tiledesk-solo_logo_new_gray.png"
196
+ width="15" height="15" style="margin-left: 6px; margin-top: 2px;" /></span>
197
+ <span style="font-weight: bold; margin-left: 2px;">Tiledesk</span>
198
+ </div>
199
199
 
200
200
  </td>
201
201
  </tr>
@@ -184,7 +184,7 @@
184
184
  <span>Powered by </span>
185
185
  <span style="display: flex;"><img
186
186
  src="https://tiledesk.com/wp-content/uploads/2023/05/tiledesk-solo_logo_new_gray.png" width="15"
187
- height="15" style="margin-left: 6px;" /></span>
187
+ height="15" style="margin-left: 6px; margin-top: 2px;" /></span>
188
188
  <span style="font-weight: bold; margin-left: 2px;">Tiledesk</span>
189
189
  </div>
190
190
 
@@ -244,7 +244,7 @@
244
244
  <span>Powered by </span>
245
245
  <span style="display: flex;"><img
246
246
  src="https://tiledesk.com/wp-content/uploads/2023/05/tiledesk-solo_logo_new_gray.png" width="15"
247
- height="15" style="margin-left: 6px;" /></span>
247
+ height="15" style="margin-left: 6px; margin-top: 2px;" /></span>
248
248
  <span style="font-weight: bold; margin-left: 2px;">Tiledesk</span>
249
249
  </div>
250
250
 
@@ -333,7 +333,7 @@
333
333
  <span>Powered by </span>
334
334
  <span style="display: flex;"><img
335
335
  src="https://tiledesk.com/wp-content/uploads/2023/05/tiledesk-solo_logo_new_gray.png" width="15"
336
- height="15" style="margin-left: 6px;" /></span>
336
+ height="15" style="margin-left: 6px; margin-top: 2px;" /></span>
337
337
  <span style="font-weight: bold; margin-left: 2px;">Tiledesk</span>
338
338
  </div>
339
339
 
@@ -181,12 +181,12 @@
181
181
  <hr style="width:94%;height:1px;border:none;background-color: #cacaca;">
182
182
 
183
183
  <div style="display: flex; padding: 20px 18px; color: #888888; align-items: center;">
184
- <span>Powered by </span>
185
- <span style="display: flex;"><img
186
- src="https://tiledesk.com/wp-content/uploads/2023/05/tiledesk-solo_logo_new_gray.png" width="15"
187
- height="15" style="margin-left: 6px;" /></span>
188
- <span style="font-weight: bold; margin-left: 2px;">Tiledesk</span>
189
- </div>
184
+ <span>Powered by </span>
185
+ <span style="display: flex;"><img
186
+ src="https://tiledesk.com/wp-content/uploads/2023/05/tiledesk-solo_logo_new_gray.png"
187
+ width="15" height="15" style="margin-left: 6px; margin-top: 2px;" /></span>
188
+ <span style="font-weight: bold; margin-left: 2px;">Tiledesk</span>
189
+ </div>
190
190
 
191
191
  </td>
192
192
  </tr>
@@ -272,7 +272,7 @@
272
272
  <span>Powered by </span>
273
273
  <span style="display: flex;"><img
274
274
  src="https://tiledesk.com/wp-content/uploads/2023/05/tiledesk-solo_logo_new_gray.png"
275
- width="15" height="15" style="margin-left: 6px;" /></span>
275
+ width="15" height="15" style="margin-left: 6px; margin-top: 2px;" /></span>
276
276
  <span style="font-weight: bold; margin-left: 2px;">Tiledesk</span>
277
277
  </div>
278
278
 
@@ -269,7 +269,7 @@
269
269
  <span>Powered by </span>
270
270
  <span style="display: flex;"><img
271
271
  src="https://tiledesk.com/wp-content/uploads/2023/05/tiledesk-solo_logo_new_gray.png" width="15"
272
- height="15" style="margin-left: 6px;" /></span>
272
+ height="15" style="margin-left: 6px; margin-top: 2px;" /></span>
273
273
  <span style="font-weight: bold; margin-left: 2px;">Tiledesk</span>
274
274
  </div>
275
275
 
@@ -191,7 +191,7 @@
191
191
  <span>Powered by </span>
192
192
  <span style="display: flex;"><img
193
193
  src="https://tiledesk.com/wp-content/uploads/2023/05/tiledesk-solo_logo_new_gray.png" width="15"
194
- height="15" style="margin-left: 6px;" /></span>
194
+ height="15" style="margin-left: 6px; margin-top: 2px;" /></span>
195
195
  <span style="font-weight: bold; margin-left: 2px;">Tiledesk</span>
196
196
  </div>
197
197
 
@@ -263,7 +263,7 @@
263
263
  <span>Powered by </span>
264
264
  <span style="display: flex;"><img
265
265
  src="https://tiledesk.com/wp-content/uploads/2023/05/tiledesk-solo_logo_new_gray.png" width="15"
266
- height="15" style="margin-left: 6px;" /></span>
266
+ height="15" style="margin-left: 6px; margin-top: 2px;" /></span>
267
267
  <span style="font-weight: bold; margin-left: 2px;">Tiledesk</span>
268
268
  </div>
269
269
 
@@ -268,7 +268,7 @@
268
268
  <span>Powered by </span>
269
269
  <span style="display: flex;"><img
270
270
  src="https://tiledesk.com/wp-content/uploads/2023/05/tiledesk-solo_logo_new_gray.png" width="15"
271
- height="15" style="margin-left: 6px;" /></span>
271
+ height="15" style="margin-left: 6px; margin-top: 2px;" /></span>
272
272
  <span style="font-weight: bold; margin-left: 2px;">Tiledesk</span>
273
273
  </div>
274
274
 
@@ -187,7 +187,7 @@
187
187
  <span>Powered by </span>
188
188
  <span style="display: flex;"><img
189
189
  src="https://tiledesk.com/wp-content/uploads/2023/05/tiledesk-solo_logo_new_gray.png" width="15"
190
- height="15" style="margin-left: 6px;" /></span>
190
+ height="15" style="margin-left: 6px; margin-top: 2px;" /></span>
191
191
  <span style="font-weight: bold; margin-left: 2px;">Tiledesk</span>
192
192
  </div>
193
193