mvdnbrk/laravel-postmark-webhooks
Composer 安装命令:
composer require mvdnbrk/laravel-postmark-webhooks
包简介
Handle Postmark webhooks in a Laravel application.
README 文档
README
Handle Postmark webhooks in a Laravel application
Postmark can send out several webhooks to your application when an event occurs.
This way Postmark is able to immediately notify you when something new occurs.
This package can help you handle those webhooks.
Installation
You can install the package via composer:
composer require mvdnbrk/laravel-postmark-webhooks
This package will log all incoming webhooks to the database by default.
Run the migrations to create a postmark_webhook_logs table in the database:
php artisan migrate
If you want to disable database logging you can set
POSTMARK_WEBHOOKS_LOG_ENABLED=falsein your.envfile.
Setup webhooks with Postmark
Visit the servers page on your Postmark account.
Choose the server you want to setup webhooks for.
Go to settings > webhooks > add webbook.
This package will register a route where Postmark can post their webhooks to: /api/webhooks/postmark.
Fill in your webhook URL: https://<your-domain.com>/api/webhooks/postmark
Pick the events Postmark should send to you and save the webhook.
You are ready to receive webhook notifications from Postmark!
You may change the
/api/webhooks/postmarkendpoint to anything you like.
You can do this by changing thepathkey in theconfig/postmark-webooks.phpfile.
Protection of your webhook
This package protects your webhook automatically by only allowing requests from the IP range that Postmark uses.
Usage
Postmark can send out several event types by posting a webhook.
You can find the full list of webhooks in the Postmark documentation.
All webhook requests will be logged in the postmark_webhook_logs table.
The table has a payload column where the entire payload of the incoming webhook is saved.
The ID Postmark assigned to the original message will be saved in the message_id column,
the event type will be stored in the record_type column and the email address as well in the email column.
Note that event types will be converted to
snake_case.
For exampleSpamComplaintwill be saved asspam_complaint.
Events
Whenever a webhook call comes in, this package will fire a PostmarkWebhookCalled event.
You may register an event listener in the EventServiceProvider:
/** * The event listener mappings for the application. * * @var array */ protected $listen = [ PostmarkWebhookCalled::class => [ YourListener::class, ], ];
Example of a listener:
<?php namespace App\Listeners; use Mvdnbrk\PostmarkWebhooks\Events\PostmarkWebhookCalled; class YourListener { /** * Handle the event. * * @param \Mvdnbrk\PostmarkWebhooks\Events\PostmarkWebhookCalled $event * @return void */ public function handle(PostmarkWebhookCalled $event) { // Do your work here. // You can access the payload here with: $event->payload. // The email address, message ID and record type are also available: // $event->email // $event->messageId // $event->recordType } }
You may also register an event listener for a specific type of event:
/** * The event listener mappings for the application. * * @var array */ protected $listen = [ 'webhook.postmark: spam_complaint' => [ YourSpamComplaintListener::class, ], ];
Available events: open, bounce, click, delivery, spam_complaint.
Advanced configuration
You may optionally publish the config file with:
php artisan vendor:publish --provider="Mvdnbrk\PostmarkWebhooks\PostmarkWebhooksServiceProvider" --tag="config"
Within the configuration file you may change the table name being used or the Eloquent model being used to save log records to the database.
If you want to use your own model to save the logs to the database you should extend the
Mvdnbrk\PostmarkWebhooks\PostmarkWebhookclass.
You can also exclude one or more event types from being logged to the database.
Place the events you want to exclude under the except key:
'log' => [ ... 'except' => [ 'open', ... ], ],
You can map the events fired by this package to your own event classes:
'events' => [ 'spam_complaint' => App\Events\SpamComplaint, ... ],
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
Inspired by Laravel Stripe Webooks from Spatie.
License
The MIT License (MIT). Please see License File for more information.
mvdnbrk/laravel-postmark-webhooks 适用场景与选型建议
mvdnbrk/laravel-postmark-webhooks 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 44.79k 次下载、GitHub Stars 达 27, 最近一次更新时间为 2018 年 09 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「postmark」 「laravel」 「webhook」 「e-mail」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mvdnbrk/laravel-postmark-webhooks 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mvdnbrk/laravel-postmark-webhooks 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mvdnbrk/laravel-postmark-webhooks 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Library to send email across all platforms using one interface.
Provides an email provider for postmarkapp.com
A minor update of Miguel Perez's no-longer maintained code from https://github.com/miguel250/PostmarkBundle to allow for Symfony 3 compatibility. All credit/kudos/thanks for the work should obviously go to him
Inbox pattern process implementation for your Laravel Applications
Verify, normalize, and track email delivery webhooks from SendGrid, Postmark, Mailgun, Amazon SES, and Resend
Lightweight abstraction around common mail API
统计信息
- 总下载量: 44.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 27
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-09-19