0

I want to integrate user to user audio call feature using Twilio API, is it possible in Twilio? if yes can you please provide a tutorial.

Here I have added the code:
1. For get token from the Twilio

$.post(url, function(data) {      
 // Set up the Twilio Client Device with the token
    Twilio.Device.setup(data.token);
});

and it returns the token using function

public function newToken(Request $request, ClientToken $clientToken)
    {
        $forPage = $request->input('forPage');
        $twilio = config('services.twilio');
        $applicationSid = $twilio['applicationSid'];
        $clientToken->allowClientOutgoing($applicationSid);

        if ($forPage === route('dashboard', [], false)) {
            $clientToken->allowClientIncoming('support_agent');
        } else {
            $clientToken->allowClientIncoming('customer');
        }

        $token = $clientToken->generateToken();
        return response()->json(['token' => $token]);
    }

When I make a call following javascript function start

function callCustomer(phoneNumber) {
    updateCallStatus("Calling " + phoneNumber + "...");

    var params = {"phoneNumber": phoneNumber};
    Twilio.Device.connect(params);
}

and then browser ask for the enable microphone and after allowing it plays the small audio say's that "Application error occurred, Good bye!".

Dev Ramesh
  • 353
  • 1
  • 12
  • Do you want to do so via an app, in the web browser or just over the users' phones? You've also tagged this click to call, should that be a part of the feature? – philnash May 14 '18 at 05:17
  • We only have to make a call from browser to users phone, Is this possible? – Dev Ramesh May 14 '18 at 05:21
  • Sure, there are tutorials on the Twilio site to achieve this. Check out this one for [making browser calls to phones using PHP and Laravel](https://www.twilio.com/docs/voice/tutorials/browser-calls-php-laravel). Also, take a look at the documentation for using the [Twilio Client JavaScript](https://www.twilio.com/docs/voice/client/javascript). – philnash May 14 '18 at 05:24
  • I have integrate the making browser calls to phones using PHP and Laravel, but when I make a call it say's "Application error occured, Good bye!" and connection declined – Dev Ramesh May 14 '18 at 06:17
  • Ok, so what would help is if you update your question with a bunch more details so that I can help to try to solve this with you. For a start, can you share the code you are using to respond with TwiML when you make the call? – philnash May 14 '18 at 06:25
  • I have updated the question and why there is need of TwiML, we can not directly talk with user? – Dev Ramesh May 14 '18 at 06:45

2 Answers2

0

Twilio developer evangelist here.

The TwiML connects the outgoing call to the other user. When you set up the TwiML Application for outgoing calls you need to set a voice URL. When you make the call using Twilio.Device.connect then Twilio Client will connect to Twilio, Twilio will then make an HTTP request to the voice URL of your TwiML app, passing along the parameters that you send, to find out what to do with the call.

You are passing in a phoneNumber parameter, so that will be passed to your application. You've tagged this question with PHP, so here's an example (using the Twilio PHP library) of what you could do to dial onto the phone number that you are passing.

<?php
require_once './vendor/autoload.php';
use Twilio\Twiml;

$phoneNumber = $_REQUEST['phoneNumber'];

$response = new Twiml();
$dial = $response->dial();
$dial->number($phoneNumber);

echo $response;

Check out the documentation on Twilio Client for more details on how this works.

philnash
  • 70,667
  • 10
  • 60
  • 88
0

Twilio voice call please refer the following documentation step by step QuickStartDemo