notify-eu/notify-bundle

Notify bundle for Symfony

v1.0 2020-02-12 15:26 UTC

This package is auto-updated.

Last update: 2024-06-13 18:10:36 UTC


README

Latest Version on Packagist Software License Build Status StyleCI Total Downloads

This package makes it easy to send notifications using Notify with Symfony 4

Contents

Installation

You can install the package via composer:

$ composer require notify-eu/notify-bundle

Setting up your Notify account

Add your Notify credentials to your .env:

// .env
...
NOTIFY_CLIENT_ID=
NOTIFY_SECRET=
NOTIFY_TRANSPORT=
NOTIFY_URL=
],
...

NOTIFY_URL is not mandatory. Can be used when you want to overwrite the endpoint Notify is calling. (f.e. different url for Staging/production)

Usage

  1. Load the 'notifyService' inside your services/controllers
  2. Create a NotifyMessage object with the required parameters
  3. Send the message
<?php

namespace App\Controller;

use NotifyEu\NotifyBundle\Entity\NotifyMessage;
use NotifyEu\NotifyBundle\Service\NotifyService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class IndexController extends AbstractController
{
    protected $notifyService;

    public function __construct(NotifyService $notifyService)
    {
        $this->notifyService = $notifyService;
    }

    /**
     * @Route("/notify", name="app_notify")
     * @return Response
     */
    public function index()
    {
        $message = (new NotifyMessage())
            ->setNotificationType('resetPassword')
            ->addRecipient('John Doe','John.Doe@notify.eu')
            ->setLanguage('nl')
            ->setParams(['username' => 'John Doe']);

        $response = $this->notifyService->send($message);
        if ($response['success'] == true) {
            return new Response('Notification send!');
        }
    }
}

NotifyMessage

Make sure to add a recipient to the message:

    $message->addRecipient('John Doe','John.Doe@notify.eu')

All available methods

  • notificationType(''): Accepts a string value.
  • addRecipient($array): Accepts an array of arrays of 'name'/'recipient' keys
  • transport(''): Accepts a string value. if not set, it will fallback to NOTIFY_TRANSPORT in .env file
  • language(''): Accepts a string value.
  • params($array): Accepts an array of key/value parameters
  • Cc($array): Accepts an array of arrays of 'name'/'recipient' keys
  • Bcc($array): Accepts an array of arrays of 'name'/'recipient' keys

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@notify.eu 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.