Receiving RCS Messages

Prerequisites

Before proceeding, ensure you have obtained an RCS sandbox agent and API key as described in the prerequisites.

Installation

Create a Gemfile in your project directory:

1source "https://rubygems.org"
2
3gem "sinatra"
4gem "json"
5gem "dotenv"
6gem "rcs", "2.0.15"

Install the dependencies:

$bundle install

This guide uses version rcs 2.0.15. Requires Ruby version >= 3.3.0

Configuration

Create an .env file in your project root and add your Pinnacle API key:

PINNACLE_API_KEY="your_api_key" # pnclk_
AGENT_ID="your_agent_id" # agent_
PINNACLE_SIGNING_SECRET="your_signing_secret" # pss_

Setting Up a Webhook

To receive inbound RCS messages, you need to configure a webhook in the Pinnacle dashboard:

  1. Navigate to Development > Webhooks in the Pinnacle dashboard
  2. Click Create new webhook
  3. Give your webhook a descriptive name
  4. Enter your webhook endpoint URL
    • For local development, use an ngrok tunnel pointing to localhost:4567/inbound-rcs
    • For production, use your deployed server URL
  5. Add your RCS sandbox agent to your webhook for it to receive messages. You must also whitelist the devices you want to test with by navigating to your sandbox agent and adding test device phone numbers.

Optionally, you can configure custom HTTP headers (e.g. X-API-KEY) to be sent on every webhook delivery. Add them in the dashboard or via the headers field on POST /webhooks/attach. The PINNACLE-SIGNING-SECRET header is reserved.

Creating Your Webhook Endpoint

Create a new Ruby file (e.g., main.rb) and add the following snippet to the right.

The code above creates a Sinatra endpoint that:

  • Receives webhook POST requests at /inbound-rcs
  • Verifies the webhook signature using your signing secret
  • Handles inbound text messages, button clicks, media, and location shares
  • Echoes text messages back and responds to button presses

Running Your Server

Start the Sinatra server:

$ruby main.rb

Your server will start on http://localhost:4567. If you’re using ngrok for local development, start it in a separate terminal:

$ngrok http 4567

Use the ngrok URL (e.g., https://abc123.ngrok.io/inbound-rcs) as your webhook endpoint in the Pinnacle dashboard.

Testing Your Webhook

Go to localhost:4567/send-rcs/+12345678910 (e.g., to your whitelisted number). If there are no errors, you should see something like

1{
2 "success": true,
3 "response": {
4 "messageId": "msg_7401",
5 "segments": 1,
6 "totalCost": 0.03,
7 "recipient": "+18708977103",
8 "sender": "agent_pinnacleNbjn",
9 "status": "queued"
10 }
11}

and receive a message on your whitelisted device like this: rcs message

If you’re not receiving any messages, make sure you have

  • Your RCS sandbox agent associated with your webhook
  • Your test device is whitelisted

If you tap “Hello!”, your whitelisted device should receive a text saying “Hello! Button clicked successfully.” If you reply with a text message, the server will echo it back.

With that, your webhook should now be successfully receiving inbound RCS messages as well as message status updates for outbound messages! You can monitor delivery statuses by filtering events by direction:

1if message_event.type == 'MESSAGE.STATUS' && message_event.direction == 'OUTBOUND'
2 puts "Outbound message status: #{message_event.message.status}"
3end

For more detail about processing the message payload received, please view the process method.