logger

Self-hosted WhatsApp logger us...
Log | Files | Refs | README | LICENSE

commit 5e9a737e46918ddf1593faf04961b410404b0364
parent e7ca4163875dab1911ceb25baa026554794f94f9
Author: AMIT DUTTA <amitdutta4255@gmail.com>
Date:   Mon, 16 Feb 2026 19:18:32 +0530

Enhance chat document handling and CORS setup

Added functionality to create or update the parent chat document in the database and adjusted CORS headers for the verify credentials API.
Diffstat:
Mindex.js | 17+++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/index.js b/index.js @@ -111,6 +111,15 @@ async function startWhatsApp() { const isFromMe = msg.key.fromMe || false; const senderName = isFromMe ? "Me" : (msg.pushName || "Unknown"); + // --- FIX: Create/Update Parent Chat Document --- + // This makes the chat visible in the list automatically + await db.collection('Chats').doc(remoteJid).set({ + lastActive: timestamp, + displayName: senderName, + id: remoteJid + }, { merge: true }); + + // --- Save Message --- await db.collection('Chats') .doc(remoteJid) .collection('Messages') @@ -153,11 +162,10 @@ app.get('/ping', (req, res) => { res.status(200).send('Pong'); }); -// 2. PUBLIC ROUTE (NEW): Verify Credentials API -// We add CORS headers specifically for this response so your frontend can read it +// 2. PUBLIC ROUTE: Verify Credentials API app.post('/api/verify', (req, res) => { // CORS Headers - res.header("Access-Control-Allow-Origin", "*"); // Allow any domain (or set to your specific domain) + res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); const { username, password } = req.body; @@ -169,14 +177,12 @@ app.post('/api/verify', (req, res) => { } }); -// Handle OPTIONS requests for CORS pre-flight checks app.options('/api/verify', (req, res) => { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); res.sendStatus(200); }); - // 3. LOGIN PAGE (GET) app.get('/login', (req, res) => { res.send(` @@ -230,7 +236,6 @@ app.get('/logout', (req, res) => { }); // --- MIDDLEWARE: FORM AUTH --- -// ALL ROUTES BELOW THIS REQUIRE LOGIN const checkAuth = (req, res, next) => { if (!AUTH_USER || !AUTH_PASS) return next();
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror