Class: Nexmo::Calls

Inherits:
Namespace
  • Object
show all
Defined in:
lib/nexmo/calls.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.calls.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:


56
57
58
# File 'lib/nexmo/calls.rb', line 56

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

#dtmfDTMF

Returns:


245
246
247
# File 'lib/nexmo/calls.rb', line 245

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

#earmuff(id) ⇒ Response

Earmuff an in progress call.

Examples:

response = client.calls.earmuff(id)

Parameters:

  • id (String)

Returns:

See Also:


191
192
193
# File 'lib/nexmo/calls.rb', line 191

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

#get(id) ⇒ Response

Get detail of a specific call.

Examples:

response = client.calls.get(id)

Parameters:

  • id (String)

Returns:

See Also:


110
111
112
# File 'lib/nexmo/calls.rb', line 110

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

#hangup(id) ⇒ Response

Hangup an in progress call.

Examples:

response = client.calls.hangup(id)

Parameters:

  • id (String)

Returns:

See Also:


146
147
148
# File 'lib/nexmo/calls.rb', line 146

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

#list(params = nil) ⇒ ListResponse

Get details of your calls.

Examples:

response = client.calls.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:


95
96
97
# File 'lib/nexmo/calls.rb', line 95

def list(params = nil)
  request('/v1/calls', params: params, response_class: ListResponse)
end

#mute(id) ⇒ Response

Mute an in progress call.

Examples:

response = client.calls.mute(id)

Parameters:

  • id (String)

Returns:

See Also:


161
162
163
# File 'lib/nexmo/calls.rb', line 161

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

#streamStream

Returns:


233
234
235
# File 'lib/nexmo/calls.rb', line 233

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

#talkTalk

Returns:


239
240
241
# File 'lib/nexmo/calls.rb', line 239

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.calls.transfer(id, destination: destination)

Parameters:

  • id (String)
  • destination (Hash)

Returns:

See Also:


227
228
229
# File 'lib/nexmo/calls.rb', line 227

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

#unearmuff(id) ⇒ Response

Unearmuff an in progress call.

Examples:

response = client.calls.unearmuff(id)

Parameters:

  • id (String)

Returns:

See Also:


206
207
208
# File 'lib/nexmo/calls.rb', line 206

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

#unmute(id) ⇒ Response

Unmute an in progress call.

Examples:

response = client.calls.unmute(id)

Parameters:

  • id (String)

Returns:

See Also:


176
177
178
# File 'lib/nexmo/calls.rb', line 176

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

#update(id, params) ⇒ Response

Modify an in progress call.

Examples:

response = client.calls.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:


131
132
133
# File 'lib/nexmo/calls.rb', line 131

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