Giter VIP home page Giter VIP logo

laravel-hubspot-email-notification-channel's Introduction

Hubspot Email Notifications Channel for Laravel

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
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;
    }
    ...
}

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email [email protected] 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.

laravel-hubspot-email-notification-channel's People

Contributors

sk4t0 avatar trippo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.