Skip to content

Commit 421ba26

Browse files
committed
[Notifier][Webhook] Added documentation for Webhook in combination with the Notifier component
1 parent 0b58658 commit 421ba26

File tree

2 files changed

+80
-29
lines changed

2 files changed

+80
-29
lines changed

notifier.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ to send SMS messages to mobile phones. This feature requires subscribing to
5555
a third-party service that sends SMS messages. Symfony provides integration
5656
with a couple popular SMS services:
5757

58-
================== ===================================== ===========================================================================
59-
Service Package DSN
60-
================== ===================================== ===========================================================================
58+
================== ===================================== ========================================================================================================================= ===============
59+
Service Package DSN Webhook support
60+
================== ===================================== ========================================================================================================================= ===============
6161
`46elks`_ ``symfony/forty-six-elks-notifier`` ``forty-six-elks://API_USERNAME:API_PASSWORD@default?from=FROM``
6262
`AllMySms`_ ``symfony/all-my-sms-notifier`` ``allmysms://LOGIN:APIKEY@default?from=FROM``
6363
`AmazonSns`_ ``symfony/amazon-sns-notifier`` ``sns://ACCESS_KEY:SECRET_KEY@default?region=REGION``
@@ -95,10 +95,10 @@ Service Package DSN
9595
`SpotHit`_ ``symfony/spot-hit-notifier`` ``spothit://TOKEN@default?from=FROM``
9696
`Telnyx`_ ``symfony/telnyx-notifier`` ``telnyx://API_KEY@default?from=FROM&messaging_profile_id=MESSAGING_PROFILE_ID``
9797
`TurboSms`_ ``symfony/turbo-sms-notifier`` ``turbosms://AUTH_TOKEN@default?from=FROM``
98-
`Twilio`_ ``symfony/twilio-notifier`` ``twilio://SID:TOKEN@default?from=FROM``
98+
`Twilio`_ ``symfony/twilio-notifier`` ``twilio://SID:TOKEN@default?from=FROM`` yes
9999
`Vonage`_ ``symfony/vonage-notifier`` ``vonage://KEY:SECRET@default?from=FROM``
100100
`Yunpian`_ ``symfony/yunpian-notifier`` ``yunpian://APIKEY@default``
101-
================== ===================================== ===========================================================================
101+
================== ===================================== ========================================================================================================================= ===============
102102

103103
.. versionadded:: 6.1
104104

@@ -116,6 +116,12 @@ Service Package DSN
116116
were introduced in Symfony 6.3.
117117
The ``from`` option in ``Smsapi`` DSN is optional since Symfony 6.3.
118118

119+
.. tip::
120+
121+
Some third party transports, when using the API, support status callback
122+
via webhooks. See the :doc:`Webhook documentation </webhook>` for more
123+
details.
124+
119125
To enable a texter, add the correct DSN in your ``.env`` file and
120126
configure the ``texter_transports``:
121127

webhook.rst

Lines changed: 69 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -99,34 +99,79 @@ file:
9999
100100
With this done, you can now add a RemoteEvent consumer to react to the webhooks::
101101

102-
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
103-
use Symfony\Component\RemoteEvent\Consumer\ConsumerInterface;
104-
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;
105-
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;
106-
use Symfony\Component\RemoteEvent\RemoteEvent;
107-
108-
#[AsRemoteEventConsumer('mailer_mailgun')]
109-
final readonly class WebhookListener implements ConsumerInterface
110-
{
111-
public function consume(RemoteEvent $event): void
102+
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
103+
use Symfony\Component\RemoteEvent\Consumer\ConsumerInterface;
104+
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;
105+
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;
106+
use Symfony\Component\RemoteEvent\RemoteEvent;
107+
108+
#[AsRemoteEventConsumer('mailer_mailgun')]
109+
class WebhookListener implements ConsumerInterface
112110
{
113-
if ($event instanceof MailerDeliveryEvent) {
114-
$this->handleMailDelivery($event);
115-
} elseif ($event instanceof MailerEngagementEvent) {
116-
$this->handleMailEngagement($event);
117-
} else {
118-
// This is not an email event
119-
return;
111+
public function consume(RemoteEvent $event): void
112+
{
113+
if ($event instanceof MailerDeliveryEvent) {
114+
$this->handleMailDelivery($event);
115+
} elseif ($event instanceof MailerEngagementEvent) {
116+
$this->handleMailEngagement($event);
117+
} else {
118+
// This is not an email event
119+
return;
120+
}
120121
}
121-
}
122122

123-
private function handleMailDelivery(MailerDeliveryEvent $event): void
124-
{
125-
// Handle the mail delivery event
123+
private function handleMailDelivery(MailerDeliveryEvent $event): void
124+
{
125+
// Handle the mail delivery event
126+
}
127+
128+
private function handleMailEngagement(MailerEngagementEvent $event): void
129+
{
130+
// Handle the mail engagement event
131+
}
126132
}
127133

128-
private function handleMailEngagement(MailerEngagementEvent $event): void
134+
Usage in combination with the Notifier component
135+
------------------------------------------------
136+
137+
The usage of the Webhook component when using a third-party transport in
138+
the Notifier is very similar to the usage with the Mailer.
139+
140+
Currently, the following third-party sms transports support webhooks:
141+
142+
============ ==========================================
143+
SMS service Parser service name
144+
============ ==========================================
145+
Twilio ``notifier.webhook.request_parser.twilio``
146+
============ ==========================================
147+
148+
.. versionadded:: 6.3
149+
150+
The support for Twilio was introduced in Symfony 6.3.
151+
152+
For SMS transports, an additional ``SmsEvent`` is available in the RemoteEvent
153+
consumer::
154+
155+
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
156+
use Symfony\Component\RemoteEvent\Consumer\ConsumerInterface;
157+
use Symfony\Component\RemoteEvent\Event\Sms\SmsEvent;
158+
use Symfony\Component\RemoteEvent\RemoteEvent;
159+
160+
#[AsRemoteEventConsumer('notifier_twilio')]
161+
class WebhookListener implements ConsumerInterface
129162
{
130-
// Handle the mail engagement event
163+
public function consume(RemoteEvent $event): void
164+
{
165+
if ($event instanceof SmsEvent) {
166+
$this->handleSmsEvent($event);
167+
} else {
168+
// This is not an sms event
169+
return;
170+
}
171+
}
172+
173+
private function handleSmsEvent(SmsEvent $event): void
174+
{
175+
// Handle the sms event
176+
}
131177
}
132-
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy