Docs

Implementation of the consistent callback case

Step 1. Prerequisites

Customer's server makes consistent calls to managers via Apifonica API. The first responding manager is connected with the client.

diagramma.png

1. Rent an Apifonica local or virtual phone number which will be used for calling from server (in our example it will be number 883140000000000). Using personal account you can search and rent a number here

2. Rent an Apifonica local or virtual phone numbers which will be used to receive calls for managers (in our example it will be numbers 883140000000111 and 883140000000222). Using personal account you can search and rent a number here

3. Create an applications for playback of welcome audio and for end of the call. Using personal account you can create it here.

The result will be like that:

    {
      "application_sid": "app79977b9a-3cdb-3b35-b79d-111111111111",
      "controller": "http://server.com/manager",
      "method": "POST",
      "name": "Play manager intro",
      "account_sid": "acc6debab73-74cc-3eb1-a1f4-aaaaaaaaaaaa"
    }
    {
      "application_sid": "appffdcf01d-899f-3dc5-8ae8-222222222222",
      "controller": "http://server.com/end-call",
      "method": "POST",
      "name": "End call",
      "account_sid": "acc6debab73-74cc-3eb1-a1f4-aaaaaaaaaaaa"
    }

Step 2. Action’s sequence

Calls to manager №1 and manager №2

POST requests to /accounts/acc6debab73-74cc-3eb1-a1f4-aaaaaaaaaaaa/calls

The result will be like that:

{
  "from": "883140000000000",
  "to": "883140000000111",
  "call_app_sid": "app79977b9a-3cdb-3b35-b79d-111111111111",
  "timeout": 60,
  "events": "all"
}

The CallSID cal3bec98d4-42d3-3623-aefb-сссссс111111 is received in the reply of the API

{
  "from": "883140000000000",
  "to": "883140000000222",
  "call_app_sid": "app79977b9a-3cdb-3b35-b79d-111111111111",
  "timeout": 60,
  "events": "all"
}

The CallSID cal3bec98d4-42d3-3623-aefb-сссссс222222 is received in the reply of the API

Customer’s server

The customer’s server ignores all statuses, except queued, answered, and modified.

The server is notified by call statuses with the following parameters:

POST http://server.com/manager

{
  "call_sid": "cal3bec98d4-42d3-3623-aefb-сссссс222222",
  "created": "2017-04-24 09:12:09",
  "status": "queued",
  "from": "883140000000000",
  "to": "883140000000111",
  "direction": "outbound"
}

Step 3. Reply to the requests

Reply to the requests when status = queued

On all requests with the status queued, the server reply with the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<response>
    <playAudio>http://server.com/assets/music/waiting.mp3</playAudio>
</response>

In this case, the waiting.mp3 file will be played to the responding manager.

Reply to the requests when status = answered

Suppose the manager with the number 883140000000222 picked up the phone first, CallSID of this call: cal3bec98d4-42d3-3623-aefb-sssss222222.
On the first request with the answered status, the server responds with the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<response>
    <makeCall>
        <number>358999999999</number>
    </makeCall>
    <endCall/>
</response>

In this case, the manager will be connected to the client.

On subsequent requests with the answered status, the server responds with the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<response>
    <endCall/>
</response>

In this case, the remaining managers, who managed to pick up the phone before the end of the call, will hear a signal about the end of the call.

End of the dialing to the other managers

To stop dialing the other managers, after receiving the first request with the answered status, the customer’s server sends Modify the live call:

POST request to /accounts/acc6debab73-74cc-3eb1-a1f4-aaaaaaaaaaaa/calls/cal3bec98d4-42d3-3623-aefb-сссссс111111

{
  "call_app_sid": "app79977b9a-3cdb-3b35-b79d-222222222222"
}

This action initiates the following request to the customer’s server:

POST http://server.com/manager

{
  "call_sid": "cal3bec98d4-42d3-3623-aefb-сссссс111111",
  "created": "2017-04-24 09:12:35",
  "status": "modified",
  "from": "883140000000000",
  "to": "883140000000111",
  "direction": "outbound"
}

On this request, the customer’s server responds with the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<response>
    <endCall/>
</response>

After this, dialing to 883140000000111 will be stopped.