feat(worker): seal WhatsApp adapter — normalize inside session, reactions handled internally

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-27 16:58:22 +05:30
parent 661bbfe003
commit f255ef91fb
3 changed files with 138 additions and 32 deletions
+32 -14
View File
@@ -1,12 +1,5 @@
import { proto } from '@whiskeysockets/baileys';
export interface NormalizedMessage {
platformMsgId: string;
sourceGroupJid: string;
senderJid: string;
senderName?: string;
content: string;
}
import { NormalizedMessage, NormalizedReaction } from '@tower/types';
function extractText(msg: proto.IWebMessageInfo): string {
const m = msg.message;
@@ -21,18 +14,16 @@ function extractText(msg: proto.IWebMessageInfo): string {
);
}
export function normalizeMessage(msg: proto.IWebMessageInfo): NormalizedMessage | null {
export function normalizeMessage(
msg: proto.IWebMessageInfo,
accountId: string,
): 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 platformMsgId = key.id;
@@ -46,5 +37,32 @@ export function normalizeMessage(msg: proto.IWebMessageInfo): NormalizedMessage
senderJid: key.participant ?? '',
senderName: msg.pushName ?? undefined,
content,
accountId,
};
}
export function normalizeReaction(
msg: proto.IWebMessageInfo,
accountId: string,
): NormalizedReaction | null {
const key = msg.key;
if (!key) return null;
const remoteJid = key.remoteJid ?? '';
if (!remoteJid.endsWith('@g.us')) return null;
if (key.fromMe) return null;
const reaction = msg.message?.reactionMessage;
if (!reaction) return null;
const targetMsgId = reaction.key?.id;
if (!targetMsgId) return null;
return {
reactorJid: key.participant ?? '',
targetMsgId,
sourceGroupJid: remoteJid,
emoji: reaction.text ?? '',
accountId,
};
}