Skip to content

Commit

Permalink
Adding RCS examples (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
superchilled authored Aug 30, 2024
1 parent 977d149 commit 1c94038
Show file tree
Hide file tree
Showing 16 changed files with 563 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ WHATSAPP_TEMPLATE_NAME=
WHATSAPP_AUTH_TEMPLATE_NAME=
WHATSAPP_TEMPLATE_REPLACEMENT_TEXT=

## For RCS messaging
RCS_SENDER_ID=

## For media messaging (WhatsApp, Messenger, Viber)
IMAGE_URL=
IMAGE_CAPTION=
Expand All @@ -38,6 +41,11 @@ FILE_CAPTION=
AUDIO_URL=
VIDEO_URL=

## For Update Action

MESSAGE_UUID=
GEOSPECIFIC_VONAGE_API_HOST=

# Vonage Number Insight variables
INSIGHT_NUMBER=

Expand Down
18 changes: 18 additions & 0 deletions messages/rcs/revoke-message.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'dotenv/load'
require 'vonage'

VONAGE_APPLICATION_ID = ENV['VONAGE_APPLICATION_ID']
VONAGE_APPLICATION_PRIVATE_KEY_PATH = ENV['VONAGE_APPLICATION_PRIVATE_KEY_PATH']
GEOSPECIFIC_VONAGE_API_HOST = ENV['GEOSPECIFIC_VONAGE_API_HOST']
MESSAGE_UUID = ENV['MESSAGE_UUID']

client = Vonage::Client.new(
application_id: VONAGE_APPLICATION_ID,
private_key: File.read(VONAGE_APPLICATION_PRIVATE_KEY_PATH),
api_host: GEOSPECIFIC_VONAGE_API_HOST
)

client.messaging.update(
message_uuid: MESSAGE_UUID,
status: 'revoked'
)
26 changes: 26 additions & 0 deletions messages/rcs/send-file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'dotenv/load'
require 'vonage'

VONAGE_APPLICATION_ID = ENV['VONAGE_APPLICATION_ID']
VONAGE_APPLICATION_PRIVATE_KEY_PATH = ENV['VONAGE_APPLICATION_PRIVATE_KEY_PATH']
RCS_SENDER_ID = ENV['RCS_SENDER_ID']
TO_NUMBER = ENV['TO_NUMBER']
FILE_URL = ENV['FILE_URL']

client = Vonage::Client.new(
application_id: VONAGE_APPLICATION_ID,
private_key: File.read(VONAGE_APPLICATION_PRIVATE_KEY_PATH)
)

message = client.messaging.rcs(
type: 'file',
message: {
url: ENV['FILE_URL'],
}
)

client.messaging.send(
from: RCS_SENDER_ID,
to: TO_NUMBER,
**message
)
26 changes: 26 additions & 0 deletions messages/rcs/send-image.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'dotenv/load'
require 'vonage'

VONAGE_APPLICATION_ID = ENV['VONAGE_APPLICATION_ID']
VONAGE_APPLICATION_PRIVATE_KEY_PATH = ENV['VONAGE_APPLICATION_PRIVATE_KEY_PATH']
RCS_SENDER_ID = ENV['RCS_SENDER_ID']
TO_NUMBER = ENV['TO_NUMBER']
IMAGE_URL = ENV['IMAGE_URL']

client = Vonage::Client.new(
application_id: VONAGE_APPLICATION_ID,
private_key: File.read(VONAGE_APPLICATION_PRIVATE_KEY_PATH)
)

message = client.messaging.rcs(
type: 'image',
message: {
url: ENV['IMAGE_URL'],
}
)

client.messaging.send(
from: RCS_SENDER_ID,
to: TO_NUMBER,
**message
)
73 changes: 73 additions & 0 deletions messages/rcs/send-rich-card-carousel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
require 'dotenv/load'
require 'vonage'

VONAGE_APPLICATION_ID = ENV['VONAGE_APPLICATION_ID']
VONAGE_APPLICATION_PRIVATE_KEY_PATH = ENV['VONAGE_APPLICATION_PRIVATE_KEY_PATH']
RCS_SENDER_ID = ENV['RCS_SENDER_ID']
TO_NUMBER = ENV['TO_NUMBER']
IMAGE_URL = ENV['IMAGE_URL']
VIDEO_URL = ENV['VIDEO_URL']

client = Vonage::Client.new(
application_id: VONAGE_APPLICATION_ID,
private_key: File.read(VONAGE_APPLICATION_PRIVATE_KEY_PATH)
)

message = client.messaging.rcs(
type: 'custom',
message: {
contentMessage: {
richCard: {
carouselCard: {
cardWidth: "MEDIUM",
cardContents: [
{
title: "Option 1: Photo",
description: "Do you prefer this photo?",
media: {
height: "MEDIUM",
contentInfo: {
fileUrl: ENV['IMAGE_URL'],
forceRefresh: false
}
},
suggestions: [
{
reply: {
text: "Option 1",
postbackData: "card_1"
}
}
]
},
{
title: "Option 1: Video",
description: "Or this video?",
media: {
height: "MEDIUM",
contentInfo: {
fileUrl: ENV['VIDEO_URL'],
forceRefresh: false
}
},
suggestions: [
{
reply: {
text: "Option 2",
postbackData: "card_2"
}
}
]
}
]
}
}
}
}
)

client.messaging.send(
from: RCS_SENDER_ID,
to: TO_NUMBER,
**message
)
58 changes: 58 additions & 0 deletions messages/rcs/send-rich-card-standalone.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require 'dotenv/load'
require 'vonage'

VONAGE_APPLICATION_ID = ENV['VONAGE_APPLICATION_ID']
VONAGE_APPLICATION_PRIVATE_KEY_PATH = ENV['VONAGE_APPLICATION_PRIVATE_KEY_PATH']
RCS_SENDER_ID = ENV['RCS_SENDER_ID']
TO_NUMBER = ENV['TO_NUMBER']
IMAGE_URL = ENV['IMAGE_URL']

client = Vonage::Client.new(
application_id: VONAGE_APPLICATION_ID,
private_key: File.read(VONAGE_APPLICATION_PRIVATE_KEY_PATH)
)

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
)
42 changes: 42 additions & 0 deletions messages/rcs/send-suggested-action-create-calendar-event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'dotenv/load'
require 'vonage'

VONAGE_APPLICATION_ID = ENV['VONAGE_APPLICATION_ID']
VONAGE_APPLICATION_PRIVATE_KEY_PATH = ENV['VONAGE_APPLICATION_PRIVATE_KEY_PATH']
RCS_SENDER_ID = ENV['RCS_SENDER_ID']
TO_NUMBER = ENV['TO_NUMBER']

client = Vonage::Client.new(
application_id: VONAGE_APPLICATION_ID,
private_key: File.read(VONAGE_APPLICATION_PRIVATE_KEY_PATH)
)

message = client.messaging.rcs(
type: 'custom',
message: {
contentMessage: {
text: "Product Launch: Save the date!",
suggestions: [
{
action: {
text: "Save to calendar",
postbackData: "postback_data_1234",
fallbackUrl: "https://www.google.com/calendar",
createCalendarEventAction: {
startTime: "2024-08-24T20:00:00Z",
endTime: "2024-08-24T22:00:00Z",
title: "Vonage API Product Launch",
description: "Join us for the launch of our latest product!",
}
}
}
]
}
}
)

client.messaging.send(
from: RCS_SENDER_ID,
to: TO_NUMBER,
**message
)
39 changes: 39 additions & 0 deletions messages/rcs/send-suggested-action-dial.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'dotenv/load'
require 'vonage'

VONAGE_APPLICATION_ID = ENV['VONAGE_APPLICATION_ID']
VONAGE_APPLICATION_PRIVATE_KEY_PATH = ENV['VONAGE_APPLICATION_PRIVATE_KEY_PATH']
RCS_SENDER_ID = ENV['RCS_SENDER_ID']
TO_NUMBER = ENV['TO_NUMBER']

client = Vonage::Client.new(
application_id: VONAGE_APPLICATION_ID,
private_key: File.read(VONAGE_APPLICATION_PRIVATE_KEY_PATH)
)

message = client.messaging.rcs(
type: 'custom',
message: {
contentMessage: {
text: "Call us to claim your free gift!",
suggestions: [
{
action: {
text: "Call now!",
postbackData: "postback_data_1234",
fallbackUrl: "https://www.example.com/contact/",
dialAction: {
phoneNumber: "+447900000000"
}
}
}
]
}
}
)

client.messaging.send(
from: RCS_SENDER_ID,
to: TO_NUMBER,
**message
)
48 changes: 48 additions & 0 deletions messages/rcs/send-suggested-action-multiple.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require 'dotenv/load'
require 'vonage'

VONAGE_APPLICATION_ID = ENV['VONAGE_APPLICATION_ID']
VONAGE_APPLICATION_PRIVATE_KEY_PATH = ENV['VONAGE_APPLICATION_PRIVATE_KEY_PATH']
RCS_SENDER_ID = ENV['RCS_SENDER_ID']
TO_NUMBER = ENV['TO_NUMBER']

client = Vonage::Client.new(
application_id: VONAGE_APPLICATION_ID,
private_key: File.read(VONAGE_APPLICATION_PRIVATE_KEY_PATH)
)

message = client.messaging.rcs(
type: 'custom',
message: {
contentMessage: {
text: "Need some help? Call us now or visit our website for more information.",
suggestions: [
{
action: {
text: "Call us",
postbackData: "postback_data_1234",
fallbackUrl: "https://www.example.com/contact/",
dialAction: {
phoneNumber: "+447900000000"
}
}
},
{
action: {
text: "Visit site",
postbackData: "postback_data_1234",
openUrlAction: {
url: "http://example.com/"
}
}
}
]
}
}
)

client.messaging.send(
from: RCS_SENDER_ID,
to: TO_NUMBER,
**message
)
38 changes: 38 additions & 0 deletions messages/rcs/send-suggested-action-open-url.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'dotenv/load'
require 'vonage'

VONAGE_APPLICATION_ID = ENV['VONAGE_APPLICATION_ID']
VONAGE_APPLICATION_PRIVATE_KEY_PATH = ENV['VONAGE_APPLICATION_PRIVATE_KEY_PATH']
RCS_SENDER_ID = ENV['RCS_SENDER_ID']
TO_NUMBER = ENV['TO_NUMBER']

client = Vonage::Client.new(
application_id: VONAGE_APPLICATION_ID,
private_key: File.read(VONAGE_APPLICATION_PRIVATE_KEY_PATH)
)

message = client.messaging.rcs(
type: 'custom',
message: {
contentMessage: {
text: "Check out our latest offers!",
suggestions: [
{
action: {
text: "Open product page",
postbackData: "postback_data_1234",
openUrlAction: {
url: "http://example.com/"
}
}
}
]
}
}
)

client.messaging.send(
from: RCS_SENDER_ID,
to: TO_NUMBER,
**message
)
Loading

0 comments on commit 1c94038

Please sign in to comment.