it-tech

Latest News

New in Symfony 7.2: Desktop Notifications

Standard Post with Gallery

The Symfony Notifier component allows you to notify users through channels like SMS messages, chat services, email messages, and push notifications on smartphones. In Symfony 7.2 we're adding a new desktop channel to send notifications to your local desktop.

This new channel uses the JoliNotif project internally, so you must first install it in your application:

$ composer require symfony/joli-notif-notifier

If you're using Symfony Flex, installing this package also creates the necessary environment variable in the .env file and updates the config/packages/notifier.yaml file. Now you're ready to send your first desktop notification.

That's all. This notification will now be sent to the desktop of the machine that it's running the code. So, when running it locally, you will see the following notification appear on your desktop.

These notifications can be customized further, and depending on your operating system, they may support features like custom sounds, icons, and more.

use Symfony\Component\Notifier\Bridge\JoliNotif\JoliNotifOptions;
// ...

$options = (new JoliNotifOptions())
    ->setIconPath('/path/to/icons/error.png')
    ->setExtraOption('sound', 'sosumi')
    ->setExtraOption('url', 'https://example.com');

$message = new DesktopMessage('Production is down', <<<CONTENT
    ❌ Server prod-1 down
    ❌ Server prod-2 down
    ✅ Network is up
    CONTENT, $options);

$texter->send($message);