Skip to contentSkip to navigationSkip to topbar
On this page

TwiML™ Voice: <WhatsApp>


(new)

Beta

WhatsApp Business Calling is in Private Beta. The information in this document could change. We might add or update features before the product becomes Generally Available. Beta products don't have a Service Level Agreement (SLA). Learn more about beta product support(link takes you to an external page).

The <Dial> verb's <WhatsApp> noun lets you set up VoIP sessions to clients using the WhatsApp(link takes you to an external page) consumer application. With this feature, you can send a call to any WhatsApp endpoint, after first establishing consent using a WhatsApp message template. Set up your TwiML to use the <WhatsApp> noun within the <Dial> verb to connect a Voice call to a WhatsApp client. If you are unfamiliar with WhatsApp Business Calling, or want more information on how Twilio works with WhatsApp, see the Twilio WhatsApp Business Platform documentation.


Basic usage

basic-usage page anchor

The TwiML example below shows the basic TwiML syntax of <Dial><WhatsApp>.

1
<?xml version="1.0" encoding="UTF-8"?>
2
<Response>
3
<Dial callerId="whatsapp:+558551234567">
4
<WhatsApp>+555551234567</WhatsApp>
5
</Dial>
6
</Response>
(information)

Info

All WhatsApp calls must use a callerId set to a registered, Voice-activated WhatsApp sender in the format whatsapp:{sender} on the originating Twilio account.



<WhatsApp> attributes

whatsapp-attributes page anchor

The <WhatsApp> noun supports the following attributes that modify its behavior:

Attribute nameAllowed valuesDefault value
urlAny URLnone
methodGET, POSTPOST
statusCallbackEventinitiated, ringing, answered, completednone
statusCallbackAny URLnone
statusCallbackMethodGET, POSTPOST

WhatsApp destination numbers specified in the noun should be formatted in E.164 format with a + and country code, for example: +16175551212.

url attribute

attributes-url page anchor

The url attribute allows you to specify a URL that will return a TwiML response to be run on the called party's end, after they answer, but before the parties are connected.

You can use this TwiML to privately <Play> or <Say> information to the called party. You could also provide a chance to decline the phone call using <Gather> and <Hangup>. The url attribute doesn't support any other TwiML verbs.

If the answerOnBridge attribute is used on <Dial>, the current caller will continue to hear ringing while the TwiML document executes on the other end. TwiML documents executed in this manner are not allowed to contain the <Dial> verb.

The method attribute allows you to specify which HTTP method Twilio should use when requesting the URL in the url attribute. The default is POST.

statusCallbackEvent attribute

attributes-statuscallbackevent page anchor

When dialing out to a number using <Dial>, an outbound call is initiated. The call transitions from the initiated state to the ringing state when the phone starts ringing. It transitions to the answered state when the call is picked up, and finally to the completed state when the call is over.

With statusCallbackEvent, you can subscribe to receive webhooks for the different call progress events for a given call: initiated, ringing, answered, or completed. Non-relative URLs must contain a valid hostname. Underscores aren't permitted.

The statusCallbackEvent attribute allows you to specify which events Twilio should trigger a webhook on. To specify multiple events, separate them with a space: initiated ringing answered completed. If a statusCallback is provided and no statusCallbackEvent events are specified, the completed event will be sent by default.

As opposed to creating an outbound call via the API, outbound calls created using <Dial> are initiated right away and never queued. The following shows a timeline of possible call events that can be returned and the different call statuses that a <Dial> leg may experience:

Outbound Dial call events diagram.
EventDescription
initiatedThe initiated event is fired when Twilio starts dialing the call.
ringingThe ringing event is fired when the call starts ringing.
answeredThe answered event is fired when the call is answered.
completedThe completed event is fired when the call is completed, regardless of the termination status: busy, canceled, completed, failed, or no-answer. If no statusCallbackEvent is specified, completed will be fired by default.

The statusCallback attribute allows you to specify a URL for Twilio to send webhook requests to on each event specified in the statusCallbackEvent attribute.

statusCallbackMethod attribute

attributes-statuscallbackmethod page anchor

The statusCallbackMethod attribute allows you to specify which HTTP method Twilio should use when requesting the URL in the statusCallback attribute. The default is POST.

Status callback HTTP parameters

status-callback-http-parameters page anchor

The parameters Twilio passes to your application in its asynchronous request to the statusCallback URL include all parameters passed in a synchronous request to retrieve TwiML when Twilio receives a call to one of your Twilio numbers. The full list of parameters and descriptions of each are in the TwiML Voice Request documentation.

When the call progress events are fired, the statusCallback request also passes these additional parameters:

ParameterDescription
CallSidUnique identifier for this call that Twilio generates. To modify the child call, make a POST request to Calls/{CallSid} with a new TwiML URL.
ParentCallSidA unique identifier for the parent call.
CallStatusA descriptive status for the call. The value is one of queued, initiated, ringing, in-progress, busy, failed, or no-answer. See the CallStatus section for more details.
CallDurationThe duration in seconds of the just-completed call. Only present in the completed event.
RecordingUrlThe URL of the phone call's recorded audio. This parameter is included only if record is set on the <Dial> and does not include recordings initiated in other ways. RecordingUrl is only present in the completed event.
RecordingSidThe unique ID of the Recording from this call. RecordingSid is only present in the completed event.
RecordingDurationThe duration of the recorded audio (in seconds). RecordingDuration is only present in the completed event. To get a final accurate recording duration after any trimming of silence, use recordingStatusCallback.
TimestampThe timestamp when the event was fired, given as UTC in RFC 2822(link takes you to an external page) format.
CallbackSourceA string that describes the source of the webhook. This is provided to help disambiguate why the webhook was made. On Status Callbacks, this value is always call-progress-events.
SequenceNumberThe order in which the events were fired, starting from 0. Although events are fired in order, they are made as separate HTTP requests, and there is no guarantee they will arrive in the same order.