For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
SupportDashboard
DocsAPI ReferenceWebhooksMethodsUI ComponentsMCP ServerChangelog
  • Documentation
    • Introduction
    • Authentication
    • RCS Support
  • Quickstart
    • SMS
      • Python
        • Send
        • Receive
      • TypeScript
      • Ruby
    • RCS
  • Guides
    • Purchase Phone Numbers
    • Brands
    • Campaigns
    • Messages
    • Branded Test Agents
    • Handling Expired URLs
LogoLogo
SupportDashboard
QuickstartSMSPython

Receiving SMS Messages

1from rcs import Pinnacle
2from dotenv import load_dotenv
3import os
4from fastapi import FastAPI, Request
5from rcs.messages.sms.types.sms_send_response import SmsSendResponse
6from rcs.types import MessageEvent
7
8# Load environment variables
9load_dotenv()
10
11API_KEY = os.getenv("PINNACLE_API_KEY")
12SENDER_NUMBER = os.getenv("SENDER_NUMBER")
13SIGNING_SECRET = os.getenv("PINNACLE_SIGNING_SECRET")
14
15# Initialize the Pinnacle client
16client = Pinnacle(
17 api_key=API_KEY,
18)
19
20app = FastAPI()
21
22
23@app.get("/send-sms/{phone_number}")
24async def send_sms(phone_number):
25 try:
26 result: SmsSendResponse = client.messages.sms.send(
27 from_=SENDER_NUMBER,
28 text="Hello, world!",
29 to=phone_number,
30 )
31 return {"message": f"SMS message #{result.message_id} {result.status}"}
32 except Exception as e:
33 return {"message": "Error sending SMS", "error": str(e)}
34
35
36@app.post("/inbound-sms")
37async def inbound_sms(request: Request):
38 # Convert FastAPI Request to the format expected by the Pinnacle SDK
39 req_dict = {"headers": dict(request.headers), "body": await request.body()}
40
41 message_event: MessageEvent = client.messages.process(
42 req_dict, secret=SIGNING_SECRET # If omitted, will look inside of your .env for PINNACLE_SIGNING_SECRET
43 )
44 if message_event.type == "MESSAGE.RECEIVED":
45 # Check if this is an SMS message (discriminated by type field)
46 if message_event.message.type == "SMS":
47 text = message_event.message.text
48 from_number = message_event.conversation.from_
49 print(f"Received message from {from_number}: {text}")
50 return {"status": "received", "message_id": message_event.message.id}
51
52 if message_event.type == "MESSAGE.STATUS":
53 status = message_event.message.status
54 print(f"Message status: {status}")
55 return {"status": "status", "status": status}
56
57 return {"status": "processed", "event_type": message_event.type}
Was this page helpful?
Previous

TypeScript SDK Quickstart

Next
Built with

Prerequisites

Before proceeding, ensure you have obtained a phone number and API key as described in the prerequisites.

Installation

Create a Python virtual environment:

$python3 -m venv venv

Activate the virtual environment:

$source venv/bin/activate

Install the Pinnacle Python SDK and FastAPI:

$pip install rcs "fastapi[standard]"

This guide uses version rcs>=2.0.4. Requires: Python <4.0, >=3.8

Configuration

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

PINNACLE_API_KEY="your_api_key" # pnclk_
SENDER_NUMBER="your_phone_number" # +12345678910
PINNACLE_SIGNING_SECRET="your_signing_secret" # pss_

Setting Up a Webhook

To receive inbound SMS 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:8000/inbound-sms
    • For production, use your deployed server URL
  5. After creation, copy the signing secret and add it to your .env file
  6. Attach a phone number to your webhook to receive messages. If the number is a sandbox number, ensure that you’ve whitelisted a number and verified the 4-digit PIN through the phone icon on the sandbox number’s card.

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 Python file (e.g., main.py) and add the following snippet to the right.

The code above creates a FastAPI endpoint that:

  • Receives webhook POST requests at /inbound-sms
  • Verifies the webhook signature using your signing secret
  • Processes incoming message events
  • Handles both received messages and message status updates

Running Your Server

Start the FastAPI server:

$fastapi dev main.py

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

$ngrok http 8000

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

Testing Your Webhook

Send an SMS to your Pinnacle phone number from any mobile device. You should see the message logged in your server console:

Received message from +14155551234: Hello, this is a test!

If you’re not receiving any messages, make sure you have a phone number associated with your webhook.

Your webhook should now be successfully receiving inbound SMS messages as well message status updates for outbound messages!

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

Optionally, you can also create the /send-sms/{phone_number} endpoint to send an initial SMS message out.