Skip to content

Commit

Permalink
Merge pull request #274 from Vonage/dev
Browse files Browse the repository at this point in the history
Release 7.11.0
  • Loading branch information
superchilled authored Jun 16, 2023
2 parents 8f87c6f + bfa33dd commit de29168
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 275 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 7.11.0

* Updates Voice API functionality. [#270](https://github.com/Vonage/vonage-ruby-sdk/pull/270)

# 7.10.0

* Adds Verify2. [#261](https://github.com/Vonage/vonage-ruby-sdk/pull/261)
Expand Down
2 changes: 1 addition & 1 deletion lib/vonage/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# typed: strong

module Vonage
VERSION = "7.10.0"
VERSION = "7.11.0"
end
11 changes: 11 additions & 0 deletions lib/vonage/voice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ class Voice < Namespace
# @option params [String] :machine_detection
# Configure the behavior when Vonage detects that the call is answered by voicemail.
#
# @option params [Hash] :advanced_machine_detection
# Configure the behavior of Vonage's advanced machine detection. Overrides machine_detection if both are set.
# Hash with three possible properties:
# - :behavior [String]: Must be one of `continue` or `hangup`. When hangup is used, the call will be terminated if a
# machine is detected. When continue is used, the call will continue even if a machine is detected.
# - :mode [String]: Must be one of `detect` or `detect_beep`. Detect if machine answered and sends a human or
# machine status in the webhook payload. When set to `detect_beep`, the system also attempts to detect
# voice mail beep and sends an additional parameter `sub_state` in the webhook with the value `beep_start`.
# - :beep_timeout [Integer]: Min: 45, Max: 120. Maximum time in seconds Vonage should wait for a machine beep
# to be detected. A machine event with `sub_state` set to `beep_timeout` will be sent if the timeout is exceeded.
#
# @option params [Integer] :length_timer
# Set the number of seconds that elapse before Vonage hangs up after the call state changes to in_progress.
#
Expand Down
30 changes: 27 additions & 3 deletions lib/vonage/voice/actions/connect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# frozen_string_literal: true
require 'phonelib'

module Vonage
module Vonage
class Voice::Actions::Connect
attr_accessor :endpoint, :from, :eventType, :timeout, :limit, :machineDetection, :eventUrl, :eventMethod, :ringbackTone
attr_accessor :endpoint, :from, :eventType, :timeout, :limit, :machineDetection, :advanced_machine_detection, :eventUrl, :eventMethod, :ringbackTone

def initialize(attributes = {})
@endpoint = attributes.fetch(:endpoint)
Expand All @@ -13,6 +13,7 @@ def initialize(attributes = {})
@timeout = attributes.fetch(:timeout, nil)
@limit = attributes.fetch(:limit, nil)
@machineDetection = attributes.fetch(:machineDetection, nil)
@advanced_machine_detection = attributes.fetch(:advanced_machine_detection, nil)
@eventUrl = attributes.fetch(:eventUrl, nil)
@eventMethod = attributes.fetch(:eventMethod, nil)
@ringbackTone = attributes.fetch(:ringbackTone, nil)
Expand All @@ -39,6 +40,10 @@ def after_initialize!
verify_machine_detection
end

if self.advanced_machine_detection
verify_advanced_machine_detection
end

if self.eventUrl
verify_event_url
end
Expand Down Expand Up @@ -82,6 +87,25 @@ def verify_machine_detection
raise ClientError.new("Invalid 'machineDetection' value, must be either: 'continue' or 'hangup' if defined") unless self.machineDetection == 'continue' || self.machineDetection == 'hangup'
end

def verify_advanced_machine_detection
raise ClientError.new("Invalid 'advanced_machine_detection' value, must be a Hash") unless self.advanced_machine_detection.is_a?(Hash)
verify_advanced_machine_detection_behavior if self.advanced_machine_detection[:behavior]
verify_advanced_machine_detection_mode if self.advanced_machine_detection[:mode]
verify_advanced_machine_detection_beep_timeout if self.advanced_machine_detection[:beep_timeout]
end

def verify_advanced_machine_detection_behavior
raise ClientError.new("Invalid 'advanced_machine_detection[:behavior]' value, must be a `continue` or `hangup`") unless ['continue', 'hangup'].include?(self.advanced_machine_detection[:behavior])
end

def verify_advanced_machine_detection_mode
raise ClientError.new("Invalid 'advanced_machine_detection[:mode]' value, must be a `detect` or `detect_beep`") unless ['detect', 'detect_beep'].include?(self.advanced_machine_detection[:mode])
end

def verify_advanced_machine_detection_beep_timeout
raise ClientError.new("Invalid 'advanced_machine_detection[:beep_timeout]' value, must be between 45 and 120") unless self.advanced_machine_detection[:beep_timeout].between?(45, 120)
end

def verify_event_url
uri = URI.parse(self.eventUrl)

Expand Down Expand Up @@ -196,4 +220,4 @@ def vbc_endpoint(endpoint_attrs)
}
end
end
end
end
107 changes: 0 additions & 107 deletions lib/vonage/voice/actions/pay.rb

This file was deleted.

13 changes: 11 additions & 2 deletions lib/vonage/voice/actions/talk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true
module Vonage
class Voice::Actions::Talk
attr_accessor :text, :bargeIn, :loop, :level, :language, :style
attr_accessor :text, :bargeIn, :loop, :level, :language, :style, :premium

def initialize(attributes= {})
@text = attributes.fetch(:text)
Expand All @@ -11,6 +11,7 @@ def initialize(attributes= {})
@level = attributes.fetch(:level, nil)
@language = attributes.fetch(:language, nil)
@style = attributes.fetch(:style, nil)
@premium = attributes.fetch(:premium, nil)

after_initialize!
end
Expand All @@ -31,6 +32,10 @@ def after_initialize!
if self.style
verify_style
end

if self.premium
verify_premium
end
end

def verify_barge_in
Expand All @@ -49,6 +54,10 @@ def verify_style
raise ClientError.new("Expected 'style' value to be an Integer") unless self.style.is_a?(Integer)
end

def verify_premium
raise ClientError.new("Expected 'premium' value to be a Boolean") unless self.premium == true || self.premium == false
end

def action
create_talk!(self)
end
Expand All @@ -70,4 +79,4 @@ def create_talk!(builder)
ncco
end
end
end
end
12 changes: 11 additions & 1 deletion lib/vonage/voice/talk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@ class Voice::Talk < Namespace
# @option params [required, String] :text
# The text to read.
#
# @option params [String] :language
# The language to use. See {https://developer.vonage.com/en/api/voice#startTalk-req-body} for a list of valid language codes.
#
# @option params [Integer] :style
# The vocal style, as identified by an assigned integer.
# See {https://developer.vonage.com/en/voice/voice-api/concepts/text-to-speech#supported-languages} for a list of available styles.
#
# @option params [Boolean] :premium
# Set to `true` to use the premium version of the specified style if available, otherwise the standard version will be used.
#
# @option params [String] :voice_name
# The voice & language to use.
# The voice & language to use. [DEPRECATED: use `language` and `style` instead].
#
# @option params [Integer] :loop
# The number of times to repeat the text the file, 0 for infinite.
Expand Down
30 changes: 27 additions & 3 deletions test/vonage/voice/actions/connect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def test_verify_endpoint_with_invalid_phone_number
endpoint = { type: 'phone', number: 'abcd' }

exception = assert_raises { Vonage::Voice::Actions::Connect.new(endpoint: endpoint) }

assert_match "Expected 'number' value to be in E.164 format", exception.message
end

def test_verify_with_invalid_from_number
exception = assert_raises { Vonage::Voice::Actions::Connect.new(endpoint: { type: 'phone', number: '12122222222' }, from: 'abcd') }

assert_match "Invalid 'from' value, must be in E.164 format", exception.message
end

Expand All @@ -62,6 +62,30 @@ def test_verify_with_invalid_machine_detection
assert_match "Invalid 'machineDetection' value, must be either: 'continue' or 'hangup' if defined", exception.message
end

def test_verify_with_invalid_advanced_machine_detection_data_type
exception = assert_raises { Vonage::Voice::Actions::Connect.new(endpoint: { type: 'phone', number: '12122222222' }, advanced_machine_detection: 'foo') }

assert_match "Invalid 'advanced_machine_detection' value, must be a Hash", exception.message
end

def test_verify_with_invalid_advanced_machine_detection_behavior
exception = assert_raises { Vonage::Voice::Actions::Connect.new(endpoint: { type: 'phone', number: '12122222222' }, advanced_machine_detection: {behavior: 'bar'}) }

assert_match "Invalid 'advanced_machine_detection[:behavior]' value, must be a `continue` or `hangup`", exception.message
end

def test_verify_with_invalid_advanced_machine_detection_mode
exception = assert_raises { Vonage::Voice::Actions::Connect.new(endpoint: { type: 'phone', number: '12122222222' }, advanced_machine_detection: {mode: 'qux'}) }

assert_match "Invalid 'advanced_machine_detection[:mode]' value, must be a `detect` or `detect_beep`", exception.message
end

def test_verify_with_invalid_advanced_machine_detection_beep_timeout
exception = assert_raises { Vonage::Voice::Actions::Connect.new(endpoint: { type: 'phone', number: '12122222222' }, advanced_machine_detection: {beep_timeout: 1}) }

assert_match "Invalid 'advanced_machine_detection[:beep_timeout]' value, must be between 45 and 120", exception.message
end

def test_verify_with_invalid_event_url
exception = assert_raises { Vonage::Voice::Actions::Connect.new(endpoint: { type: 'phone', number: '12122222222' }, eventUrl: 'invalid') }

Expand All @@ -80,4 +104,4 @@ def test_verify_with_invalid_ringback_tone
assert_match "Invalid 'ringbackTone' value, must be a valid URL", exception.message
end

end
end
Loading

0 comments on commit de29168

Please sign in to comment.