How to Use Twilio's Content Template Builder for Messaging

February 11, 2026
Written by

How to Use Twilio's Content Template Builder for Messaging

Twilio's Content Template Builder enables you to create rich, interactive message templates that work across multiple channels including SMS, WhatsApp, and RCS. Instead of hardcoding message content into your application you’re able to design reusable templates with dynamic variables, rich media, and interactive elements directly in the Console.

In this tutorial, you'll learn how to use Twilio's Content Template Builder to create and send various types of message templates using Node.js. You'll explore creating text templates, rich cards, and templates with interactive actions.

Prerequisites

  • A Twilio account - Sign up with Twilio for free here
  • A Twilio phone number
  • Node.js installed on your machine

Understanding Content Templates

Before diving into the code, let's understand what Content Templates offer and why you should use them:

What are Content Templates?

Content Templates are pre-designed message structures that you create once and reuse across your applications. They support:

  • Dynamic Variables - Insert personalized data like names, order numbers, or dates
  • Rich Media - Include images, videos, and documents
  • Interactive Elements - Add buttons, quick replies, and call-to-action links
  • Multi-channel Support - Use the same template across SMS, WhatsApp, and RCS

Content Templates help ensure brand consistency across all your messaging while keeping message content separate from application logic. You can modify templates without changing your code, and design everything visually using the builder.

Content Templates Types

The Content Template Builder supports several template types:

  • Text - Simple text messages with optional variables
  • Media - Messages with images, videos, or documents
  • Rich Card - Combine media, text, and action buttons in a single card
  • Carousel - Multiple swipeable cards for showcasing products or options
  • Quick Reply - Text messages with suggested response buttons
  • Call to Action - Messages with buttons that trigger actions like phone calls or URL visits
  • List Picker - A list of options for users to choose from
  • Catalog - Share product catalogs
  • Flows - WhatsApp Flows for guided interactions

Some of these content types only work with certain channels. For more info on these types and their channel support, take a look at our docs: Content Types Overview.

For this tutorial, we’ll be showing how to create text templates, rich cards and media

Set up a Node.js Application

You'll start setting up your application by initializing a Node.js project and installing the dependencies you'll need.

Initialize a Node.js project

Open up your terminal, navigate to your preferred directory, and enter the following commands to create a folder, change into it, and initialize a Node.js project:

mkdir content-templates
cd content-templates
npm init -y

Install the required dependencies

Next, run the following command to install the dependencies you'll need for this project:

npm install --save twilio dotenv
  • twilio - The Twilio package will be used to access the Twilio Programmable Messaging API to send messages using Content Templates
  • dotenv - Used to load environment variables from a .env file

Import Environment Variables

You'll need your Twilio Account SID, Auth Token and Twilio phone number to send RCS messages from your Node.js application. Log in to your Twilio Console, scroll down to the Account Info section and you'll see Account SID, Auth Token and your Twilio phone number:

Front page of the Twilio console showing the account info section with credentials
Front page of the Twilio console showing the account info section with credentials

Head back to your IDE to create a file named .env. Copy the following into your .env file:

TWILIO_ACCOUNT_SID=XXXXXX
TWILIO_AUTH_TOKEN=XXXXXX
TWILIO_PHONE_NUMBER=XXXXXX
RECIPIENT_NUMBER=XXXXXX

Send a Text Template

Let's start with a simple text template that includes dynamic variables. To send a template, you'll need to create a Content Template in your Twilio Console. Navigate to Messaging > Content Template Builder to create your text template.

Content Template Builder menu of the Twilio Console with a blue button saying "create your frist content template"
Content Template Builder menu of the Twilio Console with a blue button saying "create your frist content template"

In the Content Template Builder, click Create your first content template. Then enter a Template Name (e.g., "order_confirmation"), select Text as the template type and click Create.

Twilio console screen showing the creation of a new messaging template named order_confirmation.

In the body field, enter your message with variables using double curly braces like so:

Hi {{1}}, your order #{{2}} has been confirmed! 
Estimated delivery: {{3}}. 
Thank you for shopping with us!
Twilio Console interface showing an order confirmation template with dynamic fields for WhatsApp messaging.

Click Save and you’ll be asked to provide sample values for each variable. Once added and saved, you’ll be navigated to the Content Template Builder homepage with your template shown in the list.

Take note of the Template SID below your template name as you’ll need it in the next section.

Navigate back to your project directory and create a file called send-text-template.js and add the following code:

require('dotenv').config();
const twilio = require('twilio');
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);
async function sendTextTemplate() {
    try {
        const message = await client.messages.create({
            from: process.env.TWILIO_PHONE_NUMBER,
            to: process.env.RECIPIENT_NUMBER,
            contentSid: 'HXXXXXXXXXXXXXXXXXXXXXXXXXXX', // Replace with your Content SID
            contentVariables: JSON.stringify({
                "1": "Dhruv",
                "2": "12345",
                "3": "February 7, 2026"
            })
        });
        console.log(`Message sent successfully! SID: ${message.sid}`);
    } catch (error) {
        console.error('Error sending message:', error.message);
    }
}
sendTextTemplate();

