Send a RCS Standalone Rich Card Message
In this code snippet you learn how to send a RCS Rich Card message using the custom message type of the Messages API RCS channel
- For more information on RCS Messaging see Understanding RCS messaging
- For a detailed guide on the
custommessage type see RCS Custom Messages
Example
Find the description for all variables used in each code snippet below:
| Key | Description |
|---|---|
VONAGE_APPLICATION_ID | The Vonage Application ID. |
VONAGE_PRIVATE_KEY_PATH | Private key path. |
MESSAGES_API_URL | There are two versions of the API, each with their own endpoints. For production the previous Messages API endpoint was |
JWT | Used to authenticate your request. See Authentication for more information, including how to generate a JWT. |
IMAGE_URL | The link to the image file to send. |
TO_NUMBER | The number you are sending the RCS message to in E.164 format. For example |
RCS_SENDER_ID | The sender ID for the RCS message. |
NOTE: Don't use a leading + or 00 when entering a phone number, start with the country code, for example 447700900000.
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Write the code
Add the following to send-rich-card-standalone.sh:
curl -X POST $MESSAGES_API_URL \
-H "Authorization: Bearer "$JWT \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d $'{
"message_type": "custom",
"custom": {
"contentMessage": {
"richCard": {
"standaloneCard": {
"thumbnailImageAlignment": "RIGHT",
"cardOrientation": "VERTICAL",
"cardContent": {
"title": "Quick question",
"description": "Do you like this picture?",
"media": {
"height": "TALL",
"contentInfo": {
"fileUrl": "'$IMAGE_URL'",
"forceRefresh": "false"
}
},
"suggestions": [
{
"reply": {
"text": "Yes",
"postbackData": "suggestion_1"
}
},
{
"reply": {
"text": "I love it!",
"postbackData": "suggestion_2"
}
}
]
}
}
}
}
},
"to": "'$TO_NUMBER'",
"from": "'$RCS_SENDER_ID'",
"channel": "rcs"
}'Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
npm install @vonage/server-sdkCreate a file named send-rich-card-standalone.js and add the following code:
const { Vonage } = require('@vonage/server-sdk');
const { RCSCustom } = require('@vonage/messages');
const vonage = new Vonage({
applicationId: VONAGE_APPLICATION_ID,
privateKey: VONAGE_PRIVATE_KEY,
});Write the code
Add the following to send-rich-card-standalone.js:
vonage.messages.send(
new RCSCustom({
custom: {
contentMessage: {
richCard: {
standaloneCard: {
thumbnailImageAlignment: 'RIGHT',
cardOrientation: 'VERTICAL',
cardContent: {
title: 'Quick question',
description: 'Do you like this picture?',
media: {
height: 'TALL',
contentInfo: {
fileUrl: '\'$IMAGE_URL\'',
forceRefresh: 'false',
},
},
suggestions: [
{
reply: {
text: 'Yes',
postbackData: 'suggestion_1',
},
},
{
reply: {
text: 'I love it!',
postbackData: 'suggestion_2',
},
},
],
},
},
},
},
},
to: TO_NUMBER,
from: RCS_SENDER_ID,
}),
)
.then(({ messageUUID}) => console.log(messageUUID))
.catch((error) => console.error(error));Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Add the following to build.gradle:
implementation 'com.vonage:server-sdk-kotlin:1.1.2'Create a file named SendRcsRichCard and add the following code to the main method:
val client = Vonage {
applicationId(VONAGE_APPLICATION_ID)
privateKeyPath(VONAGE_APPLICATION_PRIVATE_KEY_PATH)
}Write the code
Add the following to the main method of the SendRcsRichCard file:
val messageId = client.messages.send(
rcsCustom {
to(TO_NUMBER)
from(RCS_SENDER_ID)
custom(mapOf(
"contentMessage" to mapOf(
"richCard" to mapOf(
"standaloneCard" to mapOf(
"thumbnailImageAlignment" to "RIGHT",
"cardOrientation" to "VERTICAL",
"cardContent" to mapOf(
"title" to "Quick question",
"description" to "Do you like this picture?",
"media" to mapOf(
"height" to "TALL",
"contentInfo" to mapOf(
"fileUrl" to IMAGE_URL,
"forceRefresh" to "false"
)
),
"suggestions" to listOf(
mapOf(
"reply" to mapOf(
"text" to "Yes",
"postbackData" to "suggestion_1"
)
),
mapOf(
"reply" to mapOf(
"text" to "I love it!",
"postbackData" to "suggestion_2"
)
)
)
)
)
)
)
))
}
)Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.messages.rcs with the package containing SendRcsRichCard:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Add the following to build.gradle:
implementation 'com.vonage:server-sdk:8.15.1'Create a file named SendRcsRichCard and add the following code to the main method:
VonageClient client = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build();Write the code
Add the following to the main method of the SendRcsRichCard file:
var response = client.getMessagesClient().sendMessage(
RcsCustomRequest.builder()
.from(RCS_SENDER_ID).to(TO_NUMBER)
.custom(Map.of("contentMessage", Map.of(
"richCard", Map.of("standaloneCard", Map.of(
"thumbnailImageAlignment", "RIGHT",
"cardOrientation", "VERTICAL",
"cardContent", Map.of(
"title", "Quick question",
"description", "Do you like this picture?",
"media", Map.of(
"height", "TALL",
"contentInfo", Map.of(
"fileUrl", IMAGE_URL,
"forceRefresh", "false"
)
),
"suggestions", List.of(
Map.of(
"reply", Map.of(
"text", "Yes",
"postbackData", "suggestion_1"
)
),
Map.of(
"reply", Map.of(
"text", "I love it!",
"postbackData", "suggestion_2"
)
)
)
)
))
))
).build()
);
System.out.println("Message sent successfully. ID: " + response.getMessageUuid());Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.messages.rcs with the package containing SendRcsRichCard:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Install-Package VonageWrite the code
Add the following to SendRcsStandaloneRichCardMessage.cs:
var credentials = Credentials.FromAppIdAndPrivateKeyPath(appId, privateKeyPath);
var vonageClient = new VonageClient(credentials);
var request = new RcsCustomRequest
{
To = to,
From = rcsSenderId,
Custom =
new
{
ContentMessage = new
{
RichCard = new
{
StandaloneCard = new
{
ThumbnailImageAlignment = "RIGHT",
CardOrientation = "VERTICAL",
CardContent = new
{
Title = "Quick question",
Description = "Do you like this picture?",
Media = new
{
Height = "TALL",
ContentInfo = new
{
FileUrl = imageUrl,
ForceRefresh = false
}
},
Suggestions = new[]
{
new
{
Reply = new
{
Text = "Yes",
PostbackData = "suggestion_1",
}
},
new
{
Reply = new
{
Text = "I love it!",
PostbackData = "suggestion_2",
}
}
}
}
}
}
}
}
};
var response = await vonageClient.MessagesClient.SendAsync(request);
Console.WriteLine($"Message UUID: {response.MessageUuid}");Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
composer require vonage/clientCreate a file named send-rich-card-standalone.php and add the following code:
$keypair = new \Vonage\Client\Credentials\Keypair(
file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH),
VONAGE_APPLICATION_ID
);
$client = new \Vonage\Client($keypair);Write the code
Add the following to send-rich-card-standalone.php:
$rcsCard = new Vonage\Messages\Channel\RCS\RcsCustom(
'07778887777',
'09997485156',
[
"contentMessage" => [
"richCard" => [
"standaloneCard" => [
"thumbnailImageAlignment" => "RIGHT",
"cardOrientation" => "VERTICAL",
"cardContent" => [
"title" => "Quick question",
"description" => "Do you like this picture?",
"media" => [
"height" => "TALL",
"contentInfo" => [
"fileUrl" => "'\$IMAGE_URL'",
"forceRefresh" => "false"
]
],
"suggestions" => [
[
"reply" => [
"text" => "Yes",
"postbackData" => "suggestion_1"
]
],
[
"reply" => [
"text" => "I love it!",
"postbackData" => "suggestion_2"
]
]
]
]
]
]
]
]
);
$client->messages()->send($rcsCard);Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
pip install vonageWrite the code
Add the following to send-rich-card-standalone.py:
from vonage import Auth, Vonage
from vonage_messages.models import RcsCustom
client = Vonage(
Auth(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
)
)
custom_dict = {
"contentMessage": {
"richCard": {
"standaloneCard": {
"thumbnailImageAlignment": "RIGHT",
"cardOrientation": "VERTICAL",
"cardContent": {
"title": "Quick question",
"description": "Do you like this picture?",
"media": {
"height": "TALL",
"contentInfo": {
"fileUrl": "'$IMAGE_URL'",
"forceRefresh": "false",
},
},
"suggestions": [
{
"reply": {
"text": "Yes",
"postbackData": "suggestion_1",
}
},
{
"reply": {
"text": "I love it!",
"postbackData": "suggestion_2",
}
},
],
},
}
}
}
}
message = RcsCustom(
to=TO_NUMBER,
from_=RCS_SENDER_ID,
custom=custom_dict,
)
response = client.messages.send(message)
print(response)Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
gem install vonageCreate a file named send-rich-card-standalone.rb and add the following code:
client = Vonage::Client.new(
application_id: VONAGE_APPLICATION_ID,
private_key: File.read(VONAGE_APPLICATION_PRIVATE_KEY_PATH)
)Write the code
Add the following to send-rich-card-standalone.rb:
message = client.messaging.rcs(
type: 'custom',
message: {
contentMessage: {
richCard: {
standaloneCard: {
thumbnailImageAlignment: "RIGHT",
cardOrientation: "VERTICAL",
cardContent: {
title: "Quick question",
description: "Do you like this picture?",
media: {
height: "TALL",
contentInfo: {
fileUrl: ENV['IMAGE_URL'],
forceRefresh: false
}
},
suggestions: [
{
reply: {
text: "Yes",
postbackData: "suggestion_1"
}
},
{
reply: {
text: "I love it!",
postbackData: "suggestion_2"
}
}
]
}
}
}
}
}
)
client.messaging.send(
from: RCS_SENDER_ID,
to: TO_NUMBER,
**message
)Run your code
Save this file to your machine and run it:
Try it out
When you run the code a message is sent to the destination number.