Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 61 additions & 10 deletions notifier.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@
services like Slack and Telegram;
* :ref:`Email channel <notifier-email-channel>` integrates the :doc:`Symfony Mailer </mailer>`;
* Browser channel uses :ref:`flash messages <flash-messages>`.
* :ref:`Push channel <notifier-push-channel>` sends notifications to phones and browsers via push notifications.
* :ref:`Desktop channel <notifier-desktop-channel>` displays desktop notifications on the same host machine.
* :ref:`Push channel <notifier-push-channel>` sends notifications to phones and
browsers via push notifications.
* :ref:`Desktop channel <notifier-desktop-channel>` displays desktop notifications
on the same host machine.

.. versionadded:: 7.2

The ``Desktop`` channel was introduced in Symfony 7.2.

.. _notifier-sms-channel:

Expand Down Expand Up @@ -635,28 +641,33 @@
Desktop Channel
~~~~~~~~~~~~~~~

The desktop channel is used to display desktop notifications on the same host machine using
:class:`Symfony\\Component\\Notifier\\Texter` classes. Currently, Symfony
is integrated with the following providers:
The desktop channel is used to display local desktop notifications on the same
host machine using :class:`Symfony\\Component\\Notifier\\Texter` classes. Currently,
Symfony is integrated with the following providers:

=============== ==================================== ==============================================================================
Provider Package DSN
=============== ==================================== ==============================================================================
`JoliNotif`_ ``symfony/joli-notif-notifier`` ``jolinotif://default``
=============== ==================================== ==============================================================================

.. versionadded: 7.2
.. versionadded:: 7.2

The JoliNotif bridge was introduced in Symfony 7.2.

To enable a texter, add the correct DSN in your ``.env`` file and
configure the ``texter_transports``:
If you are using :ref:`Symfony Flex <symfony-flex>`, installing that package will
also create the necessary environment variable and configuration. Otherwise, you'll
need to add the following manually:

1) Add the correct DSN in your ``.env`` file:

.. code-block:: bash

# .env
JOLINOTIF=jolinotif://default

2) Update the Notifier configuration to add a new texter transport:

.. configuration-block::

.. code-block:: yaml
Expand Down Expand Up @@ -699,9 +710,49 @@
;
};

.. versionadded:: 7.2
Now you can send notifications to your desktop as follows::

The ``Desktop`` channel was introduced in Symfony 7.2.
// src/Notifier/SomeService.php
use Symfony\Component\Notifier\Message\DesktopMessage;
use Symfony\Component\Notifier\TexterInterface;
// ...

class SomeService
{
public function __construct(
private TexterInterface $texter,
) {
}

public function notifyNewSubscriber(User $user): void
{
$message = new DesktopMessage(
'New subscription! 🎉',
sprintf('%s is a new subscriber', $user->getFullName())
);

$texter->send($message);
}
}

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;

Check failure on line 741 in notifier.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[Missing class] Class, interface or trait with name "Symfony\Component\Notifier\Bridge\JoliNotif\JoliNotifOptions" does not exist
// ...

$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);

Configure to use Failover or Round-Robin Transports
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
Loading