class Nexmo::Voice

Public Instance Methods

create(params) click to toggle source

Create an outbound Call.

@example

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

@option params [required, Array<Hash>] :to

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

@option params [required, Hash] :from

Connect to a Phone (PSTN) number.

@option params [Array<String>] :ncco

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

@option params [Array<String>] :answer_url

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

@option params [String] :answer_method

The HTTP method used to send event information to answer_url.

@option params [required, Array<String>] :event_url

The webhook endpoint where call progress events are sent to.

@option params [String] :event_method

The HTTP method used to send event information to event_url.

@option params [String] :machine_detection

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

@option params [Integer] :length_timer

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

@option params [Integer] :ringing_timer

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

@param [Hash] params

@return [Response]

@see developer.nexmo.com/api/voice#createCall

# File lib/nexmo/voice.rb, line 57
def create(params)
  request('/v1/calls', params: params, type: Post)
end
dtmf() click to toggle source

@return [DTMF]

# File lib/nexmo/voice.rb, line 246
def dtmf
  @dtmf ||= DTMF.new(@config)
end
earmuff(id) click to toggle source

Earmuff an in progress call.

@example

response = client.voice.earmuff(id)

@param [String] id

@return [Response]

@see developer.nexmo.com/api/voice#updateCall

# File lib/nexmo/voice.rb, line 192
def earmuff(id)
  update(id, action: 'earmuff')
end
get(id) click to toggle source

Get detail of a specific call.

@example

response = client.voice.get(id)

@param [String] id

@return [Response]

@see developer.nexmo.com/api/voice#getCall

# File lib/nexmo/voice.rb, line 111
def get(id)
  request('/v1/calls/' + id)
end
hangup(id) click to toggle source

Hangup an in progress call.

@example

response = client.voice.hangup(id)

@param [String] id

@return [Response]

@see developer.nexmo.com/api/voice#updateCall

# File lib/nexmo/voice.rb, line 147
def hangup(id)
  update(id, action: 'hangup')
end
list(params = nil) click to toggle source

Get details of your calls.

@example

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

@option params [String] :status

Filter by call status.

@option params [String] :date_start

Return the records that occurred after this point in time.

@option params [String] :date_end

Return the records that occurred before this point in time.

@option params [Integer] :page_size

Return this amount of records in the response.

@option params [Integer] :record_index

Return calls from this index in the response.

@option params [String] :order

Either `ascending` or `descending` order.

@option params [String] :conversation_uuid

Return all the records associated with a specific conversation.

@param [Hash] params

@return [ListResponse]

@see developer.nexmo.com/api/voice#getCalls

# File lib/nexmo/voice.rb, line 96
def list(params = nil)
  request('/v1/calls', params: params, response_class: ListResponse)
end
mute(id) click to toggle source

Mute an in progress call.

@example

response = client.voice.mute(id)

@param [String] id

@return [Response]

@see developer.nexmo.com/api/voice#updateCall

# File lib/nexmo/voice.rb, line 162
def mute(id)
  update(id, action: 'mute')
end
stream() click to toggle source

@return [Stream]

# File lib/nexmo/voice.rb, line 234
def stream
  @stream ||= Stream.new(@config)
end
talk() click to toggle source

@return [Talk]

# File lib/nexmo/voice.rb, line 240
def talk
  @talk ||= Talk.new(@config)
end
transfer(id, destination:) click to toggle source

Transfer an in progress call.

@example

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

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

@param [String] id @param [Hash] destination

@return [Response]

@see developer.nexmo.com/api/voice#updateCall

# File lib/nexmo/voice.rb, line 228
def transfer(id, destination:)
  update(id, action: 'transfer', destination: destination)
end
unearmuff(id) click to toggle source

Unearmuff an in progress call.

@example

response = client.voice.unearmuff(id)

@param [String] id

@return [Response]

@see developer.nexmo.com/api/voice#updateCall

# File lib/nexmo/voice.rb, line 207
def unearmuff(id)
  update(id, action: 'unearmuff')
end
unmute(id) click to toggle source

Unmute an in progress call.

@example

response = client.voice.unmute(id)

@param [String] id

@return [Response]

@see developer.nexmo.com/api/voice#updateCall

# File lib/nexmo/voice.rb, line 177
def unmute(id)
  update(id, action: 'unmute')
end
update(id, params) click to toggle source

Modify an in progress call.

@example

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

@option params [required, String] :action

@option params [Hash] :destination

Required when **:action** is `transfer`.

@param [String] id @param [Hash] params

@return [Response]

@see developer.nexmo.com/api/voice#updateCall

# File lib/nexmo/voice.rb, line 132
def update(id, params)
  request('/v1/calls/' + id, params: params, type: Put)
end