skip to Main Content

I have this code:

require dirname(__FILE__)."/twilio/services/Twilio.php"; 
$client = new Services_Twilio($option['twilioAccountSid'], $option['twilioAuthToken']); 

$client->account->sms_messages->create($option['twilioFrom'], 
    $to, 
    'Will you attend?',
    array('StatusCallback'=>'http://domain.com/callback.php'));

callback.php:

file_put_contents('/twilio.log', print_r(array($_REQUEST), true) . PHP_EOL );

The scenario is the following. I send the message “Will you attend?” $to +155555555. When they reply back, I want to insert that answer into a database.

I thought that callback.php will be called when they reply with a message, and I’ll have the variable $_REQUEST[‘body’] with their answer, along with other variables, but that’s not the case. In twilio.log I have only a confirmation that I sent the message.

How to I grab the response message into a php file for latter use with a database?

2

Answers


  1. Chosen as BEST ANSWER

    https://www.twilio.com/user/account/phone-numbers/ Select the number you use. Look next to Messaging for Request URL . There you have to put your callback and it will work.


  2. No, its working the way its supposed to. The callback doesn’t have anything to do with the user responding to the SMS, its Twilio’s response to processing your outgoing message.

    One solution for you might be to use cookies if you need to essential track a conversation.

    https://www.twilio.com/docs/quickstart/php/sms/tracking-conversations

    On the other hand, if the only communication you expect to get back is either a yes or no, having the calling number and the reply maybe enough for you, even without using cookies.

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