@tiledesk/tiledesk-whatsapp-connector 0.1.55 → 0.1.57
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 +23 -4
- package/models/Transaction.js +37 -0
- package/package.json +2 -2
- package/tiledesk/WhatsappLogger.js +37 -1
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
|
-
|
|
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
|
-
|
|
1065
|
-
|
|
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(
|
|
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.
|
|
3
|
+
"version": "0.1.57",
|
|
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.
|
|
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",
|
|
@@ -3,7 +3,11 @@ 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);
|
|
@@ -12,6 +16,8 @@ class WhatsappLogger {
|
|
|
12
16
|
MessageLog.findOneAndUpdate({ message_id: message_id }, { $set: {status: status, status_code: status_code, error: error }}, { new: true }).then((messageLog) => {
|
|
13
17
|
winston.verbose("(wab) status of message_id " + message_id + " updated to " + status);
|
|
14
18
|
winston.debug("(wab) messageLog updated ", messageLog);
|
|
19
|
+
|
|
20
|
+
this.sendLogWebhook(messageLog);
|
|
15
21
|
}).catch((err) => {
|
|
16
22
|
winston.error("(wab) findOneAndUpdate error: ", err);
|
|
17
23
|
})
|
|
@@ -43,6 +49,36 @@ class WhatsappLogger {
|
|
|
43
49
|
return code;
|
|
44
50
|
}
|
|
45
51
|
|
|
52
|
+
sendLogWebhook(messageLog) {
|
|
53
|
+
let event = {
|
|
54
|
+
name: "tiledesk.whatsapplog",
|
|
55
|
+
attributes: {
|
|
56
|
+
messageLog: messageLog,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
this.tdClient.fireEvent(event, (err, result) => {
|
|
60
|
+
if (err) {
|
|
61
|
+
winston.error("(wab) An error occurred invoking an event:", err);
|
|
62
|
+
}
|
|
63
|
+
winston.verbose("(wab) Real time log event fired");
|
|
64
|
+
winston.debug("(wab) Real time log event fired: ", result);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/*
|
|
69
|
+
sendLogWebhook(project_id, messageLog) {
|
|
70
|
+
this.tdClient.sendSupportMessage(
|
|
71
|
+
"support-group-" + project_id + "-whatsapplog-hidden",
|
|
72
|
+
{ text: "Whatsapp Log", attributes: { messageLog: messageLog} },
|
|
73
|
+
(err) => {
|
|
74
|
+
if (err) {
|
|
75
|
+
console.error("Error sending reply:", err);
|
|
76
|
+
}
|
|
77
|
+
winston.verbose("(wab-worker) Log webhook sent successfully");
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
*/
|
|
81
|
+
|
|
46
82
|
}
|
|
47
83
|
|
|
48
84
|
module.exports = { WhatsappLogger };
|