This package makes it easy to send notifications using Notify with Symfony 4
You can install the package via composer:
$ composer require notify-eu/notify-bundle
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)
- Load the 'notifyService' inside your services/controllers
- Create a NotifyMessage object with the required parameters
- 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!');
}
}
}
Make sure to add a recipient to the message:
$message->addRecipient('John Doe','John.Doe@notify.eu')
notificationType('')
: Accepts a string value.addRecipient($array)
: Accepts an array of arrays of 'name'/'recipient' keystransport('')
: Accepts a string value. if not set, it will fallback to NOTIFY_TRANSPORT in .env filelanguage('')
: Accepts a string value.params($array)
: Accepts an array of key/value parametersCc($array)
: Accepts an array of arrays of 'name'/'recipient' keysBcc($array)
: Accepts an array of arrays of 'name'/'recipient' keys
Please see CHANGELOG for more information what has changed recently.
$ composer test
If you discover any security related issues, please email info@notify.eu instead of using the issue tracker.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.