1
votes

I am looking to get the message body and the sending number of a text message every time someone texts my Twilio number. I'd like to have Twilio send either a GET or POST request (akin to a GitHub service hook) to my endpoint every time a new message is received.

I see the Request URL feature in the manage number section, but I don't see any message info being sent through that request when my number receives a text.

Is it possible to get the sender's number and the message body right now from a hook?

1

1 Answers

1
votes

The information you are looking for is in the request to your endpoint.

When Twilio receives a message for one of your Twilio numbers it makes a synchronous HTTP request to the message URL configured for that number (just like a browser posting a form).

If your Twilio SMS webhook is configured with 'HTTP POST' you can get all the values from $_POST something like this:

foreach ($_POST as $param_name => $param_val) {
    // do something with $param_name and $param_val
}

or for the message body and the sending number:

$message_body = $_POST['Body'];
$sending_number = $_POST['From'];

More info in the docs:

https://www.twilio.com/docs/api/twiml/sms/twilio_request