Build a simple voicemail
This guide composes sessions, playback, recording, webhooks, and S3-backed message storage. The examples use JavaScript-like pseudocode.
Mailbox state
The DID is selected by application routing. The application only needs the approved listener number and the saved message references:
Choose the call path
The application answers the session, waits for the confirmation event, and
then chooses the path from caller_id:
Phone numbers arrive in the canonical format described in Formats.
Play saved messages
Create a fresh, time-bounded S3 URL for each message. Start the next message only after the previous playback has stopped:
The playback/play response is 202 Accepted with an operation_uuid.
The matching webhook event is the completion signal; the HTTP response only
confirms that the command was accepted.
Record a message and store it in S3
The application starts recording, stops it on a caller action or timeout, and
stores the completed recording only after recording.ended:
Store the S3 object key as durable state. Generate a fresh playback URL when the message is played; recording URLs expire.
Command and event rules
Every command follows the same shape:
Deduplicate webhook deliveries before changing mailbox state. On
playback.failed, recording.failed, or call.ended, cancel pending timers,
avoid saving unconfirmed recordings, and mark the session terminal.