settermjd/mezzio-twilio-webhook-validator

This package provides middleware for validating Twilio webhooks.

0.1.1 2025-09-19 04:57 UTC

This package is auto-updated.

Last update: 2025-09-21 21:27:49 UTC


README

PHP QA Workflow

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:

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:

The Account Info panel in the Twilio Console's main dashboard, where the Account SID and Twilio phone number have been redacted

  • 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 and TWILIO_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