The twilio/media
content type allows you 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).
If you plan to submit this content 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 content 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, a video cannot be sent using the same content template.
During a 24-hour user-initiated session, content template approval is not required by WhatsApp for twilio/media
content templates.
For out of session (business-initiated) media templates, an additional approval step is required during the Beta. In the Media field of the content 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 and must resolve to a publicly hosted file.
For 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"}
The twilio/media
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.
Parameter | Type | Required | Variable support | Description |
---|---|---|---|---|
body | string | Only required to get content template approved by WhatsApp. | Yes | The text of the message you want to send.
|
media | string[] | Yes | Yes | The URL of the media you want to send. Variables are only supported after the domain. For example: www.twilio.com/images/{{1}} .You can find the supported and accepted media types on Accepted Content Types for Media. |
1// Install the C# / .NET helper library from twilio.com/docs/csharp/install23using System;4using Twilio;5using Twilio.Rest.Content.V1;67TwilioClient.Init(accountSid, authToken);89// define the twilio/media type10var twilioMedia = new TwilioMedia.Builder();11twilioMedia.WithBody("Thank you for your order {{1}}");12var media1 = new Media.Builder()13.WithMedia("https://twilio-cms-prod.s3.amazonaws.com/images/library-logo-resource2x.width-1000.png")14.Build();15twilioMedia.WithMedia(new List<Media>() { media1 });1617// define all the content types to be part of the template18var types = new Types.Builder();19types.WithTwilioMedia(twilioMedia.Build());2021// build the create request object22var contentCreateRequest = new ContentCreateRequest.Builder();23contentCreateRequest.WithTypes(types.Build());24contentCreateRequest.WithLanguage("en");25contentCreateRequest.WithFriendlyName("media_template");26contentCreateRequest.WithVariables(new Dictionary<string, string>() { {"1", "OrderNumber"} });2728// create the twilio template29var contentTemplate = await CreateAsync(contentCreateRequest.Build());3031Console.WriteLine($"Created Twilio Content Template SID: {contentTemplate.Sid}");
1{2"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",3"date_created": "2022-08-29T15:12:22Z",4"date_updated": "2022-08-29T15:12:22Z",5"friendly_name": "media_template",6"language": "en",7"links": {8"approval_create": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests/whatsapp",9"approval_fetch": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests"10},11"sid": "HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",12"types": {13"twilio/media": {14"body": "Thank you for your order {{1}}",15"media": [16"https://twilio-cms-prod.s3.amazonaws.com/images/library-logo-resource2x.width-1000.png"17]18}19},20"url": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",21"variables": {22"1": "OrderNumber"23}24}