# 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]
>
> `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](/docs/content/using-variables-with-content-api).

## Supported channels

* WhatsApp
* Facebook Messenger

## Channels specific information

### WhatsApp

* `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](/docs/content/using-variables-with-content-api).
* 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`.
* If your template contains more than one button, you must submit it for approval.
* For unapproved cards used during a session, the following rules apply:
  * Only the buttons types `QUICK_REPLY`, `URL`, `VOICE_CALL_REQUEST` and `VOICE_CALL` are supported. Templates that include a `PHONE_NUMBER` button type are not supported.
  * If you send a Content resource that contains buttons with different action types within a session in an unapproved template, the request fails. WhatsApp requires every button in an in session message to use the same action type. For example, an unapproved template that includes both a `voice\_call` button and a`url` button fails validation.
  * There can only be one URL button in the Content. For example, a Content with two URL buttons will fail.

## Message preview

![Owl Air flight details with links to check flight status and weather.](https://docs-resources.prod.twilio.com/ea74ae58324d0f07001d49600e71667bad4b2d294a7411a1bf64992ee18d4e01.png)

## Data parameters

| Parameter | Type   | Required | [Variable support](/docs/content/using-variables-with-content-api) | Description                                                                                                                |
| --------- | ------ | -------- | ------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
| `body`    | string | Yes      | Yes                                                                | The text of the message you want to send. This is included as a regular text message. <br />Maximum length: 640 characters |
| `actions` | array  | Yes      | Yes                                                                | Call to action content templates support `URL`, `PHONE`, `COPY_CODE`, and `VOICE_CALL` buttons.                            |

### `actions` properties

To learn more about see \[common components], see [common components](/docs/content/content-types-overview#common-components).

> \[!NOTE]
>
> 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.

| Property             | Supported channels                                    | Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| -------------------- | ----------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `URL`                | <ul><li>WhatsApp</li><li>Facebook Messenger</li></ul> | <ul><li>**`type`**: `URL`</li><li>**`title`**: Button text of URL redirect button. Variables aren't supported. <br />Maximum length: 20 characters</li><li>**`url`**: URL opened when the user clicks the button. Variables are supported at the end of the URL string.</li></ul>                                                                                                                                                                                                 |
| `PHONE`              | <ul><li>WhatsApp</li><li>Facebook Messenger</li></ul> | <ul><li>**`type`**: `PHONE`</li><li>**`title`**: Button text of URL redirect button. Variables aren't supported. <br />Maximum length: 20 characters</li><li>**`phone`**: [E.164](/docs/glossary/what-e164) formatted phone number to call when the recipient taps the button. Variables aren't supported.</li></ul>                                                                                                                                                              |
| `VOICE_CALL`         | WhatsApp                                              | <ul><li>**`type`**: `VOICE_CALL`</li><li>**`title`**: Button text of VoIP call button. Variables aren't supported. <br />Maximum length: 20 characters</li><li>**`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).</li></ul> |
| `VOICE_CALL_REQUEST` | WhatsApp                                              | <ul><li>**`type`**: `VOICE_CALL_REQUEST`</li></ul>                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `COPY_CODE`          | WhatsApp                                              | <ul><li>**`type`**: `COPY_CODE`</li><li>**`title`**: Button text of copy code button. Variables aren't supported. <br />Maximum length: 20 characters</li><li>**`code`**: Coupon code that is copied to end user clipboard after clicking button. Variables are supported.</li></ul>                                                                                                                                                                                              |

## Code examples and responses

Create a Call-To-Action template

```cs
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Content.V1;

     TwilioClient.Init(accountSid, authToken);

    // define the twilio/call-to-action type
    var twilioCallToAction = new TwilioCallToAction.Builder();
    twilioCallToAction.WithBody("Owl Air: We will see you soon! Flight {{1}} to {{2}} departs at {{3}} from Gate {{4}}.");
    var cta1 = new CallToAction.Builder()
        .WithType(CallToActionActionType.Url)
        .WithUrl("https://owlair.com/{{5}}")
        .WithTitle("Check Flight Status")
        .Build();
    var cta2 = new CallToAction.Builder()
        .WithType(CallToActionActionType.PhoneNumber)
        .WithPhone("+15555551234")
        .WithTitle("Call Support")
        .Build();
    twilioCallToAction.WithActions(new List<CallToAction>() { cta1, cta2 });

    // define all the content types to be part of the template
    var types = new Types.Builder();
    types.WithTwilioCallToAction(twilioCallToAction.Build());

    // build the create request object
    var contentCreateRequest = new ContentCreateRequest.Builder();
    contentCreateRequest.WithTypes(types.Build());
    contentCreateRequest.WithLanguage("en");
    contentCreateRequest.WithFriendlyName("owl_air_cta");
    contentCreateRequest.WithVariables(new Dictionary<string, string>() { {"1", "flight_number"}, {"2", "arrival_city"}, {"3", "departure_time"}, {"4", "gate_number"}, {"5", "url_suffix"} });
    
    // create the twilio template
    var contentTemplate = await CreateAsync(contentCreateRequest.Build());

    Console.WriteLine($"Created Twilio Content Template SID: {contentTemplate.Sid}");
```

```java
package Examples;

import com.twilio.rest.content.v1.Content;
import java.util.Arrays;
import java.util.Map;

public class TwilioCallToAction {
    public static String CreateTemplate() {
        var twilioCallToAction = new Content.TwilioCallToAction();
        twilioCallToAction.setBody("Owl Air: We will see you soon! Flight {{1}} to {{2}} departs at {{3}} from Gate {{4}}.");

        var action1 = new Content.CallToActionAction();
        action1.setType(Content.CallToActionActionType.URL);
        action1.setUrl("https://owlair.com/{{5}}");
        action1.setTitle("Check Flight Status");

        var action2 = new Content.CallToActionAction();
        action2.setType(Content.CallToActionActionType.PHONE_NUMBER);
        action2.setPhone("+18005551234");
        action2.setTitle("Call Support");

        twilioCallToAction.setActions(Arrays.asList(action1, action2));

        var types = new Content.Types();
        types.setTwilioCallToAction(twilioCallToAction);

        var createRequest = new Content.ContentCreateRequest("en", types);
        createRequest.setFriendlyName("owl_air_cta");
        createRequest.setVariables(Map.of(
        "1", "flight_number",
        "2", "arrival_city",
        "3", "departure_time",
        "4", "gate_number",
        "5", "url_suffix"
        ));

        var content = Content.creator(createRequest).create();

        return content.getSid();
    }
}
```

```bash
curl -X POST 'https://content.twilio.com/v1/Content' \
-H 'Content-Type: application/json' \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN \
-d '{
  "friendly_name": "owl_air_cta",
  "language": "en",
  "variables": {"1": "flight_number", 
                "2": "arrival_city",
                "3": "departure_time",
                "4": "gate_number",
                "5": "url_suffix"}, 
  "types": {
    "twilio/call-to-action": {
      "body": "Owl Air: We will see you soon! Flight {{1}} to {{2}} departs at {{3}} from Gate {{4}}.",
      "actions": [{
          "type": "URL",
          "title": "Check Flight Status",
          "url": "https://owlair.com/{{5}}"
        },
        {
          "type": "PHONE_NUMBER",
          "title": "Call Support",
          "phone": "+15555551234"
      }]
    }
  }
}'
```

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