Class: Nexmo::Voice

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

Defined Under Namespace

Classes: DTMF, ListResponse, 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 (required, Hash)

    Connect to a Phone (PSTN) number.

  • :ncco (Array<String>)

    The Nexmo 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 Nexmo 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 Nexmo detects that the call is answered by voicemail.

  • :length_timer (Integer)

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

  • :ringing_timer (Integer)

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

Returns:

See Also:



57
58
59
# File 'lib/nexmo/voice.rb', line 57

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

#dtmfDTMF

Returns:



246
247
248
# File 'lib/nexmo/voice.rb', line 246

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:



192
193
194
# File 'lib/nexmo/voice.rb', line 192

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:



111
112
113
# File 'lib/nexmo/voice.rb', line 111

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:



147
148
149
# File 'lib/nexmo/voice.rb', line 147

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

#list(params = nil) ⇒ 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.

Returns:

See Also:



96
97
98
# File 'lib/nexmo/voice.rb', line 96

def list(params = nil)
  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:



162
163
164
# File 'lib/nexmo/voice.rb', line 162

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

#streamStream

Returns:



234
235
236
# File 'lib/nexmo/voice.rb', line 234

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

#talkTalk

Returns:



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

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:



228
229
230
# File 'lib/nexmo/voice.rb', line 228

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:



207
208
209
# File 'lib/nexmo/voice.rb', line 207

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:



177
178
179
# File 'lib/nexmo/voice.rb', line 177

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:



132
133
134
# File 'lib/nexmo/voice.rb', line 132

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