twilio/call-to-action


The twilio/call-to-action buttons let recipients tap to trigger actions such as launching a website, copying a coupon code, or making a phone call.

If you are using a URL button and want to submit the content template for WhatsApp approval, the URL must resolve to a publicly accessible website. If there is a variable, a valid path sample should be included in the variables array. The combined URL should resolve to a publicly accessible website.

For example, "url": ["https://www.twilio.com/{{1}}"] would include a path sample in the variables definition: "variables": {"1": "docs"}.

(warning)

Warning

Twilio/call-to-action content templates can be sent via WhatsApp for out of session messages with variables. If the content template's body starts or ends with a variable, it won't be approved by WhatsApp. The same applies if two variables are placed next to each other. A sample variable is required. For additional information about variables, see Using Variables with Content Templates.


  • WhatsApp
  • Facebook Messenger

Channels specific information

channels-specific-information page anchor
  • VOICE_CALL and VOICE_CALL_REQUEST are currently a private beta feature in select regions.
  • If the content template is being sent in session over WhatsApp without approval, only three buttons are allowed.
  • On WhatsApp, a card must be approved as a content template before it can be sent. Additional approval steps are required if you use variables with twilio/card. A valid media sample is required if a twilio/card content template is created with media and/or variables and you plan to submit this template to WhatsApp for approval. Static media URLs should resolve to publicly hosted media files. Variable media URLs should include a valid media URL suffix in the variable declaration.
  • Each approved variable WhatsApp card template can include only one type of media. WhatsApp classifies approved templates into 1 of 3 types of media headers (Image, Video, Document) based on the sample that was submitted. Once the template has been approved another type of media header can't be sent using the template.
    • For example, if a content template is approved with an image, you can't send a video using that same content template.
  • If the content template's body starts or ends with a variable or has two variables next to each other, the content template won't be approved by WhatsApp without a sample variable. For additional information about variables, see Using Variables with Content Templates.
  • When creating your content template, ensure that the phone number in the actions array below is valid. Otherwise, the content template will fail to send.
  • WhatsApp footers translate to subtitles in twilio/cards.
  • Template approval is required if multiple buttons are present.

Content Api - CTA preview.

ParameterTypeRequiredVariable supportDescription
bodystringYesYesThe text of the message you want to send. This is included as a regular text message.
Maximum length: 640 characters
actionsarrayYesYesCall to action content templates support URL, PHONE, COPY_CODE, and VOICE_CALL buttons.

To learn more about see [common components], see common components.

(information)

Info

Limitations:

  • Only one of the two call options can be on a content template:
    • PHONE
    • VOICE_CALL
  • Up to two URL buttons are allowed.
  • Up to five quick reply buttons are allowed.
PropertySupported channelsParameters
URL
  • WhatsApp
  • Facebook Messenger
  • type: URL
  • title: Button text of URL redirect button. Variables aren't supported.
    Maximum length: 20 characters
  • url: URL opened when the user clicks the button. Variables are supported at the end of the URL string.
PHONE
  • WhatsApp
  • Facebook Messenger
  • type: PHONE
  • title: Button text of URL redirect button. Variables aren't supported.
    Maximum length: 20 characters
  • phone: E.164 formatted phone number to call when the recipient taps the button. Variables aren't supported.
VOICE_CALLWhatsApp
  • type: VOICE_CALL
  • title: Button text of VoIP call button. Variables aren't supported.
    Maximum length: 20 characters
  • ttl_minutes: Optional parameter. The lifespan of the button in minutes. After this time expires, the button can't be used to start a call to the business. You can use variables. The default is 10,080 minutes (7 days). The expected value is an integer between 1 and 43,200 minutes (30 days).
VOICE_CALL_REQUESTWhatsApp
  • type: VOICE_CALL_REQUEST
COPY_CODEWhatsApp
  • type: COPY_CODE
  • title: Button text of copy code button. Variables aren't supported.
    Maximum length: 20 characters
  • code: Coupon code that is copied to end user clipboard after clicking button. Variables are supported.

Code examples and responses

code-examples-and-responses page anchor
1
// Install the C# / .NET helper library from twilio.com/docs/csharp/install
2
3
using System;
4
using Twilio;
5
using Twilio.Rest.Content.V1;
6
7
TwilioClient.Init(accountSid, authToken);
8
9
// define the twilio/call-to-action type
10
var twilioCallToAction = new TwilioCallToAction.Builder();
11
twilioCallToAction.WithBody("Owl Air: We will see you soon! Flight {{1}} to {{2}} departs at {{3}} from Gate {{4}}.");
12
var cta1 = new CallToAction.Builder()
13
.WithType(CallToActionActionType.Url)
14
.WithUrl("https://owlair.com/{{5}}")
15
.WithTitle("Check Flight Status")
16
.Build();
17
var cta2 = new CallToAction.Builder()
18
.WithType(CallToActionActionType.PhoneNumber)
19
.WithPhone("+15555551234")
20
.WithTitle("Call Support")
21
.Build();
22
twilioCallToAction.WithActions(new List<CallToAction>() { cta1, cta2 });
23
24
// define all the content types to be part of the template
25
var types = new Types.Builder();
26
types.WithTwilioCallToAction(twilioCallToAction.Build());
27
28
// build the create request object
29
var contentCreateRequest = new ContentCreateRequest.Builder();
30
contentCreateRequest.WithTypes(types.Build());
31
contentCreateRequest.WithLanguage("en");
32
contentCreateRequest.WithFriendlyName("owl_air_cta");
33
contentCreateRequest.WithVariables(new Dictionary<string, string>() { {"1", "flight_number"}, {"2", "arrival_city"}, {"3", "departure_time"}, {"4", "gate_number"}, {"5", "url_suffix"} });
34
35
// create the twilio template
36
var contentTemplate = await CreateAsync(contentCreateRequest.Build());
37
38
Console.WriteLine($"Created Twilio Content Template SID: {contentTemplate.Sid}");

Output

1
{
2
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
3
"date_created": "2022-01-15T17:09:58Z",
4
"date_updated": "2022-01-15T17:09:58Z",
5
"friendly_name": "owl_air_cta",
6
"language": "en",
7
"links": {
8
"approval_fetch": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests",
9
"approval_create": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests/whatsapp"
10
},
11
"sid": "HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
12
"types": {
13
"twilio/call-to-action": {
14
"actions": [
15
{
16
"url": "https://owlair.com/{{5}}",
17
"type": "URL",
18
"title": "Check Flight Status"
19
},
20
{
21
"phone_number": "+15555551234",
22
"type": "PHONE_NUMBER",
23
"title": "Call Support"
24
}
25
],
26
"body": "Owl Air: We will see you soon! Flight {{1}} to {{2}} departs at {{3}} from Gate {{4}}."
27
}
28
},
29
"url": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
30
"variables": {
31
"1": "flight_number",
32
"3": "departure_time",
33
"2": "arrival_city",
34
"5": "url_suffix",
35
"4": "gate_number"
36
}
37
}