Skip to content

Commit 5663d17

Browse files
authored
feat: Adding and Updating MMS and RCS snippets (#119)
1 parent 8d60296 commit 5663d17

13 files changed

+277
-211
lines changed

messages/mms/send-mms-content.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'dotenv/load'
2+
require 'vonage'
3+
4+
VONAGE_APPLICATION_ID = ENV['VONAGE_APPLICATION_ID']
5+
VONAGE_PRIVATE_KEY = ENV['VONAGE_PRIVATE_KEY']
6+
MMS_SENDER_ID = ENV['MMS_SENDER_ID']
7+
MESSAGES_TO_NUMBER = ENV['MESSAGES_TO_NUMBER']
8+
MESSAGES_IMAGE_URL = ENV['MESSAGES_IMAGE_URL']
9+
MESSAGES_FILE_URL = ENV['MESSAGES_FILE_URL']
10+
11+
client = Vonage::Client.new(
12+
application_id: VONAGE_APPLICATION_ID,
13+
private_key: VONAGE_PRIVATE_KEY
14+
)
15+
16+
message = client.messaging.mms(
17+
type: 'content',
18+
message: [
19+
{
20+
type: 'image',
21+
url: MESSAGES_IMAGE_URL
22+
},
23+
{
24+
type: 'file',
25+
url: MESSAGES_FILE_URL
26+
}
27+
]
28+
)
29+
30+
client.messaging.send(
31+
from: MMS_SENDER_ID,
32+
to: MESSAGES_TO_NUMBER,
33+
**message
34+
)

messages/mms/send-mms-file.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'dotenv/load'
2+
require 'vonage'
3+
4+
VONAGE_APPLICATION_ID = ENV['VONAGE_APPLICATION_ID']
5+
VONAGE_PRIVATE_KEY = ENV['VONAGE_PRIVATE_KEY']
6+
MMS_SENDER_ID = ENV['MMS_SENDER_ID']
7+
MESSAGES_TO_NUMBER = ENV['MESSAGES_TO_NUMBER']
8+
MESSAGES_FILE_URL = ENV['MESSAGES_FILE_URL']
9+
10+
client = Vonage::Client.new(
11+
application_id: VONAGE_APPLICATION_ID,
12+
private_key: VONAGE_PRIVATE_KEY
13+
)
14+
15+
message = client.messaging.mms(
16+
type: 'file',
17+
message: {
18+
url: MESSAGES_FILE_URL
19+
}
20+
)
21+
22+
client.messaging.send(
23+
from: MMS_SENDER_ID,
24+
to: MESSAGES_TO_NUMBER,
25+
**message
26+
)

messages/mms/send-mms-text.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'dotenv/load'
2+
require 'vonage'
3+
4+
VONAGE_APPLICATION_ID = ENV['VONAGE_APPLICATION_ID']
5+
VONAGE_PRIVATE_KEY = ENV['VONAGE_PRIVATE_KEY']
6+
MMS_SENDER_ID = ENV['MMS_SENDER_ID']
7+
MESSAGES_TO_NUMBER = ENV['MESSAGES_TO_NUMBER']
8+
9+
client = Vonage::Client.new(
10+
application_id: VONAGE_APPLICATION_ID,
11+
private_key: VONAGE_PRIVATE_KEY
12+
)
13+
14+
message = client.messaging.mms(
15+
type: 'text',
16+
message: "This is an MMS text message sent via the Vonage Messages API."
17+
)
18+
19+
client.messaging.send(
20+
from: MMS_SENDER_ID,
21+
to: MESSAGES_TO_NUMBER,
22+
**message
23+
)

messages/rcs/send-rich-card-carousel.rb

Lines changed: 38 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,54 +14,46 @@
1414
)
1515

1616
message = client.messaging.rcs(
17-
type: 'custom',
17+
type: 'carousel',
1818
message: {
19-
contentMessage: {
20-
richCard: {
21-
carouselCard: {
22-
cardWidth: "MEDIUM",
23-
cardContents: [
24-
{
25-
title: "Option 1: Photo",
26-
description: "Do you prefer this photo?",
27-
media: {
28-
height: "MEDIUM",
29-
contentInfo: {
30-
fileUrl: MESSAGES_IMAGE_URL,
31-
forceRefresh: false
32-
}
33-
},
34-
suggestions: [
35-
{
36-
reply: {
37-
text: "Option 1",
38-
postbackData: "card_1"
39-
}
40-
}
41-
]
42-
},
43-
{
44-
title: "Option 1: Video",
45-
description: "Or this video?",
46-
media: {
47-
height: "MEDIUM",
48-
contentInfo: {
49-
fileUrl: MESSAGES_VIDEO_URL,
50-
forceRefresh: false
51-
}
52-
},
53-
suggestions: [
54-
{
55-
reply: {
56-
text: "Option 2",
57-
postbackData: "card_2"
58-
}
59-
}
60-
]
61-
}
62-
]
63-
}
19+
cards: [
20+
{
21+
title: "Option 1: Photo",
22+
text: "Do you prefer this photo?",
23+
media_url: MESSAGES_IMAGE_URL,
24+
media_height: "SHORT",
25+
media_description: "Picture of a cat",
26+
thumbnail_url: MESSAGES_IMAGE_URL,
27+
media_force_refresh: false,
28+
suggestions: [
29+
{
30+
type: "reply",
31+
text: "Option 1",
32+
postback_data: "card_1"
33+
}
34+
]
35+
},
36+
{
37+
title: "Option 2: Video",
38+
text: "Or this video?",
39+
media_url: MESSAGES_VIDEO_URL,
40+
media_height: "SHORT",
41+
media_description: "Video of a cat",
42+
thumbnail_url: MESSAGES_IMAGE_URL,
43+
media_force_refresh: false,
44+
suggestions: [
45+
{
46+
type: "reply",
47+
text: "Option 2",
48+
postback_data: "card_2"
49+
}
50+
]
6451
}
52+
]
53+
},
54+
opts: {
55+
rcs: {
56+
card_width: "SMALL"
6557
}
6658
}
6759
)

messages/rcs/send-rich-card-standalone.rb

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,32 @@
1313
)
1414

1515
message = client.messaging.rcs(
16-
type: 'custom',
16+
type: 'card',
1717
message: {
18-
contentMessage: {
19-
richCard: {
20-
standaloneCard: {
21-
thumbnailImageAlignment: "RIGHT",
22-
cardOrientation: "VERTICAL",
23-
cardContent: {
24-
title: "Quick question",
25-
description: "Do you like this picture?",
26-
media: {
27-
height: "TALL",
28-
contentInfo: {
29-
fileUrl: MESSAGES_IMAGE_URL,
30-
forceRefresh: false
31-
}
32-
},
33-
suggestions: [
34-
{
35-
reply: {
36-
text: "Yes",
37-
postbackData: "suggestion_1"
38-
}
39-
},
40-
{
41-
reply: {
42-
text: "I love it!",
43-
postbackData: "suggestion_2"
44-
}
45-
}
46-
]
47-
}
48-
}
18+
title: "Quick question",
19+
text: "Do you like this picture?",
20+
media_url: MESSAGES_IMAGE_URL,
21+
media_height: "SHORT",
22+
media_description: "Picture of a cat",
23+
thumbnail_url: MESSAGES_IMAGE_URL,
24+
media_force_refresh: false,
25+
suggestions: [
26+
{
27+
type: "reply",
28+
text: "Yes",
29+
postback_data: "suggestion_1"
30+
},
31+
{
32+
type: "reply",
33+
text: "I love it!",
34+
postback_data: "suggestion_2"
4935
}
36+
]
37+
},
38+
opts: {
39+
rcs: {
40+
card_orientation: "HORIZONTAL",
41+
image_alignment: "RIGHT"
5042
}
5143
}
5244
)

messages/rcs/send-suggested-action-create-calendar-event.rb

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,21 @@
1212
)
1313

1414
message = client.messaging.rcs(
15-
type: 'custom',
16-
message: {
17-
contentMessage: {
18-
text: "Product Launch: Save the date!",
19-
suggestions: [
20-
{
21-
action: {
22-
text: "Save to calendar",
23-
postbackData: "postback_data_1234",
24-
fallbackUrl: "https://www.google.com/calendar",
25-
createCalendarEventAction: {
26-
startTime: "2024-08-24T20:00:00Z",
27-
endTime: "2024-08-24T22:00:00Z",
28-
title: "Vonage API Product Launch",
29-
description: "Event to demo a new and exciting Vonage API product"
30-
}
31-
}
32-
}
33-
]
34-
}
15+
type: 'text',
16+
message: "Product Launch: Save the date!",
17+
opts: {
18+
suggestions: [
19+
{
20+
type: "create_calendar_event",
21+
text: "Save to calendar",
22+
postback_data: "postback_data_1234",
23+
start_time: "2024-08-24T20:00:00Z",
24+
end_time: "2024-08-24T22:00:00Z",
25+
title: "Vonage API Product Launch",
26+
description: "Event to demo a new and exciting Vonage API product",
27+
fallback_url: "https://www.google.com/calendar"
28+
}
29+
]
3530
}
3631
)
3732

messages/rcs/send-suggested-action-dial.rb

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,18 @@
1212
)
1313

1414
message = client.messaging.rcs(
15-
type: 'custom',
16-
message: {
17-
contentMessage: {
18-
text: "Call us to claim your free gift!",
19-
suggestions: [
20-
{
21-
action: {
22-
text: "Call now!",
23-
postbackData: "postback_data_1234",
24-
fallbackUrl: "https://www.example.com/contact/",
25-
dialAction: {
26-
phoneNumber: "+447900000000"
27-
}
28-
}
29-
}
30-
]
31-
}
15+
type: 'text',
16+
message: "Call us to claim your free gift!",
17+
opts: {
18+
suggestions: [
19+
{
20+
type: "dial",
21+
text: "Call now!",
22+
postback_data: "postback_data_1234",
23+
phone_number: "+447900000000",
24+
fallback_url: "https://www.example.com/contact/"
25+
}
26+
]
3227
}
3328
)
3429

messages/rcs/send-suggested-action-multiple.rb

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,25 @@
1212
)
1313

1414
message = client.messaging.rcs(
15-
type: 'custom',
16-
message: {
17-
contentMessage: {
18-
text: "Need some help? Call us now or visit our website for more information.",
19-
suggestions: [
20-
{
21-
action: {
22-
text: "Call us",
23-
postbackData: "postback_data_1234",
24-
fallbackUrl: "https://www.example.com/contact/",
25-
dialAction: {
26-
phoneNumber: "+447900000000"
27-
}
28-
}
29-
},
30-
{
31-
action: {
32-
text: "Visit site",
33-
postbackData: "postback_data_1234",
34-
openUrlAction: {
35-
url: "http://example.com/"
36-
}
37-
}
38-
}
39-
]
40-
}
15+
type: 'text',
16+
message: "Need some help? Call us now or visit our website for more information.",
17+
opts: {
18+
suggestions: [
19+
{
20+
type: "dial",
21+
text: "Call us",
22+
postback_data: "postback_data_1234",
23+
phone_number: "+447900000000",
24+
fallback_url: "https://www.example.com/contact/"
25+
},
26+
{
27+
type: "open_url",
28+
text: "Visit site",
29+
postback_data: "postback_data_1234",
30+
url: "https://www.example.com/",
31+
description: "A URL for the Example website"
32+
}
33+
]
4134
}
4235
)
4336

0 commit comments

Comments
 (0)