Twillio reply to message

巧了我就是萌 提交于 2019-12-24 10:41:09

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/23703958/twillio-reply-to-message

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!