-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEVX-8697: Messages API Updates for RCS and WhatsApp (#316)
* Implementing RCS channel in Messages API * Implementing Messaging update method * Adding code somments for update method * Adding rcs to CHANNELS hash in Message class * Bumping version and updating changelog
- Loading branch information
1 parent
e5c41f1
commit 6e799a0
Showing
10 changed files
with
312 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# typed: true | ||
|
||
module Vonage | ||
class Messaging::Channels::RCS < Messaging::Message | ||
MESSAGE_TYPES = ['text', 'image', 'video', 'file', 'custom'] | ||
|
||
attr_reader :data | ||
|
||
def initialize(attributes = {}) | ||
@type = attributes.fetch(:type, nil) | ||
@message = attributes.fetch(:message, nil) | ||
@opts = attributes.fetch(:opts, {}) | ||
@data = {} | ||
|
||
after_initialize! | ||
end | ||
|
||
private | ||
|
||
def build | ||
data[:channel] = 'rcs' | ||
super | ||
end | ||
|
||
def verify_type | ||
raise ClientError.new("Invalid message type") unless MESSAGE_TYPES.include?(type) | ||
end | ||
|
||
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' | ||
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 | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# typed: strong | ||
|
||
module Vonage | ||
VERSION = '7.26.0' | ||
VERSION = '7.27.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,226 @@ | ||
# typed: false | ||
|
||
|
||
class Vonage::Messaging::Channels::RCSTest < Vonage::Test | ||
def test_rcs_initialize | ||
message = Vonage::Messaging::Channels::RCS.new(type: 'text', message: 'Hello world!') | ||
|
||
assert_kind_of Vonage::Messaging::Channels::RCS, message | ||
end | ||
|
||
def test_rcs_text_message | ||
expected = { | ||
channel: 'rcs', | ||
message_type: 'text', | ||
text: 'Hello world!' | ||
} | ||
|
||
message = Vonage::Messaging::Channels::RCS.new( | ||
type: 'text', | ||
message: 'Hello world!' | ||
) | ||
|
||
assert_equal expected, message.data | ||
end | ||
|
||
def test_rcs_text_message_wth_optional_parameters | ||
expected = { | ||
channel: 'rcs', | ||
message_type: 'text', | ||
text: 'Hello world!', | ||
ttl: 600, | ||
client_ref: "abc123", | ||
webhook_url: "https://example.com/status" | ||
} | ||
|
||
message = Vonage::Messaging::Channels::RCS.new( | ||
type: 'text', | ||
message: 'Hello world!', | ||
opts: { | ||
ttl: 600, | ||
client_ref: "abc123", | ||
webhook_url: "https://example.com/status" | ||
} | ||
) | ||
|
||
assert_equal expected, message.data | ||
end | ||
|
||
def test_rcs_image_message | ||
expected = { | ||
channel: 'rcs', | ||
message_type: 'image', | ||
image: { | ||
url: 'https://example.com/image.jpg' | ||
} | ||
} | ||
|
||
message = Vonage::Messaging::Channels::RCS.new( | ||
type: 'image', | ||
message: { | ||
url: 'https://example.com/image.jpg' | ||
} | ||
) | ||
|
||
assert_equal expected, message.data | ||
end | ||
|
||
def test_rcs_video_message | ||
expected = { | ||
channel: 'rcs', | ||
message_type: 'image', | ||
image: { | ||
url: 'https://example.com/video.webm' | ||
} | ||
} | ||
|
||
message = Vonage::Messaging::Channels::RCS.new( | ||
type: 'image', | ||
message: { | ||
url: 'https://example.com/video.webm' | ||
} | ||
) | ||
|
||
assert_equal expected, message.data | ||
end | ||
|
||
def test_rcs_file_message | ||
expected = { | ||
channel: 'rcs', | ||
message_type: 'file', | ||
file: { | ||
url: 'https://example.com/file.pdf' | ||
} | ||
} | ||
|
||
message = Vonage::Messaging::Channels::RCS.new( | ||
type: 'file', | ||
message: { | ||
url: 'https://example.com/file.pdf' | ||
} | ||
) | ||
|
||
assert_equal expected, message.data | ||
end | ||
|
||
def test_rcs_custom_message | ||
expected = { | ||
channel: 'rcs', | ||
message_type: 'custom', | ||
custom: { | ||
contentMessage: { | ||
text: 'Which ice-cream flavour do you prefer?', | ||
suggestions: [ | ||
{ | ||
reply: { | ||
text: 'Vanilla', | ||
postback: 'vanilla' | ||
} | ||
}, | ||
{ | ||
reply: { | ||
text: 'Chocolate', | ||
postback: 'chocolate' | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
|
||
message = Vonage::Messaging::Channels::RCS.new( | ||
type: 'custom', | ||
message: { | ||
contentMessage: { | ||
text: 'Which ice-cream flavour do you prefer?', | ||
suggestions: [ | ||
{ | ||
reply: { | ||
text: 'Vanilla', | ||
postback: 'vanilla' | ||
} | ||
}, | ||
{ | ||
reply: { | ||
text: 'Chocolate', | ||
postback: 'chocolate' | ||
} | ||
} | ||
] | ||
} | ||
} | ||
) | ||
|
||
assert_equal expected, message.data | ||
end | ||
|
||
def test_rcs_invalid_message_type | ||
exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'invalid', message: 'Hello world!') } | ||
|
||
assert_instance_of Vonage::ClientError, exception | ||
assert_match "Invalid message type", exception.message | ||
end | ||
|
||
def test_rcs_text_message_invalid_type | ||
exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'text', message: 123) } | ||
|
||
assert_instance_of Vonage::ClientError, exception | ||
assert_match "Invalid parameter type. `:message` must be a String", exception.message | ||
end | ||
|
||
def test_rcs_image_message_invalid_type | ||
exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'image', message: 'https://example.com/image.jpg') } | ||
|
||
assert_instance_of Vonage::ClientError, exception | ||
assert_match "Invalid parameter type. `:message` must be a Hash", exception.message | ||
end | ||
|
||
def test_rcs_image_message_missing_url | ||
exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'image', message: {}) } | ||
|
||
assert_instance_of Vonage::ClientError, exception | ||
assert_match "Missing parameter. `:message` must contain a `:url` key", exception.message | ||
end | ||
|
||
def test_rcs_video_message_invalid_type | ||
exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'video', message: 'https://example.com/video.webm') } | ||
|
||
assert_instance_of Vonage::ClientError, exception | ||
assert_match "Invalid parameter type. `:message` must be a Hash", exception.message | ||
end | ||
|
||
def test_rcs_video_message_missing_url | ||
exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'video', message: {}) } | ||
|
||
assert_instance_of Vonage::ClientError, exception | ||
assert_match "Missing parameter. `:message` must contain a `:url` key", exception.message | ||
end | ||
|
||
def test_rcs_file_message_invalid_type | ||
exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'file', message: 'https://example.com/file.pdf') } | ||
|
||
assert_instance_of Vonage::ClientError, exception | ||
assert_match "Invalid parameter type. `:message` must be a Hash", exception.message | ||
end | ||
|
||
def test_rcs_file_message_missing_url | ||
exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'file', message: {}) } | ||
|
||
assert_instance_of Vonage::ClientError, exception | ||
assert_match "Missing parameter. `:message` must contain a `:url` key", exception.message | ||
end | ||
|
||
def test_rcs_custom_message_invalid_type | ||
exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'custom', message: 'Hello world!') } | ||
|
||
assert_instance_of Vonage::ClientError, exception | ||
assert_match "Invalid parameter type. `:message` must be a Hash", exception.message | ||
end | ||
|
||
def test_rcs_custom_message_with_empty_message_hash | ||
exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'custom', message: {}) } | ||
|
||
assert_instance_of Vonage::ClientError, exception | ||
assert_match "Invalid parameter content. `:message` must not be empty", exception.message | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters