Class: Vonage::Voice

Inherits:
Namespace
  • Object
show all
Defined in:
lib/vonage/voice.rb

Defined Under Namespace

Classes: DTMF, ListResponse, Ncco, Stream, Talk

Instance Method Summary collapse

Instance Method Details

#create(params) ⇒ Response

Create an outbound Call.

Examples:

response = client.voice.create({
  to: [{type: 'phone', number: '14843331234'}],
  from: {type: 'phone', number: '14843335555'},
  answer_url: ['https://example.com/answer']
})

Parameters:

  • params (Hash)

Options Hash (params):

  • :to (required, Array<Hash>)

    Connect to a Phone (PSTN) number, SIP Endpoint, Websocket, or VBC extension.

  • :from (Hash)

    Connect to a Phone (PSTN) number. Should not be set if :random_from_number is true If not set, then :random_from_number will automatically be set to true

  • :random_from_number (Boolean)

    Set to true to use random phone number as from. The number will be selected from the list of the numbers assigned to the current application. random_from_number: true cannot be used together with :from.

  • :ncco (Array<String>)

    The Vonage Call Control Object to use for this call. Required unless :answer_url is provided.

  • :answer_url (Array<String>)

    The webhook endpoint where you provide the Vonage Call Control Object that governs this call. Required unless :ncco is provided.

  • :answer_method (String)

    The HTTP method used to send event information to answer_url.

  • :event_url (required, Array<String>)

    The webhook endpoint where call progress events are sent to.

  • :event_method (String)

    The HTTP method used to send event information to event_url.

  • :machine_detection (String)

    Configure the behavior when Vonage detects that the call is answered by voicemail.

  • :advanced_machine_detection (Hash)

    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.
  • :length_timer (Integer)

    Set the number of seconds that elapse before Vonage hangs up after the call state changes to in_progress.

  • :ringing_timer (Integer)

    Set the number of seconds that elapse before Vonage hangs up after the call state changes to ringing.

Returns:

See Also:



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/vonage/voice.rb', line 74

def create(params)
  if params.key?(:from) && params[:random_from_number] == true
    raise ClientError.new("`from` should not be set if `random_from_number` is `true`")
  end

  if params && !params.key?(:from)
    params.merge!(random_from_number: true)
  end

  request('/v1/calls', params: params, type: Post)
end

#dtmfDTMF

Returns:



279
280
281
# File 'lib/vonage/voice.rb', line 279

def dtmf
  @dtmf ||= DTMF.new(@config)
end

#earmuff(id) ⇒ Response

Earmuff an in progress call.

Examples:

response = client.voice.earmuff(id)

Parameters:

  • id (String)

Returns:

See Also:



225
226
227
# File 'lib/vonage/voice.rb', line 225

def earmuff(id)
  update(id, action: 'earmuff')
end

#get(id) ⇒ Response

Get detail of a specific call.

Examples:

response = client.voice.get(id)

Parameters:

  • id (String)

Returns:

See Also:



144
145
146
# File 'lib/vonage/voice.rb', line 144

def get(id)
  request('/v1/calls/' + id)
end

#hangup(id) ⇒ Response

Hangup an in progress call.

Examples:

response = client.voice.hangup(id)

Parameters:

  • id (String)

Returns:

See Also:



180
181
182
# File 'lib/vonage/voice.rb', line 180

def hangup(id)
  update(id, action: 'hangup')
end

#list(params = nil, auto_advance = true) ⇒ ListResponse

Get details of your calls.

Examples:

response = client.voice.list
response.each do |item|
  puts "#{item.uuid} #{item.direction} #{item.status}"
end

Parameters:

  • params (Hash) (defaults to: nil)

Options Hash (params):

  • :status (String)

    Filter by call status.

  • :date_start (String)

    Return the records that occurred after this point in time.

  • :date_end (String)

    Return the records that occurred before this point in time.

  • :page_size (Integer)

    Return this amount of records in the response.

  • :record_index (Integer)

    Return calls from this index in the response.

  • :order (String)

    Either ascending or descending order.

  • :conversation_uuid (String)

    Return all the records associated with a specific conversation.

  • :auto_advance (Boolean)

    Set this to false to not auto-advance through all the pages in the record and collect all the data. The default is true.

Returns:

See Also:



125
126
127
128
129
130
131
# File 'lib/vonage/voice.rb', line 125

def list(params = nil, auto_advance = true)
  if params && !params.key?(:auto_advance)
    params.merge!(auto_advance: true)
  end

  request('/v1/calls', params: params, response_class: ListResponse)
end

#mute(id) ⇒ Response

Mute an in progress call.

Examples:

response = client.voice.mute(id)

Parameters:

  • id (String)

Returns:

See Also:



195
196
197
# File 'lib/vonage/voice.rb', line 195

def mute(id)
  update(id, action: 'mute')
end

#streamStream

Returns:



267
268
269
# File 'lib/vonage/voice.rb', line 267

def stream
  @stream ||= Stream.new(@config)
end

#talkTalk

Returns:



273
274
275
# File 'lib/vonage/voice.rb', line 273

def talk
  @talk ||= Talk.new(@config)
end

#transfer(id, destination:) ⇒ Response

Transfer an in progress call.

Examples:

destination = {
  type: 'ncco',
  url: ['https://example.com/ncco.json']
}

response = client.voice.transfer(id, destination: destination)

Parameters:

  • id (String)
  • destination (Hash)

Returns:

See Also:



261
262
263
# File 'lib/vonage/voice.rb', line 261

def transfer(id, destination:)
  update(id, action: 'transfer', destination: destination)
end

#unearmuff(id) ⇒ Response

Unearmuff an in progress call.

Examples:

response = client.voice.unearmuff(id)

Parameters:

  • id (String)

Returns:

See Also:



240
241
242
# File 'lib/vonage/voice.rb', line 240

def unearmuff(id)
  update(id, action: 'unearmuff')
end

#unmute(id) ⇒ Response

Unmute an in progress call.

Examples:

response = client.voice.unmute(id)

Parameters:

  • id (String)

Returns:

See Also:



210
211
212
# File 'lib/vonage/voice.rb', line 210

def unmute(id)
  update(id, action: 'unmute')
end

#update(id, params) ⇒ Response

Modify an in progress call.

Examples:

response = client.voice.update(id, action: 'hangup')

Parameters:

  • id (String)
  • params (Hash)

Options Hash (params):

  • :action (required, String)
  • :destination (Hash)

    Required when :action is transfer.

Returns:

See Also:



165
166
167
# File 'lib/vonage/voice.rb', line 165

def update(id, params)
  request('/v1/calls/' + id, params: params, type: Put)
end