定制 datomatic/laravel-hubspot-email-notification-channel 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

datomatic/laravel-hubspot-email-notification-channel

Composer 安装命令:

composer require datomatic/laravel-hubspot-email-notification-channel

包简介

Laravel Channel to save email and notifications on Hubspot Email

README 文档

README

Latest Version on Packagist Software License Quality Score Total Downloads

This package makes it easy to log notifications to Hubspot Email Engagement V3 with Laravel >= 8.x

Contents

Installation

You can install the package via composer:

composer require datomatic/laravel-hubspot-email-notification-channel

Setting up the HubspotEmail service

Generate an API Key or a Private App from Hubspot. Important! From November 30th 2022 Hubspot will require you to use only private apps. If you have both API Key and Private App configured, to switch using only Private App just remove HUBSPOT_API_KEY from your .env file.

Configure your Hubspot API on .env

HUBSPOT_API_KEY=XXXXXXXX 
# or
HUBSPOT_ACCESS_TOKEN=XXXXXXXX
HUBSPOT_OWNER_ID=XXX //an Hubspot owner id to save as email creator

To publish the config file to config/newsletter.php run:

php artisan vendor:publish --provider="Datomatic\LaravelHubspotEmailNotificationChannel\HubspotEmailServiceProvider"

This will publish a file hubspot.php in your config directory with the following contents:

// config/hubspot.php

return [
    'api_key' => env('HUBSPOT_API_KEY'),
    'access_token' => env('HUBSPOT_API_KEY'),
    'hubspot_owner_id' => env('HUBSPOT_OWNER_ID',null)
];

Usage

You can now use the channel in your via() method inside the Notification class.

Email notification

Your Notification class must have toMail method. The package accepts: MailMessage lines notifications, MailMessage view notifications and Markdown mail notifications.

Data stored on Hubspot:

  • Hubspot Contact Id => The Notifiable Model must have getHubspotContactId(\Illuminate\Notifications\Notification $notification) function
  • Send at timestamp
  • subject
  • mail text (the html of the email or the toHubspotTextMail method of notification)

Example

Notification example

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
            ]
        );
    }

    //Optional text method
    public function toHubspotTextMail($notifiable):string
    {
        return 'text of message to put on hubspot';
    }
    ...
}

Send text version of html email

An example of use of toHubspotTextMail method is to send the text version of the email.

use Soundasleep\Html2Text;
class OrderConfirmation extends Notification
{
    ...

    public function toHubspotTextMail(mixed $notifiable): string
    {
        return Html2Text::convert($this->toMail($notifiable)->render());
    }
}

Model example

namespace App\Models;

class User extends Authenticatable{
    ...
    public function getHubspotContactId(\Illuminate\Notifications\Notification $notification){
        return $this->hubspot_contact_id;
    }
    ...
}

Dynamic Contact Owner

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

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email info@albertoperipolli.com instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

datomatic/laravel-hubspot-email-notification-channel 适用场景与选型建议

datomatic/laravel-hubspot-email-notification-channel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.69k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2022 年 01 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 datomatic/laravel-hubspot-email-notification-channel 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-08