When this matters
Inbound media handling is essential for:- Saving customer-uploaded PDFs, receipts, or invoices.
- Processing user-submitted photos or videos for customer support.
- Archiving voice notes (
audiomessages) for transcription or QA.
Processing flow
Downloading user-submitted media involves three main steps:1. Detect media webhook
Wazapin POSTs a lightweightmessage.new webhook with a msg_type set to image, video, audio, document, or sticker.
Here is an example webhook payload for an inbound image:
Inbound image webhook body
2. Fetch the media URL
Call GET /v1/messages/ using themessage_id from the payload. The API response will contain the content block with a direct download link:
- For images/videos/audio/documents:
content.media_url - For stickers:
content.sticker_url
3. Download the file
Stream the binary content frommedia_url (or sticker_url) to your local file system, AWS S3, Google Cloud Storage, or other storage provider.
Code example
Here is how to catch the webhook, get the message details, and download the file:Channel support
Both official and unofficial channels support inbound media messages.- Official Channels: Handled via Meta’s secure media servers. Direct download URLs are proxy links provided by Wazapin and include expiring tokens.
- Unofficial Channels: Pairs with WhatsApp Web to cache and upload media assets to Wazapin’s cloud store.
Troubleshooting
Expired media URLs
Wazapin media download URLs contain temporary access tokens. To prevent broken links, download the files immediately upon receiving the webhook. Do not store themedia_url in your database expecting it to work indefinitely.
Wrong content-type or extensions
Wazapin proxy endpoints attempt to resolve correct MIME types and extensions. However, always validate the magic bytes or Content-Type headers when writing files to disk (e.g., verifying a.png file has png headers) to prevent execution vulnerabilities.