Receive messages
Receive inbound messages from Pinnacle.
To receive inbound messages from Pinnacle, you need to set up a webhook URL where Pinnacle can send the messages.
Set the webhook URL
You can set the webhook URL in your Pinnacle account settings. Alternatively, you can set it programmatically using the SDK:
from rcs import Pinnacle, RCSMediaMessage
pinn = Pinnacle(
api_key=YOUR_API_KEY,
webhook_url=YOUR_WEBHOOK_URL,
)
This will configure the SDK to send inbound messages to the specified webhook URL.
Handle incoming messages
The SDK provides a conveneince method to handle incoming messages. You can define a function that will be called whenever a message is received.
on_message(
callback: OnMessageCallback,
pathname: str = "/"
)
This will create a POST endpoint at the specified pathname that will handle incoming messages. The callback function will receive the message data as a parameter.
OnMessageCallback
takes a single argument of type PayloadData
.
Example
Here is an example of how to handle incoming messages:
from rcs import Pinnacle, PayloadData
pinn = Pinnacle(
api_key=YOUR_API_KEY,
webhook_url=YOUR_WEBHOOK_URL,
)
def receive_message(payload: PayloadData):
print(f"Received message: {payload}")
pinn.on_message(receive_message)
Incoming payload structure
When Pinnacle sends a message to your webhook, it will send a JSON payload with the following structure.
PayloadData
PayloadData contains the following fields:
The type of the message. Can be either message
or postback
.
The payload of the button if the messageType
is postback
.
The payload of the message if the messageType
is message
.
Example
{
"messageType": "message",
"messagePayload": {
"text": "Hello, World!",
"mediaType": "image",
"media": "https://example.com/image.jpg",
"sent": "2022-01-01T00:00:00Z",
"fromNum": "+1234567890"
}
}
MessagePayload
MessagePayload contains the following fields:
Optional text content of the message.
Optional type of the media if the message contains media. See the Media Types for more information.
Optional URL of the media if the message contains media.
Timestamp when the message was sent.
The phone number from which the message was sent.
Example
{
"text": "Hello, World!",
"mediaType": "image",
"media": "https://example.com/image.jpg",
"sent": "2022-01-01T00:00:00Z",
"fromNum": "+1234567890"
}
ButtonPayload
ButtonPayload contains the following fields:
Optional title content of the message.
Optional payload associated with the button.
Optional execute command associated with the action.
Timestamp when the message was sent.
The phone number from which the message was sent.
Example
{
"title": "Button Title",
"payload": "button_payload",
"execute": "some_command",
"sent": "2022-01-01T00:00:00Z",
"fromNum": "+1234567890"
}
Build your own webhook
If you decide not to use the SDK, you can also receive messages by implementing your own webhook. Check out the API Reference for more details.
Was this page helpful?