notification wa by mqtt broker

This commit is contained in:
2025-12-18 10:05:50 +07:00
parent 2b93baa648
commit 907f5767c1
9 changed files with 248 additions and 4 deletions

9
app.js
View File

@@ -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;