datomatic / laravel-hubspot-email-notification-channel
Laravel Channel to save email and notifications on Hubspot Email
Fund package maintenance!
Datomatic
Installs: 5 207
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 1
Forks: 2
Open Issues: 0
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
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
- html body
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 ] ); } ... }
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.