PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, November 18, 2022

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

 November 18, 2022     twilio, twilio-api, twilio-php     No comments   

Issue

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'], 
   ]);
}

Solution

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');


Answered By - Kapitan Teemo
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing