Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 17d26f9

Browse files
committed
Merge branch '6.3' into 6.4
* 6.3: [Notifier][Webhook] Added documentation for Webhook in combination with the Notifier component Fix indentation
2 parents 9d26845 + 1766878 commit 17d26f9

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``
@@ -98,10 +98,10 @@ Service Package DSN
9898
`SpotHit`_ ``symfony/spot-hit-notifier`` ``spothit://TOKEN@default?from=FROM``
9999
`Telnyx`_ ``symfony/telnyx-notifier`` ``telnyx://API_KEY@default?from=FROM&messaging_profile_id=MESSAGING_PROFILE_ID``
100100
`TurboSms`_ ``symfony/turbo-sms-notifier`` ``turbosms://AUTH_TOKEN@default?from=FROM``
101-
`Twilio`_ ``symfony/twilio-notifier`` ``twilio://SID:TOKEN@default?from=FROM``
101+
`Twilio`_ ``symfony/twilio-notifier`` ``twilio://SID:TOKEN@default?from=FROM`` yes
102102
`Vonage`_ ``symfony/vonage-notifier`` ``vonage://KEY:SECRET@default?from=FROM``
103103
`Yunpian`_ ``symfony/yunpian-notifier`` ``yunpian://APIKEY@default``
104-
================== ===================================== ===========================================================================
104+
================== ===================================== ========================================================================================================================= ===============
105105

106106
.. versionadded:: 6.1
107107

@@ -128,6 +128,12 @@ Service Package DSN
128128
The `Sendinblue`_ integration is deprecated since
129129
Symfony 6.4, use the `Brevo`_ integration instead.
130130

131+
.. tip::
132+
133+
Some third party transports, when using the API, support status callback
134+
via webhooks. See the :doc:`Webhook documentation </webhook>` for more
135+
details.
136+
131137
To enable a texter, add the correct DSN in your ``.env`` file and
132138
configure the ``texter_transports``:
133139

webhook.rst

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

115-
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
116-
use Symfony\Component\RemoteEvent\Consumer\ConsumerInterface;
117-
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;
118-
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;
119-
use Symfony\Component\RemoteEvent\RemoteEvent;
120-
121-
#[AsRemoteEventConsumer('mailer_mailgun')]
122-
final readonly class WebhookListener implements ConsumerInterface
123-
{
124-
public function consume(RemoteEvent $event): void
115+
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
116+
use Symfony\Component\RemoteEvent\Consumer\ConsumerInterface;
117+
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;
118+
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;
119+
use Symfony\Component\RemoteEvent\RemoteEvent;
120+
121+
#[AsRemoteEventConsumer('mailer_mailgun')]
122+
class WebhookListener implements ConsumerInterface
125123
{
126-
if ($event instanceof MailerDeliveryEvent) {
127-
$this->handleMailDelivery($event);
128-
} elseif ($event instanceof MailerEngagementEvent) {
129-
$this->handleMailEngagement($event);
130-
} else {
131-
// This is not an email event
132-
return;
124+
public function consume(RemoteEvent $event): void
125+
{
126+
if ($event instanceof MailerDeliveryEvent) {
127+
$this->handleMailDelivery($event);
128+
} elseif ($event instanceof MailerEngagementEvent) {
129+
$this->handleMailEngagement($event);
130+
} else {
131+
// This is not an email event
132+
return;
133+
}
133134
}
134-
}
135135

136-
private function handleMailDelivery(MailerDeliveryEvent $event): void
137-
{
138-
// Handle the mail delivery event
136+
private function handleMailDelivery(MailerDeliveryEvent $event): void
137+
{
138+
// Handle the mail delivery event
139+
}
140+
141+
private function handleMailEngagement(MailerEngagementEvent $event): void
142+
{
143+
// Handle the mail engagement event
144+
}
139145
}
140146

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

0 commit comments

Comments
 (0)