Skip to main content

Send RCS messages

Send RCS messages with Messente's Omnichannel API.


Introduction​

RCS (Rich Communication Services) is a messaging protocol that enhances traditional SMS with rich media and provides a more interactive experience for the users. In addition to standard text messages, RCS supports media attachments, carousel cards, standalone cards, and suggested actions/replies. Using Omnichannel API, you can send RCS messages to engage your audience more effectively.

Simple RCS text message​

Text messages are the most basic form of RCS communication. They allow you to send plain text content, just like traditional SMS.

from pprint import pprint
from messente_api import (
OmnimessageApi,
Omnimessage,
Configuration,
ApiClient,
Rcs,
OmnimessageMessagesInner,
)
from messente_api.rest import ApiException


configuration = Configuration(
username="YOUR_MESSENTE_API_USERNAME",
password="YOUR_MESSENTE_API_PASSWORD",
)

api_instance = OmnimessageApi(ApiClient(configuration))

# Build the RCS message payload
rcs = Rcs(
sender='<sender name (optional)>',
text="hello, world!"
)
omnimessage = Omnimessage(
to='<recipient_phone_number>',
messages=[OmnimessageMessagesInner(rcs)],
)

try:
# Send the omnimessage
response = api_instance.send_omnimessage(omnimessage)
print(
"Successfully sent Omnimessage with id: %s that consists of the following messages:"
% response.omnimessage_id
)
for message in response.messages:
pprint(message)
except ApiException as exception:
print("Exception while sending the Omnimessage: %s\n" % exception)

RCS message with media content​

Media messages allow you to send rich media content, such as images, videos, and audio files. When you send a message with media content, you must provide a publicly accessible URL for the content.

from pprint import pprint
from messente_api import (
OmnimessageApi,
Omnimessage,
Configuration,
ApiClient,
Rcs,
OmnimessageMessagesInner,
RcsContentInfo,
)
from messente_api.rest import ApiException


configuration = Configuration(
username="YOUR_MESSENTE_API_USERNAME",
password="YOUR_MESSENTE_API_PASSWORD",
)

api_instance = OmnimessageApi(ApiClient(configuration))

# Build the RCS message payload
rcs = Rcs(
channel='rcs',
sender='<sender name (optional)>',
content_info=RcsContentInfo(
file_url='<URL to a public media resource>',
force_refresh=False
)
)
omnimessage = Omnimessage(
to='<recipient_phone_number>',
messages=[OmnimessageMessagesInner(rcs)],
)

try:
# Send the omnimessage
response = api_instance.send_omnimessage(omnimessage)
print(
"Successfully sent Omnimessage with id: %s that consists of the following messages:"
% response.omnimessage_id
)
for message in response.messages:
pprint(message)
except ApiException as exception:
print("Exception while sending the Omnimessage: %s\n" % exception)

RCS message with a standalone card​

Standalone cards allow you to send a single customized media item with an optional title, description, and suggested reply/action buttons.

from pprint import pprint
from messente_api import (
OmnimessageApi,
Omnimessage,
Configuration,
ApiClient,
Rcs,
OmnimessageMessagesInner,
RcsCardContent,
RcsMedia,
RcsContentInfo,
RcsRichCard,
RcsSuggestion,
RcsSuggestedReply,
RcsMediaHeight,
RcsStandaloneCard,
RcsCardOrientation,
RcsImageAlignment,
)
from messente_api.rest import ApiException


configuration = Configuration(
username="YOUR_MESSENTE_API_USERNAME",
password="YOUR_MESSENTE_API_PASSWORD",
)

api_instance = OmnimessageApi(ApiClient(configuration))
card_content = RcsCardContent(
title="Cute dog",
description="Look at this cute dog. Would you like to hear more?",
suggestions=[
RcsSuggestion(
reply=RcsSuggestedReply(
text="🗒️ Tell me more",
postback_data="card_1"
)
),
RcsSuggestion(
reply=RcsSuggestedReply(
text="🚫 Not interested",
postback_data="card_1"
)
)
],
media=RcsMedia(
height=RcsMediaHeight.MEDIUM,
content_info=RcsContentInfo(
file_url="https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg",
force_refresh=False
)
)
)

standalone_card = RcsStandaloneCard(
card_orientation=RcsCardOrientation.VERTICAL,
thumbnail_image_alignment=RcsImageAlignment.LEFT,
card_content=card_content,
)

rich_card = RcsRichCard(
standalone_card=standalone_card,
)

rcs = Rcs(
sender="YOUR_SENDER_NAME (optional)",
rich_card=rich_card,
)

omnimessage = Omnimessage(
to='RECIPIENT_PHONE_NUMBER',
messages=[OmnimessageMessagesInner(rcs)],
)

try:
# Send the omnimessage
response = api_instance.send_omnimessage(omnimessage)
print(
"Successfully sent Omnimessage with id: %s that consists of the following messages:"
% response.omnimessage_id
)
for message in response.messages:
pprint(message)
except ApiException as exception:
print("Exception while sending the Omnimessage: %s\n" % exception)

RCS Standalone Card Example

RCS Standalone Card Example

Carousel cards allow you to send a list of items, which users can swipe through. Each item in the carousel can contain its own text, media, actions and suggestions. This example will create a carousel with two cards, each containing an image, title, description, and suggested replies.

from pprint import pprint
from messente_api import (
OmnimessageApi,
Omnimessage,
Configuration,
ApiClient,
Rcs,
OmnimessageMessagesInner,
RcsCardContent,
RcsMedia,
RcsContentInfo,
RcsCarouselCard,
RcsRichCard,
RcsCardWidth,
RcsSuggestion,
RcsSuggestedReply,
RcsMediaHeight,
)
from messente_api.rest import ApiException


configuration = Configuration(
username="YOUR_MESSENTE_API_USERNAME",
password="YOUR_MESSENTE_API_PASSWORD",
)

api_instance = OmnimessageApi(ApiClient(configuration))
card1 = RcsCardContent(
title="Cute dog",
description="This dog is very cute",
suggestions=[
RcsSuggestion(
reply=RcsSuggestedReply(
text="Card #1",
postback_data="card_1"
)
)
],
media=RcsMedia(
height=RcsMediaHeight.MEDIUM,
content_info=RcsContentInfo(
file_url="https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg",
force_refresh=False
)
)
)

card2 = RcsCardContent(
title="Cool elephant",
description="This elephant is very cool",
suggestions=[
RcsSuggestion(
reply=RcsSuggestedReply(
text="Card #2",
postback_data="card_2"
)
)
],
media=RcsMedia(
height=RcsMediaHeight.MEDIUM,
content_info=RcsContentInfo(
file_url="https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg",
force_refresh=False
)
)
)

carousel_card = RcsCarouselCard(
card_width=RcsCardWidth.SMALL,
card_contents=[card1, card2]
)

rich_card = RcsRichCard(
carousel_card=carousel_card
)

rcs = Rcs(
sender="<sender name (optional)>",
rich_card=rich_card,
)

omnimessage = Omnimessage(
to='<recipient_phone_number>',
messages=[OmnimessageMessagesInner(rcs)],
)

try:
# Send the omnimessage
response = api_instance.send_omnimessage(omnimessage)
print(
"Successfully sent Omnimessage with id: %s that consists of the following messages:"
% response.omnimessage_id
)
for message in response.messages:
pprint(message)
except ApiException as exception:
print("Exception while sending the Omnimessage: %s\n" % exception)

RCS Carousel Card Example

RCS Carousel Card Example