Requirement

We needed to build a robust and highly available video and audio calling solution for the client. This was to be placed in the accompanying iOS, Android and Web Application so that anyone could call an interpreter on the fly. Previously only “On-Location” interpretation sessions were being held, so this solution was proposed to have all time connectivity anywhere in the world.

Twilio

Twilio is a third party API service that provides different communication solutions such as an Audio/Video API, Messaging service, SIP trunking among others. This was an obvious choice for our solution as we needed a service that would handle the codec and quality resolutions and leave us with a simple interface with which we could initiate and monitor calls.

Solution Implemented

The solution was designed to have three phases:

Phase 1:

In the first phase we added twilio SDK to our server side project which enabled us to authenticate with the said service. Since this was a VOIP call we had to handle everything from searching for a specific interpreter to call and handle all the events, which included people connecting in and out of the call and finally to end the call and bill the customer.

All the customer had to do was select the languages they spoke and needed interpretation   from, the rest was handled by our system. First we searched all the interpreters that spoke that language and were then pinged via push notifications (APNS or FCM). As soon as any interpreter answered the call we connected the two “Legs” of the call together.

After the server side of the code was completed we moved on to the client side in phase 2.

Phase 2:

After the server side code was completed we started implementation on the client side applications simultaneously. Twilio SDK was integrated into the iOS, Android and Web Application. As soon as a call was received the selected media was connected to the call. In case of an audio call the microphone and with video we had to connect the microphone and the camera as well as handle any hardware restrictions. The customer also had the option to add a third party into the call be it any other interpreter using our VOIP solution or a simple landline call over POTS.

Phase 3:

The last phase was attributed to billing and processing of the ended call. Once the call was over the customer was billed at a predefined rate depending on the interpreter and the language selected. The interpreter’s earnings were also transferred to them following the call.

Results

The result was a simple yet very effective two-to-three way communication solution that helped customers reach an interpreter instantly. We bridged the gap between different cultures and languages with a simple push of a button. This was particularly useful in cases of emergency when communication became a hurdle such as at a hospital or police case.

Code To Initiate Call:

try {
    $call = $this->client->calls->create(
        "client:$to",
        "client:$from",
        [
            'url' => secure_url('webhook/twilio/xml/add_client', [$callTrackingId]),
        ]
    );
} catch (\Exception $ex) {
    $this->response->say('Something went wrong, Sorry about that. Please try again later.');
    return $this->response;
}

Adding A Third Party in the Ongoing call:

try {
    $call = $this->client->calls->create(
        $to,
        $this->twilioNumber,
        [
            'url' => secure_url('webhook/twilio/xml/add_phone', [$roomName]),
            'method' => 'POST',
            'timeout' => 60,
            'statusCallbackMethod' => 'POST',
            'statusCallback' => secure_url('webhook/twilio/call_progress_events'),
            'statusCallbackEvent' => [
                'initiated', 'ringing', 'answered', 'completed',
            ], ]
    );
} catch (\Exception $ex) {
    throw new \App\Exceptions\Exception("The number $to is not a valid phone number.");
}
return $call->sid;

Ending The Call:

try {
        $call = $this->client->calls($sid)->update([
            'status' => 'completed',
        ]);
    } catch (\Exception $ex) {
        throw new \App\Exceptions\Exception('Something went wrong. Please try again later.');
    }
    return $call;
}

0 Comments

Leave a Reply