The contentVariables parameter is a JSON string that maps variable numbers to their values. For more info on using content variables check out our docs: Using Variables with Content Templates.

Run the following command on your terminal to test your text template:

node send-text-template.js

You should see a success message with the Message SID printed to your console.

Smartphone screen showing an SMS from Twilio confirming an order with an estimated delivery date of February 7, 2026.

Send Media

Media templates let you send images, videos, or documents with optional caption text. For this example, we’ll use a similar message we used in the last section but send a receipt for the recipient

Navigate back to the Content Template Builder in your Twilio Console. Navigate to Messaging > Content Template Builder and click the Create new button at the top right of the menu.

Then enter a Template Name (e.g., "order_receipt"), select Media as the template type and click Create.

Twilio console showing the content template creation page with sections for general information and content type selection.

In the body field, enter your message with variables using double curly braces like so:

Hi {{1}}, your order #{{2}} has been confirmed! Attached below is your receipt.

For the Media URL field, enter in a URL path of where you media is hosted. You can also use variables for this field like so:

https://demo.twilio.com/receipt/{{2}}.pdf
Twilio Console displaying a receipt template configuration page for messaging.

Click Save and you’ll be asked to provide sample values for each variable. Once added and saved, you’ll be navigated to the Content Template Builder homepage with your template shown in the list.

Take note of the Template SID below your template name as you’ll need it in the next section.

Navigate back to your IDE or editor and create a file called send-media.js within the project directory. This file is where you'll write the code to send an RCS message with an image.

Then, open the send-media.js file and add the following code:

require('dotenv').config();
const twilio = require('twilio');
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);
async function sendMediaTemplate() {
    try {
        const message = await client.messages.create({
            from: process.env.TWILIO_PHONE_NUMBER,
            to: process.env.RECIPIENT_NUMBER,
            contentSid: 'HXXXXXXXXXXXXXXXXXXXXXXXXXXX', // Replace with your Media Content SID
            contentVariables: JSON.stringify({
                "1": "Dhruv",
                "2": "12345"
            })
        });
        console.log(`Media message sent successfully! SID: ${message.sid}`);
    } catch (error) {
        console.error('Error sending message:', error.message);
    }
}
sendMediaTemplate();

Run the following command to test sending the media message with the media attached:

Copy code

node send-media

You should see a success message with the Message SID printed to your console, and the recipient should receive the media message with the media.

Send an RCS Rich Card

Rich cards allow you to combine media, text, and interactive elements into a single, visually appealing message.

 A Twilio phone number with RCS capabilities and a Messaging Service with your RCS sender configured is required to send RCS rich cards.

Check out our docs on enabling RCS or follow our Getting Started with RCS tutorial.

For more information on rich cards and all available configuration options, check out our documentation on the twilio/card content type.

To send an RCS rich card, you’ll first need to set up a Messaging Service linked with your Twilio phone number with RCS enabled.

To get your RCS Messaging Service SID, navigate to the Messaging tab on the left and then click Services. Here is where you’ll see all your Messaging Services, including your RCS service. Take note of the Sid of your RCS sender for your .env file.

Messaging Service page of the Twilio console showing the RCS service with its SID
Messaging Service page of the Twilio console showing the RCS service with its SID

Add the following to your .env file and replace the XXXXXX placeholders with the actual Sid:

TWILIO_RCS_SERVICE_SID=XXXXXX

To send rich cards, you'll need to create a Content Template in your Twilio Console. Navigate to Messaging > Content Template Builder to create your rich card template.

Click on Create New or Create your first content template. On the form, give your template a name and language and then select Card as the content type. Finally, click Create.

Twilio console page for creating a messaging content template with options for text, media, and interactive elements.

For this tutorial, I created a rich card for a coffee shop promotion. Here's the example:

Screenshot of Twilio Console showing the setup for an RCS rich card with morning brew special message.

You can also add action buttons to your rich card:

  • Quick Reply
  • Phone Number
  • Visit Website
  • Coupon Code

Once created, copy the Content SID for the next step.

Then, create a new file called send-rich-card.js and add the following code:

require('dotenv').config();
const twilio = require('twilio');
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);
async function sendRichCard() {
    try {
        const message = await client.messages.create({
            messagingServiceSid: process.env.TWILIO_RCS_SERVICE_SID,
            to: process.env.RECIPIENT_NUMBER,
            contentSid: 'YOUR_CONTENT_SID', // Replace with your Content Template SID
        });
        console.log(`Rich card sent successfully! SID: ${message.sid}`);
    } catch (error) {
        console.error('Error sending rich card:', error.message);
    }
}
sendRichCard();

Replace YOUR_CONTENT_SID with the template SID and save. Navigate back to your terminal and enter the following command to send the template:

node send-rich-card
Smartphone displaying a text message with a coffee promotion featuring a cup of coffee and coffee beans.

What's Next?

You've successfully learned how to use Twilio's Content Template Builder to create and send various types of message templates! Here are some ways to expand on what you've built:

For more information on Content Templates and all available options, check out Twilio's Content API documentation.

Dhruv Patel is a Developer on Twilio's Developer Voices team. You can find Dhruv working in a coffee shop with a glass of cold brew or he can be reached at dhrpatel [at] twilio.com .