settermjd / mezzio-twilio-webhook-validator
This package provides middleware for validating Twilio webhooks.
Fund package maintenance!
Community Bridge
Requires
- php: ~8.4
- psr/http-server-middleware: ^1.0
- twilio/sdk: ^8.8
- vlucas/phpdotenv: ^5.6
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.87
- laminas/laminas-coding-standard: ^3.1
- laminas/laminas-component-installer: ^3.5
- laminas/laminas-diactoros: ^3.6
- mikey179/vfsstream: ^1.6
- phpstan/phpdoc-parser: ^2.3
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpunit/phpunit: ^12.3
README
Mezzio Twilio Webhook Validator
This package provides PSR-15-compliant middleware for validating Twilio webhooks in Mezzio applications.
Requirements
To use the application, you'll need the following:
- A Twilio account (free or paid). Create an account if you don't already have one.
- PHP 8.4
- Composer installed globally
Usage
The package is designed to be used as part of Mezzio-based applications, and goes to a lot of effort to make doing so as simple as possible.
Install the package
To install the package, use Composer by running the following command:
composer require settermjd/mezzio-twilio-webhook-validator
During installation, the project's ConfigProvider will be loaded into your Mezzio application's config/config.php, loading all of the required services into the application's DI container.
Set the required environment variables
The package requires two environment variables to be set: TWILIO_ACCOUNT_SID
and TWILIO_AUTH_TOKEN
.
To do that:
- Log in to the Twilio Console in your browser of choice
- Copy the Account SID and Auth Token from the Account Info panel in the Console's main dashboard
- Copy .env.example as .env
- In .env paste the two values as the values for
TWILIO_ACCOUNT_SID
andTWILIO_AUTH_TOKEN
, respectively
How to Use the Middleware
To use the middleware, you can pipe it so that it's used for every route.
To do that, in config/pipeline.php, add the following before DispatchMiddleware
is piped.
use Settermjd\Mezzio\Twilio\WebhookValidator\Middleware\WebhookValidatorMiddleware; // ... $app->pipe(WebhookValidatorMiddleware::class);
Alternatively, you can add it just for individual routes.
To do that, configure the route's middleware as an array, with WebhookValidatorMiddleware
listed before the route's handler.
use Settermjd\Mezzio\Twilio\WebhookValidator\Middleware\WebhookValidatorMiddleware; // ... $app->get( '/contact', [ WebhookValidatorMiddleware::class, App\Handler\ContactHandler::class, ], 'contact' );
Contributing
If you want to contribute to the project, whether you have found issues with it or just want to improve it, here's how:
- Issues: ask questions and submit your feature requests, bug reports, etc
- Pull requests: send your improvements
Did You Find the Project Useful?
If the project was useful, and you want to say thank you and/or support its active development, here's how:
Add a GitHub Star to the project Write an interesting article about the project wherever you blog