Kapitan Teemo
Kapitan Teemo

Reputation: 2164

How to handle my sms statuscallback in twilio using php laravel?

I saw an example in twilio: https://www.twilio.com/docs/sms/tutorials/how-to-confirm-delivery-php

<?php
$sid = $_REQUEST['MessageSid'];
$status = $_REQUEST['MessageStatus'];

openlog("myMessageLog", LOG_PID | LOG_PERROR, LOG_USER);
syslog(LOG_INFO, "SID: $sid, Status: $status");
closelog();

I don't know what the code above exactly do, but what I want is to save the data to my local database.

The code in my post method(my statuscallback):

public function smsStatusCallback(Request $request){

   $sms = SmsChannel::create([
      'number' => $request['MessageSid'],
      'body' => $request['MessageStatus'], 
   ]);
}

Upvotes: 1

Views: 901

Answers (1)

Kapitan Teemo
Kapitan Teemo

Reputation: 2164

I've found a solution already. I saw the possible solutions in twilio debugger: "Double check that your TwiML URL does not ...". So I tried making it as a twiml

public function smsStatusCallback(Request $request){

  $response = new Twiml();

  $sms = SmsChannel::create([
    'sid' => $request['MessageSid'],
    'status' => $request['MessageStatus'], 
  ]);

   return response($response)
     ->header('Content-Type', 'text/xml');

}

I've added my route to api.php since the URL should be accessible by twilio.

Route::post('sms-status-callback','CommunicationController@smsStatusCallback');

Upvotes: 1

Related Questions