定制 settermjd/twilio-eventstreams-webhook-validator-slim 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

settermjd/twilio-eventstreams-webhook-validator-slim

最新稳定版本:0.0.2

Composer 安装命令:

composer require settermjd/twilio-eventstreams-webhook-validator-slim

包简介

Slim middleware for validating Twilio Event Streams Webhooks

README 文档

README

testing workflow

This is a small piece of middleware for the Slim Framework (v4) that validates a Twilio Event Streams Webhook.

How Does It Work?

After adding the middleware to one or more of your application's routes, when a route is dispatched, the webhook is validated. If the webhook is valid, the next request is called. Otherwise, an HTTP 400 Bad Request is returned, along with a problem details response, formatted as JSON or XML based on the request's Accept header.

Why Use It?

You could code up the functionality yourself; and check out the tutorial on the Twilio blog if you'd like to. But, this middleware avoids the need to do so. Instead, just initialise it and add it to the relevant routes, then focus on the remaining functionality of your application.

Prerequisites

To use this middleware, you're going to need a Twilio account (either free or paid). If you are new to Twilio, create a free account.

⚡️ Quick Start

To use the middleware in your Slim (v4) application, first add the project as a dependency by running the following command:

composer require settermjd/twilio-eventstreams-webhook-validator-slim

Then, in the appropriate part of your application, initialise a new EventStreams\EventStreamsWebhookValidatorMiddleware object, which requires three parameters:

  • The application's public URI. During development you could use ngrok to expose the application to the public internet and generate the public URI.
  • The webhook URI's path
  • A \Twilio\Security\RequestValidator object, initialised with your Twilio Auth Token

Note: The first two parameters to EventStreamsWebhookValidatorMiddleware ensure that the app's correct public URI is used as part of the webhook validation process.

Then, follow the Slim Middleware documentation to add the middleware to the respective route. Below, you can find examples of adding it as Route Middleware:

<?php

declare(strict_types=1);

require_once('vendor/autoload.php');

use EventStreams\EventStreamsWebhookValidatorMiddleware;
use Twilio\Security\RequestValidator;

$app = new \Slim\App();

$eventStreamsWebhookValidatorMiddleware = new EventStreamsWebhookValidatorMiddleware(
    "<<THE APP'S PUBLIC URL>>",
    "<<THE WEBHOOK PATH>>",
     new RequestValidator("<<YOUR TWILIO AUTH TOKEN>>")
);

$app->get('/', function ($request, $response, $args) {
    $response->getBody()->write(' Hello ');
    return $response;
})->add($eventStreamsWebhookValidatorMiddleware);

$app->run();

Then, replace <<THE APP'S PUBLIC URL>>" with the public URI of the application, <<THE WEBHOOK PATH>> with he path of the route that handles the webhook request, and <<YOUR TWILIO AUTH TOKEN>> with your Twilio Auth Token.

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

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2024-09-10