feat: add Baileys message normalizer

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-27 15:08:10 +05:30
parent 4c721f0b19
commit 7151e0dd6d
4 changed files with 410 additions and 8 deletions
+47
View File
@@ -0,0 +1,47 @@
import { proto } from '@whiskeysockets/baileys';
export interface NormalizedMessage {
platformMsgId: string;
sourceGroupJid: string;
senderJid: string;
senderName?: string;
content: string;
}
function extractText(msg: proto.IWebMessageInfo): string {
const m = msg.message;
if (!m) return '';
return (
m.conversation ||
m.extendedTextMessage?.text ||
m.imageMessage?.caption ||
m.videoMessage?.caption ||
m.documentMessage?.caption ||
''
);
}
export function normalizeMessage(msg: proto.IWebMessageInfo): NormalizedMessage | null {
const key = msg.key;
if (!key) return null;
const remoteJid = key.remoteJid ?? '';
// Only process group messages (group JIDs end with @g.us)
if (!remoteJid.endsWith('@g.us')) return null;
// Skip our own outgoing messages
if (key.fromMe) return null;
if (!msg.message) return null;
const content = extractText(msg);
return {
platformMsgId: key.id ?? '',
sourceGroupJid: remoteJid,
senderJid: key.participant ?? '',
senderName: msg.pushName ?? undefined,
content,
};
}