datomatic / laravel-hubspot-email-notification-channel
Laravel 邮件和通知存储到 Hubspot 邮件通道
v1.3.3
2024-07-15 07:09 UTC
Requires
- php: >=7.4
- guzzlehttp/guzzle: ^7.4
- illuminate/notifications: ^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- mockery/mockery: ^1.4
- orchestra/testbench: ^6.13
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4.18
README
此包使您能够轻松地将通知记录到Hubspot Email Engagement V3,版本 Laravel >= 8.x
内容
安装
您可以通过 composer 安装此包
composer require datomatic/laravel-hubspot-email-notification-channel
设置 HubspotEmail 服务
从 Hubspot 生成一个API 密钥或一个私有应用。 重要!从 2022 年 11 月 30 日起,Hubspot 将要求您仅使用私有应用。如果您同时配置了 API 密钥和私有应用,要切换到仅使用私有应用,只需从您的 .env 文件中删除 HUBSPOT_API_KEY
即可。
在 .env 中配置您的 Hubspot API
HUBSPOT_API_KEY=XXXXXXXX # or HUBSPOT_ACCESS_TOKEN=XXXXXXXX HUBSPOT_OWNER_ID=XXX //an Hubspot owner id to save as email creator
要发布配置文件到 config/newsletter.php,请运行
php artisan vendor:publish --provider="Datomatic\LaravelHubspotEmailNotificationChannel\HubspotEmailServiceProvider"
这将发布一个包含以下内容的 hubspot.php 文件到您的配置目录
// config/hubspot.php return [ 'api_key' => env('HUBSPOT_API_KEY'), 'access_token' => env('HUBSPOT_API_KEY'), 'hubspot_owner_id' => env('HUBSPOT_OWNER_ID',null) ];
用法
您现在可以在 Notification 类的 via()
方法中使用该通道。
邮件通知
您的 Notification 类必须具有 toMail 方法。该包接受:MailMessage 行通知、MailMessage 视图通知和 Markdown 邮件通知。
存储在 Hubspot 上的数据
- Hubspot 联系人 ID => 可通知的模型必须具有 getHubspotContactId(\Illuminate\Notifications\Notification $notification) 函数
- 发送时间戳
- 主题
- HTML 正文
示例
通知示例
use Datomatic\LaravelHubspotEmailNotificationChannel\HubspotEmailChannel; use Illuminate\Notifications\Notification; class OrderConfirmation extends Notification { ... public function via($notifiable) { return ['mail', HubspotEmailChannel::class]]; } public function toMail($notifiable) { $message = (new MailMessage) ->subject(__('order.order_confirm', ['code' => $this->order->code])); return $message->view( 'emails.order', [ 'title' => __('order.order_confirm', ['code' => $this->order->code]), 'order' => $this->order ] ); } ... }
模型示例
namespace App\Models; class User extends Authenticatable{ ... public function getHubspotContactId(\Illuminate\Notifications\Notification $notification){ return $this->hubspot_contact_id; } ... }
动态联系人所有者
use Datomatic\LaravelHubspotEmailNotificationChannel\HubspotEmailChannel; use Illuminate\Notifications\Notification; class PersonalMessage extends Notification { ... public function via($notifiable) { return ['mail', HubspotEmailChannel::class]]; } public function toMail($notifiable) { $message = (new MailMessage) ->subject(__('messages.personal_subject')) ->from($this->employee->email, $this->employee->name) ->metadata('hubspot_owner_id', $this->employee->hubspot_owner_id); return $message->view( 'messages.personal', [ 'title' => __('messages.personal_welcome', ['recipient' => $notifiable->name]), 'employee' => $this->employee ] ); } ... }
变更日志
有关最近更改的更多信息,请参阅CHANGELOG。
测试
$ composer test
安全
如果您发现任何安全问题,请通过电子邮件 info@albertoperipolli.com 联系我们,而不是使用问题跟踪器。
贡献
有关详细信息,请参阅CONTRIBUTING。
致谢
许可协议
MIT 许可协议 (MIT)。有关更多信息,请参阅许可文件。