kitbrennan90/laravel-sendgrid-webhooks 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

kitbrennan90/laravel-sendgrid-webhooks

Composer 安装命令:

composer require kitbrennan90/laravel-sendgrid-webhooks

包简介

Laravel package for receiving and storing event webhooks from Sendgrid

README 文档

README

This package enables your Laravel application to receive event webhooks from Sendgrid, and will automatically store those webhooks in your database. The package also fires Laravel events so you can hook in to the webhooks and take your own actions.

Installation

Getting the package

The best way to install this package is with composer. Run this from your command line:

composer require kitbrennan90/laravel-sendgrid-webhooks ~1.0

Run the migrations

This package will create a table called sendgrid_webhook_events which will be used to store all the Sendgrid webhooks received.

Once you have included the package, this migration will run automatically with your normal migrations, so just call:

php artisan migrate

Copy the config file (optional)

This library works without any local configuration, however you may want to use the config file in order to tweak the logs you receive (eg. to receive logs when you receive duplicate events).

Call the command below to copy the package config files:

php artisan vendor:publish --provider="LaravelSendgridWebhooks\ServiceProvider"

Tell Sendgrid to use your new event webhook URL

Head over to https://app.sendgrid.com/settings/mail_settings and click on the 'Event Notification' section.

Your HTTP Post URL is: https://yourwebsite.com/sendgrid/webhook

Using the library

Querying records

This library uses a standard Laravel Eloquent model, so you can therefore query it as you would any other model.

// Include the class
use \LaravelSendgridWebhooks\Models\SendgridWebhookEvent;

////////////////////

// Get all records:
SendgridWebhookEvent::all();

// Get all by message ID:
$sendgridMessageId = 'abc123';
SendgridWebhookEvent::where('sg_message_id', $sendgridMessageId)->all();

// Get all by event ID:
$sendgridEventId = 'xyz987';
SendgridWebhookEvent::where('sg_event_id', $sendgridEventId)->all();

// Get all by event type
SendgridWebhookEvent::where('event', LaravelSendgridWebhooks\Enums::PROCESSED)->all();
SendgridWebhookEvent::where('event', LaravelSendgridWebhooks\Enums::DEFERRED)->all();
SendgridWebhookEvent::where('event', LaravelSendgridWebhooks\Enums::DELIVERED)->all();
SendgridWebhookEvent::where('event', LaravelSendgridWebhooks\Enums::OPEN)->all();
SendgridWebhookEvent::where('event', LaravelSendgridWebhooks\Enums::CLICK)->all();
SendgridWebhookEvent::where('event', LaravelSendgridWebhooks\Enums::BOUNCE)->all();
SendgridWebhookEvent::where('event', LaravelSendgridWebhooks\Enums::DROPPED)->all();
SendgridWebhookEvent::where('event', LaravelSendgridWebhooks\Enums::SPAMREPORT)->all();
SendgridWebhookEvent::where('event', LaravelSendgridWebhooks\Enums::UNSUBSCRIBE)->all();
SendgridWebhookEvent::where('event', LaravelSendgridWebhooks\Enums::GROUP_UNSUBSCRIBE)->all();
SendgridWebhookEvent::where('event', LaravelSendgridWebhooks\Enums::GROUP_RESUBSCRIBE)->all();

// Count all bounces
SendgridWebhookEvent::where('event', LaravelSendgridWebhooks\Enums::BOUNCE)->count();

Interacting with a record

Accessing data included with all event types:

// Get a record
$event = SendgridWebhookEvent::first();

// Included with all event types
$event->timestamp;
$event->email;
$event->event;
$event->categories;
$event->sg_event_id;
$event->sg_message_id;
$event->payload; // Array of full payload sent by Sendgrid

Some data is only included with specific events. You can find out what these attributes are here: https://sendgrid.com/docs/API_Reference/Event_Webhook/event.html#-Event-objects

We include this data under the payload array within a record. For example:

// Get a record
$event = SendgridWebhookEvent::first();

// Access the reason attribute, included on 'dropped' and 'bounced' events.
$event->payload['reason'];

kitbrennan90/laravel-sendgrid-webhooks 适用场景与选型建议

kitbrennan90/laravel-sendgrid-webhooks 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.03k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2019 年 04 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 kitbrennan90/laravel-sendgrid-webhooks 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kitbrennan90/laravel-sendgrid-webhooks 我们能提供哪些服务?
定制开发 / 二次开发

基于 kitbrennan90/laravel-sendgrid-webhooks 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.03k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 25
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 11
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-04-16