Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

squibby's avatar

How to use Twilio webhooks

How to go about receiving data back from twilio once they have processed and sent an SMS message? Is this possible with this service and laravel?

I am sending email and text message alerts from my application. When sending email messages via Mailgun api I am able to add custom headers and then receive a webhook from Mailgun which I then use to update my email status.

I am using the Twilio laravel package, and would like to add a recipient id/token to the message request and receive that back from twilio once they have processed the SMS, or even better once it has been delivered to recipients phone.

Thanks

0 likes
1 reply
squibby's avatar
squibby
OP
Best Answer
Level 8

This can be done by using twilio webhooks. Ensure a status callback url is passed when making a request to twilio. In my case I send a url which leads to a controller method which then processes the webhook depending on query parameters.

$client->messages->create(
               '123456789',
                array(
                    'messagingServiceSid' => config('sms.sid'),
                    'body' => 'Insert sms text here',
                    'statusCallback' => 'http://www.myapp.com/hooks/sms?token=d43dfg41d3f3573dfg4354'
                )
            );

Please or to participate in this conversation.