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

twilio/card


Twilio/card is a structured template which can be used to send a series of related information. It must include a title and at least one additional field.

(information)

Info

On WhatsApp, a card must be approved as a template before it can be sent. If you use variables with twilio/card, then additional approval steps are required. If a twilio/card template is created with media and with variables and you plan to submit this template to WhatsApp for approval, a valid media sample is required. Static media urls should resolve to publicly hosted media files. Variable media urls should include a valid media URL suffix in the variable declaration.

Only one type of media can be sent per approved variable WhatsApp card template. 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 cannot be sent using the template.

Ex. If a template is approved with an image then a video cannot be sent using the same template.

In the Media field of the template you create, provide the URL of the publicly hosted file.

If you are using a media in the card with a variable. Please submit a sample path of a publicly hosted image URL in the variable array. The combined URL must contain the file type. The combined URL must resolve to a publicly hosted file.

Example:

"media": ["https://twilio-cms-prod.s3.amazonaws.com/{{1}}"] would include a path sample in the variables definition. "variables": {"1": "images/library-logo-resource2x.width-1000.png"}

If you are using a call-to-action URL button in your card, 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

  • 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 here .
  • Update the phone number to a valid phone number in the actions array below when creating your template. This template will fail to send otherwise.
  • WhatsApp footers translate to subtitles in Twilio/cards.

Supported Channels

supported-channels page anchor

WhatsApp, Facebook Messenger


Screen Shot 2022-08-25 at 1.28.57 PM.

title:

  • Type: string
  • Required: yes
  • Variable Support: yes
  • Description: Title of card.

    • Maximum: 1024 characters

subtitle:

  • Type: string
  • Required: no
  • Variable Support: no
  • Description: Subtitle of card.

    • Maximum: 60 characters

media:

  • Type: string[]
  • Required: no
  • Variable Support: yes
  • Description: The URL of the media to send with the message.

    • Supported and Accepted media types can be referenced here (MMS) and here (WhatsApp).

actions:

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

    • Up to 2 buttons for PHONE or URL actions
    • Up to 3 buttons for QUICK_REPLY action

Create a Card Template

create-a-card-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/text type for less rich channels (e.g. SMS)
_38
var twilioText = new TwilioText.Builder();
_38
twilioText.WithBody("Hi {{1}}. Thanks for contacting Owl Air Support. How can we help?");
_38
_38
// define the twilio/card type for more rich channels
_38
var twilioCard = new TwilioCard.Builder();
_38
twilioCard.WithTitle("Owl Air Support");
_38
var cardAction1 = new CardAction.Builder()
_38
.WithType(CardActionType.Url)
_38
.WithUrl("https://www.twilio.com")
_38
.WithTitle("Contact Us")
_38
.Build();
_38
twilioCard.WithActions(new List<CardAction>() { cardAction1 });
_38
_38
// define all the content types to be part of the template
_38
var types = new Types.Builder();
_38
types.WithTwilioText(twilioText.Build());
_38
types.WithTwilioCard(twilioCard.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_card");
_38
contentCreateRequest.WithVariables(new Dictionary<string, string>() { {"1", "John"} });
_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

_39
{
_39
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_39
"date_created": "2022-08-30T09:19:17Z",
_39
"date_updated": "2022-08-30T09:19:17Z",
_39
"friendly_name": "owl_air_card",
_39
"language": "en",
_39
"links": {
_39
"approval_create": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests/whatsapp",
_39
"approval_fetch": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests"
_39
},
_39
"sid": "HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_39
"types": {
_39
"twilio/card": {
_39
"actions": [
_39
{
_39
"title": "Order Online",
_39
"type": "URL",
_39
"url": "https://www.owlair.com/"
_39
},
_39
{
_39
"phone_number": "+15551234567",
_39
"title": "Call Us",
_39
"type": "PHONE_NUMBER"
_39
}
_39
],
_39
"body": null,
_39
"media": null,
_39
"subtitle": "To unsubscribe, reply Stop",
_39
"title": "Congratulations, you have reached Elite status! Add code {{1}} for 10% off."
_39
},
_39
"twilio/text": {
_39
"body": "Congratulations, your account reached Elite status, you are now eligible for 10% off any flight! Just add coupon code {{1}} to check out."
_39
}
_39
},
_39
"url": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_39
"variables": {
_39
"1": "coupon_code"
_39
}
_39
}


Rate this page: