Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/vonage/messaging/channels/mms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Vonage
class Messaging::Channels::MMS < Messaging::Message
MESSAGE_TYPES = ['image', 'vcard', 'audio', 'video']
MESSAGE_TYPES = ['text', 'image', 'vcard', 'audio', 'video', 'file', 'content'].freeze

attr_reader :data

Expand All @@ -29,8 +29,16 @@ def verify_type
end

def verify_message
raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
raise Vonage::ClientError.new(":url is required in :message") unless message[:url]
case type
when 'text'
raise Vonage::ClientError.new("Invalid parameter type. `:message` must be a String") unless message.is_a? String
when 'content'
raise Vonage::ClientError.new("Invalid parameter type. `:message` must be an Array") unless message.is_a? Array
raise Vonage::ClientError.new("Invalid parameter content. `:message` must not be empty") if message.empty?
else
raise Vonage::ClientError.new("Invalid parameter type. `:message` must be a Hash") unless message.is_a? Hash
raise Vonage::ClientError.new("Missing parameter. `:message` must contain a `:url` key") unless message[:url]
end
end
end
end
4 changes: 2 additions & 2 deletions lib/vonage/messaging/channels/rcs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Vonage
class Messaging::Channels::RCS < Messaging::Message
MESSAGE_TYPES = ['text', 'image', 'video', 'file', 'custom']
MESSAGE_TYPES = ['text', 'image', 'video', 'file', 'card', 'carousel', 'custom']

attr_reader :data

Expand Down Expand Up @@ -32,7 +32,7 @@ def verify_message
case type
when 'text'
raise Vonage::ClientError.new("Invalid parameter type. `:message` must be a String") unless message.is_a? String
when 'custom'
when 'card', 'carousel', 'custom'
raise Vonage::ClientError.new("Invalid parameter type. `:message` must be a Hash") unless message.is_a? Hash
raise Vonage::ClientError.new("Invalid parameter content. `:message` must not be empty") if message.empty?
else
Expand Down
3 changes: 3 additions & 0 deletions lib/vonage/sms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class SMS < Namespace
# An optional string used to identify separate accounts using the SMS endpoint for billing purposes.
# To use this feature, please email [[email protected]](mailto:[email protected]).
#
# @option params [String] :trusted_number
# Setting this parameter to true overrides, on a per-message basis, any protections set up via Fraud Defender (Traffic Rules, SMS Burst Protection, AIT Protection).
#
# @param [Hash] params
#
# @return [Response]
Expand Down
27 changes: 24 additions & 3 deletions test/vonage/messaging/channels/mms_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ def test_mms_initialize
assert_equal mms.data, { channel: 'mms', message_type: 'image', image: { url: 'https://example.com/image.jpg' } }
end

def test_with_valid_type_text_specified
mms = Vonage::Messaging::Channels::MMS.new(type: 'text', message: 'Hello world!')

assert_equal 'text', mms.data[:message_type]
assert_includes mms.data, :text
end

def test_with_valid_type_image_specified
mms = Vonage::Messaging::Channels::MMS.new(type: 'image', message: { url: 'https://example.com/image.jpg' })

Expand Down Expand Up @@ -37,9 +44,23 @@ def test_with_valid_type_video_specified
assert_includes mms.data, :video
end

def test_with_valid_type_file_specified
mms = Vonage::Messaging::Channels::MMS.new(type: 'file', message: { url: 'https://example.com/file.pdf' })

assert_equal 'file', mms.data[:message_type]
assert_includes mms.data, :file
end

def test_with_valid_type_content_specified
mms = Vonage::Messaging::Channels::MMS.new(type: 'content', message: [{ type: "image", url: 'https://example.com/image.jpg' }])

assert_equal 'content', mms.data[:message_type]
assert_includes mms.data, :content
end

def test_with_invalid_type_specified
exception = assert_raises {
Vonage::Messaging::Channels::MMS.new(type: 'text', message: { url: 'https://example.com/video.mp4' })
Vonage::Messaging::Channels::MMS.new(type: 'foo', message: { url: 'https://example.com/video.mp4' })
}

assert_instance_of Vonage::ClientError, exception
Expand All @@ -58,7 +79,7 @@ def test_with_invalid_message_class
}

assert_instance_of Vonage::ClientError, exception
assert_match ":message must be a Hash", exception.message
assert_match "Invalid parameter type. `:message` must be a Hash", exception.message
end

def test_with_caption
Expand All @@ -74,7 +95,7 @@ def test_without_url
}

assert_instance_of Vonage::ClientError, exception
assert_match ":url is required in :message", exception.message
assert_match "Missing parameter. `:message` must contain a `:url` key", exception.message
end

def test_with_to_specified
Expand Down
256 changes: 254 additions & 2 deletions test/vonage/messaging/channels/rcs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ def test_rcs_text_message_wth_optional_parameters
text: 'Hello world!',
ttl: 600,
client_ref: "abc123",
webhook_url: "https://example.com/status"
webhook_url: "https://example.com/status",
rcs: {
category: 'transaction'
}
}

