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

twilio/text


Twilio/text type contains only plain text-based content. While text content may be sent to OTT channels without the use of content templates, the twilio/text type can be used as a fallback content type when sending to a mix of channels. Additionally, templates make it easy to utilize variables to create dynamic content.

(warning)

Warning

Twilio/text 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

SMS, WhatsApp, Facebook Messenger


Content API - Text sample.

body:

  • Type: string
  • Required: yes
  • Variable Support: yes
  • Description: The text of the message you want to send.

    • Maximum 1,600 characters

Create Text Template

create-text-template page anchor
Java
curl

_36
// Install the Java helper library from twilio.com/docs/java/install
_36
import com.twilio.Twilio;
_36
import com.twilio.exception.ApiException;
_36
import com.twilio.rest.content.v1.Content;
_36
_36
import java.util.Map;
_36
_36
public class Example {
_36
// Find your Account SID and Auth Token at twilio.com/console
_36
// and set the environment variables. See http://twil.io/secure
_36
public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
_36
public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");
_36
_36
public static void main(String[] args) {
_36
// Initialize the SDK
_36
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
_36
_36
// Setup Content
_36
Content.TwilioText type = new Content.TwilioText();
_36
type.setBody("Hi, {{1}}. \n Thanks for contacting Owl Air Support. How can I help?.");
_36
_36
Content.Types types = new Content.Types();
_36
types.setTwilioText(type);
_36
_36
// Create Content
_36
Content.ContentCreateRequest createRequest = new Content.ContentCreateRequest("en", types);
_36
createRequest.setVariables(Map.of("1", "name"));
_36
createRequest.setFriendlyName("text_template");
_36
try {
_36
Content content = Content.creator(createRequest).create();
_36
System.out.println(content.getSid());
_36
} catch (ApiException e) {
_36
e.printStackTrace();
_36
}
_36
}
_36
}

Output

_21
{
_21
"language": "en",
_21
"date_updated": "2022-09-01T12:39:19Z",
_21
"variables": {
_21
"1": "name"
_21
},
_21
"friendly_name": "text_template",
_21
"account_sid": "ACXXXXXXXXXXXXXXXXXXX",
_21
"url": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXX",
_21
"sid": "HXXXXXXXXXXXXXXXXXXX",
_21
"date_created": "2022-09-01T12:39:19Z",
_21
"types": {
_21
"twilio/text": {
_21
"body": "Hi, {{1}}. \n Thanks for contacting Owl Air Support. How can I help?."
_21
}
_21
},
_21
"links": {
_21
"approval_fetch": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXX/ApprovalRequests",
_21
"approval_create": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXX/ApprovalRequests/whatsapp"
_21
}
_21
}


Rate this page: