digitalrisks / hubspot-notification-channel
为 Laravel 优化的 Hubspot 通知渠道。
v2.0
2022-09-13 07:57 UTC
Requires
- php: ^7.1.3|^8.0
- hubspot/hubspot-php: ^3.1
- illuminate/notifications: 5.7.*|5.8.*|^6.0|^7.0|^8.0
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ^9.5.7
README
此包简化了使用 Laravel 发送 Hubspot(单次发送电子邮件)通知的过程。
安装
您可以通过 composer 安装此包
composer require digitalrisks/hubspot-notification-channel
添加服务提供者(仅在 Laravel 5.4 或更低版本中需要)
// config/app.php 'providers' => [ ... DigitalRisks\Notifications\ServiceProvider::class, ],
设置您的 Hubspot 账户
将您的 Hubspot 密钥添加到 config/services.php
// config/services.php ... 'hubspot' => [ 'app_access_token' => env('HUBSPOT_APP_ACCESS_TOKEN', null), 'template_id' => env('TEMPLATE_NAME_ID', null) ], ...
使用方法
现在您可以在通知中的 via()
方法中使用此通道
<?php namespace App\Notifications; use DigitalRisks\Notifications\Messages\HubspotMessage; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; class SomethingHappened extends Notification { use Queueable; /** * Create a new notification instance. * * @return void */ public function __construct() { // } /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return ['hubspot']; } /** * Get the hubspot representation of the notification. * * @param mixed $notifiable * @return \DigitalRisks\Notifications\Messages\HubspotMessage */ public function toMail($notifiable) { return (new HubspotMessage) ->templateId(config('services.hubspot.template_id')) ->contactProperties([]) ->customProperties([]); } }
设置收件人字段。
<?php namespace App; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use Notifiable; /** * Route notifications for the Hubspot channel. * * @param \Illuminate\Notifications\Notification $notification * @return string */ public function routeNotificationForHubspot($notification) { return $this->email; } }
变更日志
有关最近更改的更多信息,请参阅变更日志。
测试
$ composer test
安全性
如果您发现任何与安全性相关的问题,请通过电子邮件 kani.robinson@digitalrisks.co.uk 反馈,而不是使用问题跟踪器。
鸣谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅许可证文件。