@@ -33,8 +33,14 @@ The notifier component supports the following channels:
33
33
services like Slack and Telegram;
34
34
* :ref: `Email channel <notifier-email-channel >` integrates the :doc: `Symfony Mailer </mailer >`;
35
35
* 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.
38
44
39
45
.. _notifier-sms-channel :
40
46
@@ -635,28 +641,33 @@ configure the ``texter_transports``:
635
641
Desktop Channel
636
642
~~~~~~~~~~~~~~~
637
643
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:
641
647
642
648
=============== ==================================== ==============================================================================
643
649
Provider Package DSN
644
650
=============== ==================================== ==============================================================================
645
651
`JoliNotif `_ ``symfony/joli-notif-notifier `` ``jolinotif://default ``
646
652
=============== ==================================== ==============================================================================
647
653
648
- .. versionadded: 7.2
654
+ .. versionadded :: 7.2
649
655
650
656
The JoliNotif bridge was introduced in Symfony 7.2.
651
657
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:
654
663
655
664
.. code-block :: bash
656
665
657
666
# .env
658
667
JOLINOTIF=jolinotif://default
659
668
669
+ 2) Update the Notifier configuration to add a new texter transport:
670
+
660
671
.. configuration-block ::
661
672
662
673
.. code-block :: yaml
@@ -699,9 +710,49 @@ configure the ``texter_transports``:
699
710
;
700
711
};
701
712
702
- .. versionadded :: 7.2
713
+ Now you can send notifications to your desktop as follows::
703
714
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);
705
756
706
757
Configure to use Failover or Round-Robin Transports
707
758
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments