@tiledesk/tiledesk-whatsapp-connector 0.1.56 → 0.1.58

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/index.js CHANGED
@@ -19,7 +19,7 @@ const api = require('./routes/api');
19
19
  const apiRoute = api.router;
20
20
 
21
21
  // tiledesk clients
22
- //const { TiledeskClient } = require('@tiledesk/tiledesk-client');
22
+ const { TiledeskClient } = require('@tiledesk/tiledesk-client');
23
23
  const { TiledeskWhatsappTranslator } = require('./tiledesk/TiledeskWhatsappTranslator');
24
24
  const { TiledeskSubscriptionClient } = require('./tiledesk/TiledeskSubscriptionClient');
25
25
  const { TiledeskWhatsapp } = require('./tiledesk/TiledeskWhatsapp');
@@ -1061,9 +1061,21 @@ router.post("/webhook/:project_id", async (req, res) => {
1061
1061
  }
1062
1062
  winston.verbose("(wab) update status in " + status+ " for message_id " + message_id);
1063
1063
 
1064
- const wl = new WhatsappLogger();
1065
- wl.updateMessageStatus(message_id, status, error);
1064
+ let CONTENT_KEY = "whatsapp-" + project_id;
1065
+ let settings = await db.get(CONTENT_KEY);
1066
+ winston.debug("(wab) settings: ", settings);
1067
+
1068
+ const tdClient = new TiledeskClient({
1069
+ projectId: project_id,
1070
+ token: settings.token,
1071
+ APIURL: API_URL,
1072
+ APIKEY: "___",
1073
+ log: false
1074
+ });
1066
1075
 
1076
+ const wl = new WhatsappLogger({ tdClient: tdClient});
1077
+ wl.updateMessageStatus(message_id, status, error);
1078
+
1067
1079
  }
1068
1080
 
1069
1081
  res.sendStatus(200);
@@ -1366,8 +1378,15 @@ async function startApp(settings, callback) {
1366
1378
  JOB_TOPIC_EXCHANGE = settings.JOB_TOPIC_EXCHANGE;
1367
1379
  winston.info("(wab) JOB_TOPIC_EXCHANGE is present");
1368
1380
  }
1381
+
1382
+ let LOG_MONGODB_URL;
1383
+ if (!settings.LOG_MONGODB_URL) {
1384
+ LOG_MONGODB_URL = settings.MONGODB_URL;
1385
+ } else {
1386
+ LOG_MONGODB_URL = settings.LOG_MONGODB_URL;
1387
+ }
1369
1388
 
1370
- mongoose.connect(settings.MONGODB_URL)
1389
+ mongoose.connect(LOG_MONGODB_URL)
1371
1390
  .then(() => { winston.info("Mongoose DB Connected") })
1372
1391
  .catch((err) => { winston.error("(Mongoose) Unable to connect with MongoDB ", err)
1373
1392
  })
@@ -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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-whatsapp-connector",
3
- "version": "0.1.56",
3
+ "version": "0.1.58",
4
4
  "description": "Tiledesk Whatsapp connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,7 +11,7 @@
11
11
  "author": "Giovanni Troisi",
12
12
  "license": "MIT",
13
13
  "dependencies": {
14
- "@tiledesk/tiledesk-client": "^0.8.29",
14
+ "@tiledesk/tiledesk-client": "^0.10.4",
15
15
  "app-root-path": "^3.0.0",
16
16
  "axios": "^0.27.2",
17
17
  "body-parser": "^1.20.0",
@@ -214,6 +214,14 @@
214
214
 
215
215
  <p style="font-size: 18px;"><b>What's new?</b></p>
216
216
 
217
+ <div style="width: 100%; display: flex; flex-direction: row; justify-content: space-between; margin-bottom: 15px;">
218
+ <div>
219
+ <p style="margin-bottom: 0px">Bug fixes and minor improvements</p>
220
+ </div>
221
+ <p style="font-size: 12px; color: #676767; margin-bottom: 0px;">Version <b>0.1.58</b></p>
222
+ </div>
223
+
224
+
217
225
  <div style="width: 100%; display: flex; flex-direction: row; justify-content: space-between; margin-bottom: 15px;">
218
226
  <div>
219
227
  <p>Added Messages Logs for WhatsApp broadcast</p>
@@ -237,14 +245,6 @@
237
245
  <p style="font-size: 12px; color: #676767; margin-bottom: 0px;">Version <b>0.1.52</b></p>
238
246
  </div>
239
247
 
240
- <div style="width: 100%; display: flex; flex-direction: row; justify-content: space-between; margin-bottom: 15px;">
241
- <div>
242
- <p style="margin-bottom: 0px">Bug fixes</p>
243
- <!--<p>Bug fixes and performance improvements</p>-->
244
- </div>
245
- <p style="font-size: 12px; color: #676767; margin-bottom: 0px;">Version <b>0.1.50</b></p>
246
- </div>
247
-
248
248
 
249
249
  <hr style="margin-top: 50px; margin-bottom: 20px">
250
250
 
@@ -3,15 +3,24 @@ const { MessageLog } = require("../models/WhatsappLog");
3
3
 
4
4
  class WhatsappLogger {
5
5
 
6
- constructor() {}
6
+ constructor(config) {
7
+
8
+ this.tdClient = config.tdClient;
9
+
10
+ }
7
11
 
8
12
  async updateMessageStatus(message_id, status, error) {
9
13
  let status_code = this.getCodeFromStatus(status);
10
14
  winston.debug("(wab) getCodeFromStatus result " + status_code);
11
15
 
12
16
  MessageLog.findOneAndUpdate({ message_id: message_id }, { $set: {status: status, status_code: status_code, error: error }}, { new: true }).then((messageLog) => {
13
- winston.verbose("(wab) status of message_id " + message_id + " updated to " + status);
14
- winston.debug("(wab) messageLog updated ", messageLog);
17
+
18
+ if (messageLog) {
19
+ winston.verbose("(wab) status of message_id " + message_id + " updated to " + status);
20
+ winston.debug("(wab) messageLog updated ", messageLog);
21
+ this.sendLogWebhook(messageLog);
22
+ }
23
+
15
24
  }).catch((err) => {
16
25
  winston.error("(wab) findOneAndUpdate error: ", err);
17
26
  })
@@ -43,6 +52,36 @@ class WhatsappLogger {
43
52
  return code;
44
53
  }
45
54
 
55
+ sendLogWebhook(messageLog) {
56
+ let event = {
57
+ name: "tiledesk.whatsapplog",
58
+ attributes: {
59
+ messageLog: messageLog,
60
+ },
61
+ };
62
+ this.tdClient.fireEvent(event, (err, result) => {
63
+ if (err) {
64
+ winston.error("(wab) An error occurred invoking an event:", err);
65
+ }
66
+ winston.verbose("(wab) Real time log event fired");
67
+ winston.debug("(wab) Real time log event fired: ", result);
68
+ });
69
+ }
70
+
71
+ /*
72
+ sendLogWebhook(project_id, messageLog) {
73
+ this.tdClient.sendSupportMessage(
74
+ "support-group-" + project_id + "-whatsapplog-hidden",
75
+ { text: "Whatsapp Log", attributes: { messageLog: messageLog} },
76
+ (err) => {
77
+ if (err) {
78
+ console.error("Error sending reply:", err);
79
+ }
80
+ winston.verbose("(wab-worker) Log webhook sent successfully");
81
+ });
82
+ }
83
+ */
84
+
46
85
  }
47
86
 
48
87
  module.exports = { WhatsappLogger };