brentnd/laravel-sparkposthooks

此包已被废弃,不再维护。未建议替代包。

一个简单的SparkPost webhook控制器,用于处理事件。兼容Laravel 5+和Lumen 5+。

v1.0.0 2018-05-25 00:25 UTC

This package is auto-updated.

Last update: 2021-07-08 19:14:53 UTC


README

Latest Version Software License Total Downloads

一个简单的SparkPost webhook控制器,用于帮助处理电子邮件事件。可用于在您的应用程序内通过电子邮件无法联系用户时通知用户。兼容Laravel 5+和Lumen 5+。

安装

composer require brentnd/laravel-sparkposthooks

基本用法

  1. 创建一个控制器,如下所示扩展SparkPostWebhookController。然后您可以处理任何SparkPost webhook事件。
use Brentnd\Api\Webhooks\SparkPostWebhookController;

class MySparkPostController extends SparkPostWebhookController {

    /**
     * Handle a bounced email
     *
     * @param $payload
     */
    public function handleMessageEventBounce($payload)
    {
        $email = $payload['rcpt_to'];
    }

    /**
     * Handle a rejected email
     *
     * @param $payload
     */
    public function handleMessageEventPolicyRejection($payload)
    {
        $email = $payload['rcpt_to'];
    }

    /**
     * Handle an email open
     *
     * @param $payload
     */
    public function handleTrackEventOpen($payload)
    {
        $transmissionId = $payload['transmission_id'];
    }
}
  1. 创建处理webhook的路由。在您的routes.php文件中添加以下内容。
post('sparkpost-webhook', ['as' => 'sparkpost.webhook', 'uses' => 'MySparkPostController@handleWebhook']);
  1. 排除您的路由从CSRF保护,以免失败。

  2. 确保您已在SparkPost中将webhook指向您的路由。您可以在以下位置进行操作:https://app.sparkpost.com/webhooks

Webhook事件

Webhook事件类型:

常见事件及其处理程序。对于其他事件,只需遵循相同的模式。

事件类型 事件 方法
Ping - handlePing()
消息事件 Bounce handleMessageEventBounce()
消息事件 Delivery handleMessageEventDelivery()
消息事件 Injection handleMessageEventInjection()
消息事件 策略拒绝 handleMessageEventPolicyRejection()
消息事件 延迟 handleMessageEventDelay()
参与事件 点击 handleTrackEventClick()
参与事件 打开 handleTrackEventOpen()
参与事件 初始打开 handleTrackEventInitialOpen()
退订事件 列表退订 handleUnsubscribeEventListUnsubscribe()
退订事件 链接退订 handleUnsubscribeEventLinkUnsubscribe()

贡献者

基于eventhomes/laravel-mandrillhooks