feat(whatsapp): send outbound files and attachments via Cloud API#537
Open
scopsy wants to merge 3 commits into
Open
feat(whatsapp): send outbound files and attachments via Cloud API#537scopsy wants to merge 3 commits into
scopsy wants to merge 3 commits into
Conversation
Implement media upload, MIME mapping, caption fallbacks, and card+file sequencing. Add shared PlatformName support for whatsapp buffer utilities.
Contributor
|
@scopsy is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
Implement outbound file and attachment sending for the WhatsApp adapter and update docs. Changes include: adding WhatsApp file/attachment handling in the adapter (binary uploads, sequential multi-file sends, caption rules, card+file sequencing), introducing a typed WHATSAPP_BUFFER_PLATFORM constant to pass to toBuffer, and minor code flow/comments around interactive cards and text messages. Documentation updated with a WhatsApp file uploads section and removed an earlier WhatsApp note from the shared files guide. Also remove WhatsApp from the shared PlatformName/button-style mapping so the adapter asserts the platform label where needed.
Fix logic that caused duplicate text to be sent when posting a card with an attached file by changing the conditional to only skip sending text when the text is empty. Add a unit test that posts a card with a file and verifies only one media upload and one message are sent and that the media caption contains the card title. This ensures the adapter does not send duplicate textual fallbacks alongside media.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement media upload, MIME mapping, caption fallbacks, and card+file sequencing.
Summary
The WhatsApp adapter previously ignored
filesandattachmentson outboundpost()calls (only text and interactive cards were sent). This PR implements full outbound media support via the WhatsApp Cloud API:POST /{phoneNumberId}/media→media_id→ typed media messageAttachment.urlsent directly (no upload)Packages:
@chat-adapter/whatsapp(minor)Supported inputs
files: FileUpload[]filenameand optionalmimeType. Always uploaded via/media.attachments: Attachment[]image|file|video|audio). Binary viadata/fetchData, or HTTPS URL-only viaurl.Both can be combined on
{ markdown },{ raw },{ ast }, or{ card }postables.filesare processed first, thenattachments.Examples
Behavior reference
Message flow (with media)
Multi-file
WhatsApp allows one media object per API message. Multiple
filesorattachmentsin a singlepost()produce N sequential messages. The returnedRawMessageis the last one sent (same convention as long-text chunking).Caption placement
audio, media supports captionsaudiomarkdown: "", files only)MIME type → WhatsApp message type
typeimage/jpeg,image/pngimageimage/*(e.g. GIF, WebP, SVG)documentvideo/mp4,video/3gppvideoaudio/*audiodocumentFor
AttachmentwithoutmimeType, the adapter usesattachment.type(image→ image,file→ document, etc.), then applies MIME rules whenmimeTypeis set.Size limits (pre-flight)
Throws
ValidationErrorwhen binary size is known (before upload):imageaudiovideodocumentURL-only attachments skip size validation unless
attachment.sizeis provided.Card + files
When both a card and files/attachments are present:
cardToFallbackText(card)on the first media itemCard image vs
files(important)<Image>child orcard.imageUrlonly (nofiles)files/attachments+ card with buttonsTo send a photo with buttons, pass the image via
filesorattachments, not only as a card image child.Link passthrough
Attachmentwith onlyurl(nodata/fetchData) →{ link: url }in the media payloadhttps:///mediaupload callBinary resolution
FileUpload.datatoBuffer()→uploadMedia()→{ id }Attachment.data/fetchDataAttachment.urlonly{ link }passthroughOut of scope (follow-ups)
voicevsaudiodistinction)files)/mediaTest plan
Automated
pnpm --filter @chat-adapter/whatsapp test— 127 tests (10 new file-upload cases + MIME mapping table)pnpm validate(run before merge)Manual
Video
Area.mp4
Checklist
pnpm validatepasses.changeset/whatsapp-outbound-files.mdpackages/adapter-whatsapp/AGENTS.md,apps/docs/content/docs/files.mdx