message = Vonage::Messaging::Channels::RCS.new(
Expand All @@ -39,7 +42,41 @@ def test_rcs_text_message_wth_optional_parameters
opts: {
ttl: 600,
client_ref: "abc123",
webhook_url: "https://example.com/status"
webhook_url: "https://example.com/status",
rcs: {
category: 'transaction'
}
}
)

assert_equal expected, message.data
end

def test_rcs_text_message_wth_suggestions
expected = {
channel: 'rcs',
message_type: 'text',
text: 'Hello world!',
suggestions: [
{
type: 'reply',
text: 'Yes',
postback: 'question_1_yes'
}
]
}

message = Vonage::Messaging::Channels::RCS.new(
type: 'text',
message: 'Hello world!',
opts: {
suggestions: [
{
type: 'reply',
text: 'Yes',
postback: 'question_1_yes'
}
]
}
)

Expand Down Expand Up @@ -103,6 +140,221 @@ def test_rcs_file_message
assert_equal expected, message.data
end

def test_rcs_card_message
expected = {
channel: 'rcs',
message_type: 'card',
card: {
title: 'Card Title',
text: 'Card Description',
media_url: 'https://example.com/image.jpg',
suggestions: [
{
type: 'reply',
text: 'Yes',
postback_data: 'question_1_yes'
}
]
},
rcs: {
card_orientation: 'VERTICAL',
image_alignment: 'LEFT'
}
}

message = Vonage::Messaging::Channels::RCS.new(
type: 'card',
message: {
title: 'Card Title',
text: 'Card Description',
media_url: 'https://example.com/image.jpg',
suggestions: [
{
type: 'reply',
text: 'Yes',
postback_data: 'question_1_yes'
}
]
},
opts: {
rcs: {
card_orientation: 'VERTICAL',
image_alignment: 'LEFT'
}
}
)

assert_equal expected, message.data
end

def test_rcs_carousel_message
expected = {
channel: 'rcs',
message_type: 'carousel',
carousel: {
cards: [
{
title: 'Card Title 1',
text: 'Card Description 1',
media_url: 'https://example.com/image1.jpg',
suggestions: [
{
type: 'reply',
text: 'Yes',
postback_data: 'question_1_yes'
}
]
},
{
title: 'Card Title 2',
text: 'Card Description 2',
media_url: 'https://example.com/image2.jpg',
suggestions: [
{
type: 'reply',
text: 'No',
postback_data: 'question_1_no'
}
]
}
]
},
rcs: {
card_width: 'SMALL'
}
}

message = Vonage::Messaging::Channels::RCS.new(
type: 'carousel',
message: {
cards: [
{
title: 'Card Title 1',
text: 'Card Description 1',
media_url: 'https://example.com/image1.jpg',
suggestions: [
{
type: 'reply',
text: 'Yes',
postback_data: 'question_1_yes'
}
]
},
{
title: 'Card Title 2',
text: 'Card Description 2',
media_url: 'https://example.com/image2.jpg',
suggestions: [
{
type: 'reply',
text: 'No',
postback_data: 'question_1_no'
}
]
}
]
},
opts: {
rcs: {
card_width: 'SMALL'
}
}
)

assert_equal expected, message.data
end

def test_rcs_carousel_message_with_suggestions
expected = {
channel: 'rcs',
message_type: 'carousel',
carousel: {
cards: [
{
title: 'Card Title 1',
text: 'Card Description 1',
media_url: 'https://example.com/image1.jpg',
suggestions: [
{
type: 'reply',
text: 'Yes',
postback_data: 'question_1_yes'
}
]
},
{
title: 'Card Title 2',
text: 'Card Description 2',
media_url: 'https://example.com/image2.jpg',
suggestions: [
{
type: 'reply',
text: 'No',
postback_data: 'question_1_no'
}
]
}
]
},
rcs: {
card_width: 'SMALL'
},
suggestions: [
{
type: 'reply',
text: 'Maybe',
postback_data: 'question_1_maybe'
}
]
}

message = Vonage::Messaging::Channels::RCS.new(
type: 'carousel',
message: {
cards: [
{
title: 'Card Title 1',
text: 'Card Description 1',
media_url: 'https://example.com/image1.jpg',
suggestions: [
{
type: 'reply',
text: 'Yes',
postback_data: 'question_1_yes'
}
]
},
{
title: 'Card Title 2',
text: 'Card Description 2',
media_url: 'https://example.com/image2.jpg',
suggestions: [
{
type: 'reply',
text: 'No',
postback_data: 'question_1_no'
}
]
}
]
},
opts: {
rcs: {
card_width: 'SMALL'
},
suggestions: [
{
type: 'reply',
text: 'Maybe',
postback_data: 'question_1_maybe'
}
]
}
)

assert_equal expected, message.data
end

def test_rcs_custom_message
expected = {
channel: 'rcs',
Expand Down
Loading