Audio in WhatsApp agents: receive and transcribe
How an AI agent handles audio on WhatsApp: the audio webhook, downloading the media, transcription, graceful failure and sending voice.
On WhatsApp, many people prefer talking to typing. An agent that only understands text and replies that it only reads text loses part of its customers and reinforces the bot feeling. Handling audio is possible with simple parts, but each one has a deadline, a limit or a rule you need to know before going to production.
How does an audio message reach the agent?
It arrives as a message of type audio, with no text, carrying a media identifier you use to download the file. The webhook does not carry the audio itself, only its metadata. The message text comes empty, so an agent that reads only the text field sees a null message.
According to Meta’s webhook reference, the audio object has four fields: id, the media identifier used to request the download URL; mime_type, such as audio/ogg; codecs=opus; sha256, the file hash; and voice, a boolean that is true when the audio was recorded with the app’s voice recording feature and false when it was sent as an audio file. Through CRPRO Hub, the message.received event carries the type and the id in data.content.media. If you depend on the voice field, check whether it appears in the raw object at data.message in your event, because that is Meta’s format.
What are the deadlines and limits for downloading the file?
The most important deadline is the id’s: according to Meta’s media documentation, media ids received in webhooks expire in 7 days. The download URL Meta returns for an id is valid for 5 minutes, and the download request must carry the access token or it fails.
- The id comes in the webhook and is valid for 7 days. Download while processing the event, not later.
- Meta’s temporary URL is valid for 5 minutes. If the download returns 404, request a new URL for the same id and retry.
- Media received from customers can reach 100 MB; beyond that Meta raises error 131052. For audio you send, the limit is 16 MB.
Through Hub you do not deal with the temporary URL: the route GET /api/v1/channels/{id}/media/{mediaId} downloads the file, and the response is the binary, with no envelope. Because the media disappears from Meta in a few days, keeping just the id does not help; keep the file or the transcript, according to your retention policy. The webhooks reference lists the events.
How do you turn audio into something the agent understands?
The portable way is to transcribe first: convert the audio to text with a speech recognition service and hand that text to the model as if the customer had typed it. Whether the language model you use accepts audio directly depends on the provider, so check its documentation; transcribing first works with any text model and leaves the rest of the agent intact.
// Inside the worker: the event arrived as audio
async function textoDaMensagem(evento) {
const c = evento.data.content
if (c?.type !== 'audio') return evento.data.text // plain text
const midia = c.media // { id, mime_type, sha256, ... }
// Download right away: the webhook media id expires in 7 days (Meta) and the file
// comes through Hub, authenticated, at /media/{id}.
const r = await fetch(
'https://crprohub.com/api/v1/channels/' + evento.channel_id + '/media/' + midia.id,
{ headers: { Authorization: 'Bearer ' + process.env.CRPRO_API_KEY } },
)
if (!r.ok) return null
const arquivo = Buffer.from(await r.arrayBuffer())
// Transcription: the provider is your choice; the contract is audio -> text
const t = await transcrever(arquivo, midia.mime_type)
if (!t.texto || t.confianca < 0.6) return null // better to ask than to guess
return t.texto
}
// In the agent: the transcript enters as a customer message, marked as such
const texto = await textoDaMensagem(evento)
if (texto === null) {
return enviarTexto(evento, 'I could not understand the audio. Could you type or record it again?')
}
const entrada = '[transcribed audio] ' + textoThe snippet makes three decisions. The transcript only proceeds if confidence is high enough, because a transcription error becomes a wrong answer stated with certainty; the 0.6 threshold is an example and must be calibrated with your audio. The message sent to the model is marked as a transcript, so it knows errors are possible and asks for confirmation when a critical datum, such as an order number, appears. And on failure, the agent asks the customer to type or record again instead of guessing.
How do you handle bad, long or blank audio?
Treat it as a normal case, not an exception. Noisy, silent or very long audio is frequent, and the correct behavior is to ask for another attempt or offer a person, never to invent an answer.
- Maximum duration: set a limit you can support in cost and time, and tell the customer if it is exceeded.
- Silence or noise: empty or very short text should lead to the retry message.
- Language: if you serve more than one language, configure recognition for the ones you expect.
- Confirmation on critical data: repeat the number, date or amount for the customer to confirm before acting.
- Queue: transcribing takes time. Keep it all in the worker, outside the webhook’s 10-second deadline.
The extra time also weighs on the experience. Meta’s typing indicator, which stays visible until you reply or for 25 seconds, helps signal the agent is working; the latency article in this series covers it.
Can the agent reply with audio?
It can, but rarely should. Replying by voice requires an audio in the right format and adds a speech synthesis step; for most support conversations, text is faster, cheaper and easier to review. Reply in text unless the context calls for voice.
If it does, Meta’s audio messages documentation defines: accepted formats are AAC, AMR, MP3, M4A and OGG; OGG files must use the OPUS codec in mono; the limit is 16 MB. For the message to show as a voice message, send type audio with voice set to true and an OGG file with OPUS, otherwise transcription fails. The play icon only appears for files up to 512 KB, and above that the person sees a download icon. Hub validates the audio object strictly and accepts only id or link; the voice field is not passed through, and a request that includes it is rejected as an invalid message. Through Hub, audio goes out as a regular audio file; see the quickstart and the reference. The voice-message behavior applies to those who send directly through Meta’s API.
The most common errors come from a MIME type that does not match the extension and OGG that is not OPUS. Validate the file before sending.
Frequently asked questions
Does the webhook carry the audio file?
No. It carries the media id and metadata such as mime_type and sha256. The file is downloaded afterwards, by id, and in Hub that is done on the channel’s media route.
For how long can I download a received audio?
According to Meta, a webhook media id expires in 7 days, and the download URL obtained from it is valid for 5 minutes. Download while processing the event.
Do I need to transcribe the audio or does the model understand it directly?
Transcribing works with any text model. Direct audio support depends on the model you use; check your provider’s documentation.
How do I know whether the audio was recorded in WhatsApp or sent as a file?
Meta’s audio object has voice: true for in-app recording and false for a file. Check that the field reaches your event.
Fontes
Documentação oficial da Meta, conferida em 31 de outubro de 2026.