0

I'm new to Twilio. I'm using Twilio for phone verification of my app. I'm using Laravel 5.5 for the backend & APIs. I've successfully sent the SMS to phone. I'm getting the call from Twilio but it says an application error. It doesn't read what I want to hear.

Below I'm giving every detail of my code.

Used composer require twilio/sdk for Twilio.

This is my Controller.

use Twilio\Rest\Client;
use Twilio\Twiml;

class AppUserController extends Controller{
    private $account_sid;
    private $auth_token;
    private $twilio_number;

    public function __construct(){
        $this->account_sid = Config::get('envvalue.account_sid');
        $this->auth_token = Config::get('envvalue.auth_token');
        $this->twilio_number = Config::get('envvalue.twilio_number');
    }

    public function reVerification(Request $request){
        $client = new Client($this->account_sid, $this->auth_token);
        try {
            $client->account->calls->create(
                $receiverNumber,
                $this->twilio_number,
                array(
                    "url" => "http://demo.bitcanny.com/marine-admin/public/api/twiml/"
                )
            );

            return response()->json([
                'success' => true,
                'statusCode' => '200',
                'message' => 'Otp send again'
            ], 200);
        }
        catch (Exception $e) {
            return $e->getMessage();
        }
    }

    public function twiml(){
        // A message for Twilio's TTS engine to repeat
        $sayMessage = 'Hello.';

        $twiml = new Twiml();
        $twiml->say($sayMessage);

        $response = Response::make($twiml, 200);
        $response->header('Content-Type', 'text/xml');
        return $response;
    }

}
halfer
  • 19,824
  • 17
  • 99
  • 186
sayan0020
  • 36
  • 1
  • 3
  • 9

1 Answers1

0

I found the solution. There's a silly mistake. I didn't use Response in the header of my controller.

use Response;
sayan0020
  • 36
  • 1
  • 3
  • 9
  • I am also working on the same functionality, I am getting URL part of this flow can you please elaborate a little? I am trying in a way that, I am making XML file and uploading it on S3 and then giving URL to twillio but it says same error you have faced earlier? – Muhammad Sipra Sep 26 '18 at 12:35
  • The URL you are giving, it should be the path of the function from where Twilio would read the XML file you are creating. HTTP method should be GET. – sayan0020 Sep 26 '18 at 12:54
  • OK got it, I came to know that twillio will only read the URL with a valid domain, not from localhost, S3 or any other public domain. In my case it is only working for domain i have purchased for my product. – Muhammad Sipra Sep 26 '18 at 14:08
  • Yes, you can send sms from localhost, but for calls you should have a valid domain. – sayan0020 Sep 28 '18 at 05:42