feat: WhatsApp BSUID support in Messages API (DEVX-11482) - #627
feat: WhatsApp BSUID support in Messages API (DEVX-11482)#627dragonmantank wants to merge 2 commits into
Conversation
WhatsApp users who adopt a username are identified by a business-scoped user ID (BSUID) instead of, or in addition to, a phone number. - Outbound: WhatsApp 'to' now accepts a BSUID or parent BSUID as well as a phone number (new Bsuid validation helper; WhatsappRequest recipient validation relaxed accordingly). - Inbound: added whatsapp.sender via InboundMessage.getWhatsappSender() (shared WhatsappUser model: user_id/parent_user_id/wa_id). - Status: added whatsapp.recipient via MessageStatus.getWhatsappRecipient() and WhatsApp profile via getWhatsappProfile(). - Profile: added getUsername().
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #627 +/- ##
=========================================
Coverage 99.05% 99.05%
- Complexity 3643 3656 +13
=========================================
Files 548 549 +1
Lines 8052 8068 +16
Branches 445 446 +1
=========================================
+ Hits 7976 7992 +16
Misses 56 56
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
superchilled
left a comment
There was a problem hiding this comment.
Looks good overall. My only question is whether we maybe want to be more permissive wrt the to field, e.g. allow any string input regardless of format. The current logic of sanitizeRecipient checks if the input is either in E.164 format or matches the defined regex for BSUID format.
This is fine given the current known parameters of what can be specified as the recipient for a WhatsApp message, but:
- We know from previous experience that Meta has a habit of regularly changing their API and definitions, so the current BSUID format may be subject to change in the future
- Other valid formats for the
tofield will require support in the future. For example, we already know that WhatsApp group messaging is on the Messages API product roadmap, and the group ID again has a different format
Per review feedback: validating 'to' against a client-side BSUID regex risks rejecting recipients that Meta accepts if they loosen the format, forcing an urgent SDK release. Instead, normalise E.164 phone numbers and pass any other non-empty recipient (e.g. a BSUID) through unchanged; the API validates and rejects genuinely unsupported values (error 131062). Removes the Bsuid validation class and its test.
|
Updated per review feedback (commit Dropped the bespoke New behaviour for WhatsApp
The API validates the recipient and returns error |
Summary
Adds support for WhatsApp business-scoped user IDs (BSUIDs) to the Messages API. When a WhatsApp user adopts a username, Meta may identify them by a BSUID instead of (or in addition to) a phone number. This PR lets the SDK send to BSUID recipients and parse the new BSUID fields on inbound messages and status callbacks.
Reference: Handling WhatsApp Usernames and BSUIDs
Changes
Outbound (send)
tonow accepts a BSUID or parent BSUID as well as an E.164 phone number.Bsuidvalidation helper — format{ISO alpha-2}.{≤128 alphanumeric}(e.g.US.13491208655302741918) and parent BSUID{CC}.ENT.{id}(e.g.US.ENT.11815799212886844830).WhatsappRequestrecipient validation relaxed viasanitizeRecipient()(accepts E.164 or BSUID);fromremains E.164.Inbound webhook
whatsapp.senderobject exposed viaInboundMessage.getWhatsappSender().Profile.getUsername()added.Status callback
whatsapp.recipientobject exposed viaMessageStatus.getWhatsappRecipient().profileexposed viaMessageStatus.getWhatsappProfile()(includes username).Shared model
WhatsappUser(user_id= BSUID,parent_user_id= parent BSUID,wa_id= phone number) used by bothwhatsapp.senderandwhatsapp.recipient.Tests
BsuidTest(valid/parent/max-length/malformed/null cases).WhatsappTextRequestTest.whatsapp.recipient+profile.usernameparsing inMessageStatusTest.whatsapp.sender+profile.usernameparsing inInboundMessageTest.mvn testrun passed (1465 tests, 0 failures).Notes
@sincetags use9.13.0(next version after the released 9.12.0).pom.xmlversion bump not included — assumed handled at release time viabumpversion.sh.