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

twilio/media


Twilio/media is used to send file attachments, or to send long text via MMS in the US and Canada. As such, the twilio/media type must contain at least ONE of text or media content. The total size of the text and media attachments must be less than 5MB (16MB for WhatsApp).

(information)

Info

If 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 media 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.

During a 24-hour user-initiated session, template approval is not required by WhatsApp for twilio/media templates.

For out of session (business-initiated) media templates, an additional approval step is required during the Beta. In the Media field of the template you create, provide the URL of the publicly hosted file.

If you are using a media template 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"}

(warning)

Warning

Twilio/media 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 Using Variables with Content Templates.


Supported Channels

supported-channels page anchor

MMS, WhatsApp, Facebook Messenger


content api - message preview.

body:

  • Type: string
  • Required: no (only required to get template approved by WA)
  • Variable Support: yes
  • Description: The text of the message you want to send. Maximum 1,600 characters. Each variable counts as 1 character at content creation time.

media:

  • Type: string[]
  • Required: yes
  • Variable Support: yes
  • Description: The URL of the media you want to send. Variables are only supported after the domain. For example: www.twilio.com/images/{{1}} . Supported and Accepted media types can be referenced here (MMS) and here (WhatsApp).

Create a Media Template

create-a-media-template page anchor
C#
Java
curl

_31
// Install the C# / .NET helper library from twilio.com/docs/csharp/install
_31
_31
using System;
_31
using Twilio;
_31
using Twilio.Rest.Content.V1;
_31
_31
TwilioClient.Init(accountSid, authToken);
_31
_31
// define the twilio/media type
_31
var twilioMedia = new TwilioMedia.Builder();
_31
twilioMedia.WithBody("Thank you for your order {{1}}");
_31
var media1 = new Media.Builder()
_31
.WithMedia("https://twilio-cms-prod.s3.amazonaws.com/images/library-logo-resource2x.width-1000.png")
_31
.Build();
_31
twilioMedia.WithMedia(new List<Media>() { media1 });
_31
_31
// define all the content types to be part of the template
_31
var types = new Types.Builder();
_31
types.WithTwilioMedia(twilioMedia.Build());
_31
_31
// build the create request object
_31
var contentCreateRequest = new ContentCreateRequest.Builder();
_31
contentCreateRequest.WithTypes(types.Build());
_31
contentCreateRequest.WithLanguage("en");
_31
contentCreateRequest.WithFriendlyName("media_template");
_31
contentCreateRequest.WithVariables(new Dictionary<string, string>() { {"1", "OrderNumber"} });
_31
_31
// create the twilio template
_31
var contentTemplate = await CreateAsync(contentCreateRequest.Build());
_31
_31
Console.WriteLine($"Created Twilio Content Template SID: {contentTemplate.Sid}");

Output

_24
{
_24
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_24
"date_created": "2022-08-29T15:12:22Z",
_24
"date_updated": "2022-08-29T15:12:22Z",
_24
"friendly_name": "media_template",
_24
"language": "en",
_24
"links": {
_24
"approval_create": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests/whatsapp",
_24
"approval_fetch": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests"
_24
},
_24
"sid": "HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_24
"types": {
_24
"twilio/media": {
_24
"body": "Thank you for your order {{1}}",
_24
"media": [
_24
"https://twilio-cms-prod.s3.amazonaws.com/images/library-logo-resource2x.width-1000.png"
_24
]
_24
}
_24
},
_24
"url": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_24
"variables": {
_24
"1": "OrderNumber"
_24
}
_24
}


Rate this page: