Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

twilio/call-to-action


Twilio/call-to-action buttons let recipients tap to trigger actions such as launching a website or making a phone call.

(information)

Info

Call-to-action buttons can only be sent via WhatsApp as approved templates.

If you are using a URL button and want to submit the 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.

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 templates can be sent via WhatsApp for out of session messages with variables. If the template's body starts or ends with a variable or has two variables next to each other, the template will not be approved by WhatsApp without a sample variable. For additional information about variables see Using Variables with Content Templates.


Supported Channels

supported-channels page anchor

WhatsApp, Facebook Messenger


Content Api - CTA preview.

body:

  • Type: string
  • Required: yes
  • Variable Support: yes
  • Description: The text of the message you want to send. This is included as a regular text message.

    • Maximum 640 characters

actions:

  • Type: array[ actions ]
  • Required: yes
  • Variable Support: See Common Components: Actions definition
  • Description: Buttons that recipients can tap on to act on the message:

    • Up to 2 buttons for Call-to-Action button types: PHONE_NUMBER or URL. Please note only a single PHONE_NUMBER or URL button can be used at a time. If two buttons are used, one must be a URL and the other a PHONE_NUMBER.
    • Please use "type" and "title" actions to create call-to-action buttons within the actions array.

Create a Call-To-Action Template

create-a-call-to-action-template page anchor
C#
Java
curl

_38
// Install the C# / .NET helper library from twilio.com/docs/csharp/install
_38
_38
using System;
_38
using Twilio;
_38
using Twilio.Rest.Content.V1;
_38
_38
TwilioClient.Init(accountSid, authToken);
_38
_38
// define the twilio/call-to-action type
_38
var twilioCallToAction = new TwilioCallToAction.Builder();
_38
twilioCallToAction.WithBody("Owl Air: We will see you soon! Flight {{1}} to {{2}} departs at {{3}} from Gate {{4}}.");
_38
var cta1 = new CallToAction.Builder()
_38
.WithType(CallToActionActionType.Url)
_38
.WithUrl("https://owlair.com/{{5}}")
_38
.WithTitle("Check Flight Status")
_38
.Build();
_38
var cta2 = new CallToAction.Builder()
_38
.WithType(CallToActionActionType.PhoneNumber)
_38
.WithPhone("+15555551234")
_38
.WithTitle("Call Support")
_38
.Build();
_38
twilioCallToAction.WithActions(new List<CallToAction>() { cta1, cta2 });
_38
_38
// define all the content types to be part of the template
_38
var types = new Types.Builder();
_38
types.WithTwilioCallToAction(twilioCallToAction.Build());
_38
_38
// build the create request object
_38
var contentCreateRequest = new ContentCreateRequest.Builder();
_38
contentCreateRequest.WithTypes(types.Build());
_38
contentCreateRequest.WithLanguage("en");
_38
contentCreateRequest.WithFriendlyName("owl_air_cta");
_38
contentCreateRequest.WithVariables(new Dictionary<string, string>() { {"1", "flight_number"}, {"2", "arrival_city"}, {"3", "departure_time"}, {"4", "gate_number"}, {"5", "url_suffix"} });
_38
_38
// create the twilio template
_38
var contentTemplate = await CreateAsync(contentCreateRequest.Build());
_38
_38
Console.WriteLine($"Created Twilio Content Template SID: {contentTemplate.Sid}");

Output

_37
{
_37
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_37
"date_created": "2022-01-15T17:09:58Z",
_37
"date_updated": "2022-01-15T17:09:58Z",
_37
"friendly_name": "owl_air_cta",
_37
"language": "en",
_37
"links": {
_37
"approval_fetch": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests",
_37
"approval_create": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests/whatsapp"
_37
},
_37
"sid": "HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_37
"types": {
_37
"twilio/call-to-action": {
_37
"actions": [
_37
{
_37
"url": "https://owlair.com/{{5}}",
_37
"type": "URL",
_37
"title": "Check Flight Status"
_37
},
_37
{
_37
"phone_number": "+15555551234",
_37
"type": "PHONE_NUMBER",
_37
"title": "Call Support"
_37
}
_37
],
_37
"body": "Owl Air: We will see you soon! Flight {{1}} to {{2}} departs at {{3}} from Gate {{4}}."
_37
}
_37
},
_37
"url": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_37
"variables": {
_37
"1": "flight_number",
_37
"3": "departure_time",
_37
"2": "arrival_city",
_37
"5": "url_suffix",
_37
"4": "gate_number"
_37
}
_37
}


Rate this page: