How to send RCS messages with Ruby and Twilio

December 17, 2024
Written by
Alvin Lee
Contributor
Opinions expressed by Twilio contributors are their own
Reviewed by
Paul Kamp
Twilion

Rich Communication Services (RCS) is reshaping the way businesses and consumers interact, offering a modern messaging experience that combines the reliability of SMS with the interactive features of popular messaging apps. Apple devices also now support RCS, as of the release of iOS 18. Developers around the globe are exploring how to integrate this cutting-edge channel into their applications.

In this tutorial, we’ll show you how to get started with RCS using Twilio and Ruby.

Twilio recently launched its public beta for RCS messaging. Join the public beta and start working with RCS today! Visit Twilio’s RCS Business Messaging page and click Get started. Your request should be approved within a few days.

Comparing RCS to SMS and WhatsApp

RCS is revolutionizing the messaging landscape by combining the simplicity of SMS with the advanced features of modern apps like WhatsApp. With multimedia, verified sender profiles, and comprehensive engagement tracking support, RCS offers a rich, interactive experience—all without requiring an additional app download. For a deeper dive into how RCS stacks up against other messaging channels, check out the Guide to Rich Communication Services: What Developers Need to Know.

Implementing RCS with Twilio and Ruby

Getting started with RCS to test message sending is easy with Twilio. We’ll walk you through creating an RCS sender, creating a messaging service, and sending your first RCS message using Ruby.

Prerequisites

To get started, you will need the following:

  1. A Twilio account (sign up here).
  2. A Twilio phone number for sending SMS, as a fallback to your RCS service.
  3. A device capable of receiving RCS messages.
  4. Ruby installed on your machine ( manually or with rvm).
$ ruby -version
ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux]

Step 1: Create an RCS Sender

  1. Log in to the Twilio Console.
  2. Navigate to the Explore Products section and click RCS. • If RCS isn’t visible, you may need to request access here.
Software interface displaying various product options with a highlighted arrow pointing to RCS selection.

3. In the side panel, navigate to the Senders section.

4. Click Create new sender.

Web dashboard on a senders management page with an option to create a new sender.
5. Provide a name (for example: “My First RCS Sender”). Click the continue button.
A screenshot showing the process of creating a new sender in an email platform.

Step 2: Add Profile Information

Next, you’ll add profile information for your RCS sender. Use the following:

  • Sender display name: Choose a recognizable name for your sender. Usually, this is your brand name. For our example, we will use “My First RCS Sender”.
  • Description: Describe your brand. This description will be displayed just under your display name at the top of your user’s RCS interactions.
  • Border color: Keep in mind the minimum contrast ratio. For testing purposes, start with #000000 to keep it simple.
  • Logo: Your brand logo should meet the following requirements:
        • Dimensions: 224x224 pixels
        • File size: Max 50 KB
        • Image type: JPEG/JPG/PNG
        • For testing, you can use this example image: https://corn-lobster-7338.twil.io/assets/twiliodevs-logo-rcs.png
  • Banner: Your brand banner should meet the following requirements:
        • Dimensions: 1440x448 pixels
        • File size: Max 200KB
        • Image type: JPEG/JPG/PNG
        • For testing, you can use this example image: https://corn-lobster-7338.twil.io/assets/twiliodevs-banner-rcs.png
  • Contact Details - Phone number: A phone number associated with your RCS sender is required. Optionally, you can also add an email address.
  • Link to privacy policy and Link to terms of service: For testing purposes, you can enter links to arbitrary information here. When you begin building for production usage, make sure to create an RCS sender with real information about your business.
Screenshot of Twilio profile creation screen with fields for username and avatar, plus a phone preview.

Step 3: Test Your RCS Sender

  1. On the optional Test tab, click Add device to test this sender.
Screen showing Twilio interface for confirming sender with brand information and adding phone as test device.

2. Enter the phone number of your RCS-capable device and click Invite.

3. You should receive an opt-in message from Twilio’s RCS agent on your device.

4. Confirm the opt-in on your device by selecting Make me a tester.

5. Check the dialog box in the Twilio Console, and send a test message.

Instructions for Setting Up Your RCS Test Device

6. Celebrate—you’ve just sent your first RCS message!

Smartphone screen showing the first RCS message received from a Twilio sender.
7. Since this is just a test sender, click Save as draft and close.
Twilio interface for creating a sender with a preview of the message on a mobile device.

Step 4: Create a Messaging Service

  1. In the Console, navigate to Messaging > Services.
  2. Click Create Messaging Service.
Browser window showing a web app interface for creating and managing messaging services.
3. Give the new service a name (for example: “My RCS Service”) and click Create Messaging Service.
Browser window showing the setup process for a messaging service with fields for service name and usage.

4. Add your RCS sender.

5. Click Add Sender, select RCS Sender.

User interface showing the process to add an RCS sender, with highlighted steps and guidance text.
6. Add the RCS sender you just created.
Web interface screenshot for adding RCS senders with instructions to select the RCS agent highlighted.
7. Add an SMS fallback sender by repeating the Add Sender process and selecting a phone number (or other SMS-capable sender). Then, click Step 3: Set up integration.
Screenshot of Sender Pool settings and integration steps in a web-based messaging service dashboard.

Step 5: (Optional) Set Up Webhook Integration

  1. Webhooks allow you to handle incoming messages in the same way as SMS or WhatsApp. Learn more in Twilio's docs about Incoming Message Webhooks.
  2. Use the Set Up Integration option to register a webhook. Feel free to reuse an existing one if available.
Screenshot of Twilio integration settings page with an option to add a webhook and fallback URL.

Step 6: Send Your First RCS Message with Ruby

  1. Finish the wizard flow by clicking the white Skip setup button.
Configuration wizard screen in Microsoft Azure with options for settings and a Skip button highlighted.

2. Copy the Messaging Service SID (like MGe1fdfb207e9aa5b44f398b1094d88a8b) from the Console.

Screenshot of Twilio Console showing steps to copy the messaging service SID from the Properties section.
3. Retrieve your Account SID and Auth Token from the Twilio Console.

4. Create a file in your Ruby project folder called .env. Add the credentials from the previous steps, so that your file looks like this:

MESSAGING_SERVICE_SID=replace-with-your-messaging-service-sid
ACCOUNT_SID=replace-with-your-twilio-account-sid
AUTH_TOKEN=replace-with-your-twilio-auth-token
5. Install the dependency gems you will use in your Ruby code.
$ gem install dotenv twilio-ruby

6. Create a new file named sendRCS.rb with the following code:

require 'dotenv/load'
require 'twilio-ruby'

@client = Twilio::REST::Client.new(ENV['ACCOUNT_SID'], ENV['AUTH_TOKEN'])

message = @client
  .messages
  .create(
    body: 'This RCS message contains an image',
    to: '+<INSERT THE NUMBER USED AS TEST DEVICE>',
    messaging_service_sid: ENV['MESSAGING_SERVICE_SID'],
    media_url:
      'https://pbs.twimg.com/media/GZbs3vZWAAAwqVX?format=jpg&name=medium
'
  )
 
puts message.body
7. Run the script using ruby sendRCS.rb and see the result on your phone.
Smartphone screen showing an RCS message from My First RCS Sender on a dark grid background with a red hashtag.
As you transition from sandbox testing to production usage, you’ll need to pass the country-specific verification process we skipped above. This requirement ensures compliance with local regulations and protects users from potential messaging spam. While this might introduce initial friction, it guarantees that messages from reputable sources maintain their integrity, significantly reducing spam and increasing user trust. Twilio and other carriers around the world are committed to fighting spam and avoiding the problems that were caused by the permissionless nature of SMS.

Explore Advanced RCS Features

Congratulations! You just sent your first RCS message using Ruby!

Business messaging with RCS opens up a whole new world of possibilities. If you’re looking for the next steps, start by exploring some of the other things you can do with your new capabilities:

Twilio is continuously enhancing its RCS offering with features like failover for undelivered messages and quick reply buttons. Stay tuned for updates, and start building more engaging customer experiences today!

RCS is redefining how businesses connect with customers—combining the reliability of SMS with the interactivity of modern messaging apps. With Twilio, you can harness RCS to elevate your messaging strategy.

We can’t wait to see what you build!