notification wa by mqtt broker
This commit is contained in:
9
app.js
9
app.js
@@ -8,7 +8,8 @@ const helmet = require("helmet");
|
||||
const compression = require("compression");
|
||||
const unknownEndpoint = require("./middleware/unKnownEndpoint");
|
||||
const { handleError } = require("./helpers/error");
|
||||
const { checkConnection } = require("./config");
|
||||
const { checkConnection, mqttClient } = require("./config");
|
||||
const { onNotification } = require("./services/notifikasi-wa.service");
|
||||
|
||||
const app = express();
|
||||
|
||||
@@ -47,4 +48,10 @@ app.get("/check-db", async (req, res) => {
|
||||
app.use(unknownEndpoint);
|
||||
app.use(handleError);
|
||||
|
||||
// Saat pesan diterima
|
||||
mqttClient.on('message', (topic, message) => {
|
||||
console.log(`Received message on topic "${topic}":`, message.toString());
|
||||
onNotification(topic, message);
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
|
||||
Reference in New Issue
Block a user