RCS Providers¶
Base Classes¶
RCSProvider ¶
Bases: ABC
RCS delivery provider for rich communication services.
supports_fallback
property
¶
Whether this provider supports automatic SMS fallback.
send
abstractmethod
async
¶
Send an RCS message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
RoomEvent
|
The room event containing the message content. |
required |
to
|
str
|
Recipient phone number (E.164 format). |
required |
fallback
|
bool
|
If True, allow fallback to SMS when RCS unavailable. |
True
|
Returns:
| Type | Description |
|---|---|
RCSDeliveryResult
|
Result with delivery info including whether fallback occurred. |
check_capability
async
¶
Check if a phone number supports RCS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phone_number
|
str
|
Phone number to check (E.164 format). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the number supports RCS, False otherwise. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the provider doesn't support capability check. |
parse_webhook
async
¶
Parse an inbound webhook payload into an InboundMessage.
verify_signature ¶
Verify that a webhook payload was signed by the provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
bytes
|
Raw request body bytes. |
required |
signature
|
str
|
Signature header value from the webhook request. |
required |
timestamp
|
str | None
|
Timestamp header value (required by some providers). |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the signature is valid, False otherwise. |
RCSDeliveryResult ¶
MockRCSProvider ¶
Bases: RCSProvider
Mock RCS provider for testing.
Initialize mock provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sender_id
|
str
|
Mock sender/agent ID. |
'mock_rcs_agent'
|
simulate_fallback
|
bool
|
If True, simulate SMS fallback on sends. |
False
|
simulate_failure
|
bool
|
If True, simulate send failures. |
False
|
check_capability
async
¶
Mock capability check - returns opposite of simulate_fallback.
Telnyx¶
TelnyxRCSProvider ¶
Bases: RCSProvider
RCS provider using the Telnyx REST API.
Telnyx RCS uses the same /v2/messages endpoint as SMS, but requires an RCS agent_id as the sender. When the recipient doesn't support RCS, messages can fall back to SMS (if fallback=True).
Example
config = TelnyxRCSConfig( api_key="KEY...", agent_id="your-rcs-agent-id", ) provider = TelnyxRCSProvider(config) result = await provider.send(event, to="+14155551234")
Initialize the Telnyx RCS provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
TelnyxRCSConfig
|
Telnyx RCS configuration. |
required |
public_key
|
str | None
|
Telnyx public key for webhook signature verification. Found in Mission Control Portal > Keys & Credentials > Public Key. |
None
|
send
async
¶
Send an RCS message via Telnyx.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
RoomEvent
|
The room event containing the message content. |
required |
to
|
str
|
Recipient phone number (E.164 format). |
required |
fallback
|
bool
|
If True, allow SMS fallback. If False, RCS only. |
True
|
Returns:
| Type | Description |
|---|---|
RCSDeliveryResult
|
Result with delivery info including channel used. |
check_capability
async
¶
Check if a phone number supports RCS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phone_number
|
str
|
Phone number to check (E.164 format). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the number supports RCS, False otherwise. |
verify_signature ¶
Verify a Telnyx webhook signature using ED25519.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
bytes
|
Raw request body bytes. |
required |
signature
|
str
|
Value of the |
required |
timestamp
|
str | None
|
Value of the |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the signature is valid, False otherwise. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If public_key was not provided to the constructor. |
ImportError
|
If PyNaCl is not installed. |
TelnyxRCSConfig ¶
Bases: BaseModel
Telnyx RCS provider configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
SecretStr
|
Telnyx API key (v2 key starting with KEY...). |
agent_id |
str
|
RCS agent ID (obtained after agent onboarding/brand approval). |
messaging_profile_id |
str | None
|
Optional messaging profile ID for webhooks. |
timeout |
float
|
HTTP request timeout in seconds. |
parse_telnyx_rcs_webhook ¶
Convert a Telnyx RCS webhook POST body into an InboundMessage.
Telnyx RCS webhooks use JSON format (unlike SMS which can be form-encoded). The webhook structure follows the same pattern as SMS but includes RCS-specific fields like agent_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
dict[str, Any]
|
The webhook POST body as a dictionary. |
required |
channel_id
|
str
|
The channel ID to associate with the message. |
required |
strict
|
bool
|
If True (default), raises ValueError for non-inbound webhooks. Set to False to skip validation (not recommended). |
True
|
Returns:
| Type | Description |
|---|---|
InboundMessage
|
An InboundMessage ready for process_inbound(). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If strict=True and the webhook is not an inbound message. |
Twilio¶
TwilioRCSProvider ¶
Bases: RCSProvider
RCS provider using the Twilio REST API.
Twilio RCS uses the same Messages API as SMS, but requires an RCS-enabled Messaging Service. When the recipient doesn't support RCS, Twilio can automatically fall back to SMS (unless disabled via fallback=False).
send
async
¶
Send an RCS message via Twilio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
RoomEvent
|
The room event containing the message content. |
required |
to
|
str
|
Recipient phone number (E.164 format). |
required |
fallback
|
bool
|
If True, allow SMS fallback. If False, RCS only. |
True
|
Returns:
| Type | Description |
|---|---|
RCSDeliveryResult
|
Result with delivery info including channel used. |
TwilioRCSConfig ¶
Bases: BaseModel
Twilio RCS provider configuration.
parse_twilio_rcs_webhook ¶
Convert a Twilio RCS webhook POST body into an InboundMessage.
Twilio sends webhooks as form-encoded data. Convert to dict first:
payload = dict(await request.form())