refactor: simplify whatsapp content gate

This commit is contained in:
Marcus Castro
2026-04-28 21:36:09 -03:00
parent 236c04dd71
commit c5e4a804fe
2 changed files with 12 additions and 8 deletions

View File

@@ -169,6 +169,16 @@ describe("hasInboundUserContent", () => {
).toBe(true);
});
it("returns true for contactsArrayMessage via contact placeholder extraction", () => {
expect(
hasInboundUserContent({
contactsArrayMessage: {
contacts: [{ displayName: "Alice", vcard: "BEGIN:VCARD\nEND:VCARD" }],
},
} as proto.IMessage),
).toBe(true);
});
it("returns true for buttons response (user button click)", () => {
expect(
hasInboundUserContent({

View File

@@ -456,7 +456,7 @@ function hasInteractiveResponseContent(message: proto.IMessage | undefined): boo
}
/**
* Fast O(1) check that a Baileys message carries user-visible inbound content
* Fast check that a Baileys message carries user-visible inbound content
* (text, media, contact, location, button/list selection). Returns false for
* protocol/receipt/typing notifications that arrive on the same
* `messages.upsert` stream as real messages but should not trigger pairing
@@ -472,19 +472,13 @@ export function hasInboundUserContent(rawMessage: proto.IMessage | undefined): b
if (extractMediaPlaceholder(rawMessage)) {
return true;
}
if (extractContactContext(rawMessage)) {
return true;
}
if (extractLocationData(rawMessage)) {
return true;
}
if (hasInteractiveResponseContent(rawMessage)) {
return true;
}
// Walk wrappers (ephemeral, viewOnce, etc.) — interactive responses
// can arrive nested.
for (const candidate of buildMessageChain(rawMessage)) {
if (candidate !== rawMessage && hasInteractiveResponseContent(candidate)) {
if (hasInteractiveResponseContent(candidate)) {
return true;
}
}