Skip to content

Voice API Service

Md. Mazharul islam Mithu edited this page May 4, 2017 · 4 revisions

1. Place a call

client = CheckMobi::Resources::Voice::Call.new(
           from: 'from_number',
           to: 'to_number',
           events: [], # array of events, default is [].
           notification_callback: 'http://valid_url',
           platform: 'web' # allowed values: ios, android, web, desktop
         )

To add some actions to the call

a. Play Action

play_action = CheckMobi::Resources::Voice::Actions::Play.new(
                 text: 'Any UTF-8 encoded text', # required
                 loop: 2, # => default 1
                 voice: 'MAN', # => default WOMAN, allowed values: WOMAN, MAN
                 language: 'en-AU', # => default is en-US
              )
client.events << play_action

b. Send DTMF

send_dtmf_action = CheckMobi::Resources::Voice::Actions::SendDTMF.new(
                       text: 'Any UTF-8 encoded text', # required
                       digits: '1W2',
                       async: false # => default is true
                   )
client.events << send_dtmf_action

c. Wait Action

wait_action = CheckMobi::Resources::Voice::Actions::Wait.new(
                       length: 2, # => default is 1
              )
client.events << wait_action

d. Hangup Action

hangup_action = CheckMobi::Resources::Voice::Actions::Hangup.new(
                       reason: 'rejected', # => allowed values: rejected, busy
              )
client.events << hangup_action

finally when you are done with adding events,

response = client.perform
details = JSON.parse(response.response_body)

if everything is ok,

{
    "id":"CAL-ED26AC71-807B-49B1-A81E-3956224A0CDC",
    "number_info":
        {
            "country_code":40,
            "country_iso_code":"RO",
            "carrier":"Orange",
            "is_mobile":true,
            "e164_format":"+40XXXXXXXXX",
            "formatting":"+40 XXX XXX XXX"
        }
}

For more info https://checkmobi.com/documentation.html#/place-call

2. Get call details

client = resource = CheckMobi::Resources::Voice::CallDetails.new(id: 'id')
response = client.perform
details = JSON.parse(response.response_body)

if everything is ok,

{
    "request_date": 1433451354,
    "to": "+XXXXXXX",
    "description": "MX - Orange",
    "duration_billed": 0,
    "charged_amount": 0,    
    "charged_rate": 0.0371    
}

For more details https://checkmobi.com/documentation.html#/call-status

3. Hangup Call

client = CheckMobi::Resources::Voice::HangupCall.new(req_id: 'req_id')
response = client.perform

if everything is ok,

response.status_code # => 204

For more details https://checkmobi.com/documentation.html#/hangup_call

Clone this wiki locally