@@ -33,8 +33,14 @@ The notifier component supports the following channels:
3333 services like Slack and Telegram;
3434* :ref: `Email channel <notifier-email-channel >` integrates the :doc: `Symfony Mailer </mailer >`;
3535* Browser channel uses :ref: `flash messages <flash-messages >`.
36- * :ref: `Push channel <notifier-push-channel >` sends notifications to phones and browsers via push notifications.
37- * :ref: `Desktop channel <notifier-desktop-channel >` displays desktop notifications on the same host machine.
36+ * :ref: `Push channel <notifier-push-channel >` sends notifications to phones and
37+ browsers via push notifications.
38+ * :ref: `Desktop channel <notifier-desktop-channel >` displays desktop notifications
39+ on the same host machine.
40+
41+ .. versionadded :: 7.2
42+
43+ The ``Desktop `` channel was introduced in Symfony 7.2.
3844
3945.. _notifier-sms-channel :
4046
@@ -635,28 +641,33 @@ configure the ``texter_transports``:
635641Desktop Channel
636642~~~~~~~~~~~~~~~
637643
638- The desktop channel is used to display desktop notifications on the same host machine using
639- :class: `Symfony\\ Component\\ Notifier\\ Texter ` classes. Currently, Symfony
640- is integrated with the following providers:
644+ The desktop channel is used to display local desktop notifications on the same
645+ host machine using :class: `Symfony\\ Component\\ Notifier\\ Texter ` classes. Currently,
646+ Symfony is integrated with the following providers:
641647
642648=============== ==================================== ==============================================================================
643649Provider Package DSN
644650=============== ==================================== ==============================================================================
645651`JoliNotif `_ ``symfony/joli-notif-notifier `` ``jolinotif://default ``
646652=============== ==================================== ==============================================================================
647653
648- .. versionadded: 7.2
654+ .. versionadded :: 7.2
649655
650656 The JoliNotif bridge was introduced in Symfony 7.2.
651657
652- To enable a texter, add the correct DSN in your ``.env `` file and
653- configure the ``texter_transports ``:
658+ If you are using :ref: `Symfony Flex <symfony-flex >`, installing that package will
659+ also create the necessary environment variable and configuration. Otherwise, you'll
660+ need to add the following manually:
661+
662+ 1) Add the correct DSN in your ``.env `` file:
654663
655664.. code-block :: bash
656665
657666 # .env
658667 JOLINOTIF=jolinotif://default
659668
669+ 2) Update the Notifier configuration to add a new texter transport:
670+
660671.. configuration-block ::
661672
662673 .. code-block :: yaml
@@ -699,9 +710,49 @@ configure the ``texter_transports``:
699710 ;
700711 };
701712
702- .. versionadded :: 7.2
713+ Now you can send notifications to your desktop as follows::
703714
704- The ``Desktop `` channel was introduced in Symfony 7.2.
715+ // src/Notifier/SomeService.php
716+ use Symfony\Component\Notifier\Message\DesktopMessage;
717+ use Symfony\Component\Notifier\TexterInterface;
718+ // ...
719+
720+ class SomeService
721+ {
722+ public function __construct(
723+ private TexterInterface $texter,
724+ ) {
725+ }
726+
727+ public function notifyNewSubscriber(User $user): void
728+ {
729+ $message = new DesktopMessage(
730+ 'New subscription! 🎉',
731+ sprintf('%s is a new subscriber', $user->getFullName())
732+ );
733+
734+ $texter->send($message);
735+ }
736+ }
737+
738+ These notifications can be customized further, and depending on your operating system,
739+ they may support features like custom sounds, icons, and more::
740+
741+ use Symfony\Component\Notifier\Bridge\JoliNotif\JoliNotifOptions;
742+ // ...
743+
744+ $options = (new JoliNotifOptions())
745+ ->setIconPath('/path/to/icons/error.png')
746+ ->setExtraOption('sound', 'sosumi')
747+ ->setExtraOption('url', 'https://example.com');
748+
749+ $message = new DesktopMessage('Production is down', <<<CONTENT
750+ ❌ Server prod-1 down
751+ ❌ Server prod-2 down
752+ ✅ Network is up
753+ CONTENT, $options);
754+
755+ $texter->send($message);
705756
706757Configure to use Failover or Round-Robin Transports
707758~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments