feat: add db

This commit is contained in:
2026-09-14 18:27:27 +08:00
parent e4b77e1c11
commit 193e5fff31
9 changed files with 88 additions and 10 deletions
+17 -1
View File
@@ -1,6 +1,8 @@
import { WebSocketServer, WebSocket } from "ws";
import type { BridgeRequest, RpcResponse } from "../shared/protocol";
import { initDb, insertMessage } from "./db";
import type { MessageDTO } from "../shared/dto";
const PORT = 8787;
@@ -89,7 +91,20 @@ function handleWhatsAppMessage(data: string) {
}
if (message.type === "event") {
console.log("[WhatsApp event]", message.event, message.data);
// console.log("[WhatsApp event]", message.event, message.data);
if (message.event === "message") {
const m = message.data as MessageDTO;
insertMessage({
id: m.id.id || m.id._serialized || "",
chatId: m.chatId || "",
from: typeof m.from === "string" ? m.from : m.from?._serialized || "",
to: typeof m.to === "string" ? m.to : m.to?._serialized || "",
fromMe: !!m.fromMe,
data: m,
});
}
}
}
@@ -203,4 +218,5 @@ wss.on("connection", (ws) => {
});
});
initDb();
console.log(`WhatsApp bridge listening on ws://127.0.0.1:${PORT}`);