skip to Main Content

I want to immediately terminate a call as soon as the call is initialized an the user gets one ring

this are my routes

Route::any('missedCall','RegistrationController@missedCall');
Route::any('callForMissedCall',function(){
    $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?   ><Response/>');
    $xml->addChild('Dial timeout="0"');
    $header['Content-Type'] = 'application/xml';
    return Response::make($xml->asXML(), '200', $header);
});

and the function that I am calling with the first route

    public function missedCall(Request $request)
    {
        $data = $request->all();
        if (isset($data['id'])) {
            Response::json(array("status"=>'failure',"msg"=>'Missing    argument'));
        }
        $regDetails = RegistrationDetails::find($data['id']);

        if (!$regDetails)
            return Response::json(array("status"=>"failure","msg"=>"No     data is present"));
        $phone_no = $regDetails->phone_no;
        $country = $regDetails->country;
        if (!$country)
            return    Response::json(array("status"=>"failure","msg"=>"Country missing"));
        $countryData = Country::where('name',"LIKE",$country)->first();

        $phnCode = $countryData->phonecode;
        $phone = "+".$phnCode.$phone_no;
        $twilio = Twilio::call($phone,     $_ENV['app_url']."/callForMissedCall");
     }

The above code only terminates after the user picks the call. Any solution around this.. Thanks in advance

2

Answers


  1. Chosen as BEST ANSWER

    Following this link from twillio https://www.twilio.com/docs/api/twiml/dial
    I was able to implement the calling.. It is not quite possible to terminate the call but one can follow my code to see how i was able to achieve this

        public function missedCall($id)
    {
        if (isset($id)) {
            Response::json(array("status"=>'failure',"msg"=>'Missing argument'));
        }
        $regDetails = RegistrationDetails::find($id);
    
        if (!$regDetails)
            return Response::json(array("status"=>"failure","msg"=>"No data is present"));
        $phone_no = $regDetails->phone_no;
        $country = $regDetails->country;
        if (!$country)
            return Response::json(array("status"=>"failure","msg"=>"Country missing"));
        $countryData = Country::where('name',"LIKE",$country)->first();
    
        $phnCode = $countryData->phonecode;
        $phone = "+".$phnCode.$phone_no;
        $twilio = Twilio::call($phone, $_ENV['app_url']."/callForMissedCall");
    }
    

    on the xml part of it

       Route::any('callForMissedCall',function(){
    $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><Response/>');
    $xml->addChild('Dial');
    $header['Content-Type'] = 'application/xml';
    return Response::make($xml->asXML(), '200', $header);
    

    });


  2. Twilio evangelist here.

    We just introduced a new feature called Call Progress Events which gives you more granular notifications as a call progresses. I’m not sure we can let you know that a call made exactly one ring, but I know we can tell you that it is “ringing” vs “answered”.

    If you detect “ringing” you could subsequently terminate the call.

    hope that helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search