feat: add db
This commit is contained in:
+17
-1
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user