/hubspot-engagement

Laravel Hubspot Engagement notification channel

Primary LanguagePHPMIT LicenseMIT

Hubspot Engagement Notifications Channel for Laravel

Latest Version on Packagist Software License Build Status StyleCI Quality Score Code Coverage Total Downloads

This package makes it easy to log notifications to Hubspot Engagement with Laravel 5.5+, 6.x, 7.x and 8.x

Contents

Installation

You can install the package via composer:

composer require laravel-notification-channels/hubspot-engagement

Setting up the HubspotEngagement service

Generate API Key from Hubspot.

Configure your Hubspot API on .env

HUBSPOT_API_KEY=XXXXXXXX

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

php artisan vendor:publish --provider="NotificationChannels\HubspotEngagement\HubspotEngagementServiceProvider"

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

// config/services.php

return [
    'api_key' => env('HUBSPOT_API_KEY'),
    /*
     * Guzzle options
     */
    'CLIENT_OPTIONS' => [
        'HTTP_ERRORS' => true,
    ]
];

By setting http_errors to false, you will not receive any exceptions at all, but pure responses. For possible options, see here.

Usage

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

Supported Engagement types

Currently is only supported Email type of Engagement.

Email type

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() function
  • Send at timestamp
  • from email
  • from name
  • subject
  • html body
  • to email
  • cc emails
  • bcc emails

Example

Notification example

use NotificationChannels\HubspotEngagement\HubspotEngagementChannel;
use Illuminate\Notifications\Notification;

class OrderConfirmation extends Notification
{
    ...
    public function via($notifiable)
    {
        return ['mail', HubspotEngagementChannel::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(){
        return $this->hubspot_contact_id;
    }
    ...
}

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.