Repository navigation
fix(whatsapp): model forwarded and product-inquiry context variants in WhatsAppInboundMessage - #723
Conversation
|
@ricardolx is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
The inbound message context type declared `from` and `id` as required, but Meta sends mutually exclusive context shapes: quoted replies carry from/id, forwarded messages carry only forwarded/frequently_forwarded, and catalog product inquiries add referred_product. Code narrowed by the old type dereferences context.id and crashes on forwarded messages. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Ricardo Rivero <ricardo@enzadon.com>
048d968 to
c8dfa6c
Compare
|
Reopening this — I closed it prematurely shortly after opening, which was a mistake on my part. The underlying issue is still present on Rebased onto current Happy to adjust the shape if you'd prefer a discriminated union over all-optional fields. |
Problem
WhatsAppInboundMessage.contextis typed as:But Meta's Cloud API webhook sends mutually exclusive context shapes depending on message origin (text messages webhook reference):
from+idforwarded("only included if forwarded 5 times or less") orfrequently_forwarded("only included if forwarded more than 5 times") — noid, nofromfrom+id+referred_productBecause the type declares
idrequired whenevercontextis present, downstream code likemessage.raw.message.context?.id.trim()type-checks cleanly and then throws aTypeErrorat runtime the first time a user forwards a message to the bot —contextexists,iddoesn't. We hit exactly this in production code building reply-to handling on top of the adapter.Change
contextfields are optional, and the forwarded/product-inquiry fields (forwarded,frequently_forwarded,referred_product) are added, with doc comments noting which variant each field belongs to.@chat-adapter/whatsapp: patch).The adapter itself never reads
contextat runtime, so this is a type-only change. Consumers who currently dereferencecontext.idunguarded will get a compile error after upgrading — intentionally, since that code is a latent runtime crash on forwarded messages.🤖 Generated with Claude Code