Skip to content

Commit 7962c39

Browse files
committed
Merge branch '6.3' into 6.4
* 6.3: Tweak docs for Webhooks
2 parents ab0b41e + 71b45d2 commit 7962c39

File tree

1 file changed

+38
-48
lines changed

1 file changed

+38
-48
lines changed

webhook.rst

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,26 @@ Installation
1919
Usage in Combination with the Mailer Component
2020
----------------------------------------------
2121

22-
When using a third-party mailer, you can use the Webhook component to receive
23-
webhook calls from the third-party mailer.
22+
When using a third-party mailer provider, you can use the Webhook component to
23+
receive webhook calls from this provider.
2424

25-
In this example Mailgun is used with ``'mailer_mailgun'`` as the webhook type.
26-
Any type name can be used as long as it is unique. Make sure to use it in the
27-
routing configuration, the webhook URL and the RemoteEvent consumer.
25+
Currently, the following third-party mailer providers support webhooks:
2826

29-
Install the third-party mailer as described in the documentation of the
30-
:ref:`Mailer component <mailer_3rd_party_transport>`.
27+
=============== ==========================================
28+
Mailer service Parser service name
29+
=============== ==========================================
30+
Mailgun ``mailer.webhook.request_parser.mailgun``
31+
Postmark ``mailer.webhook.request_parser.postmark``
32+
=============== ==========================================
3133

32-
The Webhook component routing needs to be defined:
34+
.. note::
35+
36+
Install the third-party mailer provider you want to use as described in the
37+
documentation of the :ref:`Mailer component <mailer_3rd_party_transport>`.
38+
Mailgun is used as the provider in this document as an example.
39+
40+
To connect the provider to your application, you need to configure the Webhook
41+
component routing:
3342

3443
.. configuration-block::
3544

@@ -77,38 +86,27 @@ The Webhook component routing needs to be defined:
7786
;
7887
};
7988
80-
Currently, the following third-party services support webhooks:
81-
82-
============== ==========================================
83-
Mailer Service Parser service name
84-
============== ==========================================
85-
Brevo ``mailer.webhook.request_parser.brevo``
86-
Mailgun ``mailer.webhook.request_parser.mailgun``
87-
Mailjet ``mailer.webhook.request_parser.mailjet``
88-
Postmark ``mailer.webhook.request_parser.postmark``
89-
Sendgrid ``mailer.webhook.request_parser.sendgrid``
90-
============== ==========================================
91-
92-
.. versionadded:: 6.3
93-
94-
The support for Mailgun and Postmark was introduced in Symfony 6.3.
95-
96-
.. versionadded:: 6.4
89+
In this example, we are using ``mailer_mailgun`` as the webhook routing name.
90+
The routing name must be unique as this is what connects the provider with your
91+
webhook consumer code.
9792

98-
The support for Brevo, Mailjet and Sendgrid was introduced in Symfony 6.4.
93+
The webhook routing name is part of the URL you need to configure at the
94+
third-party mailer provider. The URL is the concatenation of your domain name
95+
and the routing name you chose in the configuration (like
96+
``https://example.com/webhook/mailer_mailgun``.
9997

100-
Set up the webhook in the third-party mailer. For Mailgun, you can do this
101-
in the control panel. As URL, make sure to use the ``/webhook/mailer_mailgun``
102-
path behind the domain you're using.
98+
For Mailgun, you will get a secret for the webhook. Store this secret as
99+
MAILER_MAILGUN_SECRET (in the :doc:`secrets management system
100+
</configuration/secrets>` or in a ``.env`` file).
103101

104-
Mailgun will provide a secret for the webhook. Add this secret to your ``.env``
105-
file:
102+
When done, add a :class:`Symfony\\Component\\RemoteEvent\\RemoteEvent` consumer
103+
to react to incoming webhooks (the webhook routing name is what connects your
104+
class to the provider).
106105

107-
.. code-block:: env
108-
109-
MAILER_MAILGUN_SECRET=your_secret
110-
111-
With this done, you can now add a RemoteEvent consumer to react to the webhooks::
106+
For mailer webhooks, react to the
107+
:class:`Symfony\\Component\\RemoteEvent\\Event\\Mailer\\MailerDeliveryEvent` or
108+
:class:`Symfony\\Component\\RemoteEvent\\Event\\Mailer\\MailerEngagementEvent`
109+
events::
112110

113111
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
114112
use Symfony\Component\RemoteEvent\Consumer\ConsumerInterface;
@@ -157,16 +155,8 @@ Twilio ``notifier.webhook.request_parser.twilio``
157155
Vonage ``notifier.webhook.request_parser.vonage``
158156
============ ==========================================
159157

160-
.. versionadded:: 6.3
161-
162-
The support for Twilio was introduced in Symfony 6.3.
163-
164-
.. versionadded:: 6.4
165-
166-
The support for Vonage was introduced in Symfony 6.4.
167-
168-
For SMS transports, an additional ``SmsEvent`` is available in the RemoteEvent
169-
consumer::
158+
For SMS webhooks, react to the
159+
:class:`Symfony\\Component\\RemoteEvent\\Event\\Sms\\SmsEvent` event::
170160

171161
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
172162
use Symfony\Component\RemoteEvent\Consumer\ConsumerInterface;
@@ -181,13 +171,13 @@ consumer::
181171
if ($event instanceof SmsEvent) {
182172
$this->handleSmsEvent($event);
183173
} else {
184-
// This is not an sms event
174+
// This is not an SMS event
185175
return;
186176
}
187177
}
188178

189179
private function handleSmsEvent(SmsEvent $event): void
190180
{
191-
// Handle the sms event
181+
// Handle the SMS event
192182
}
193183
}

0 commit comments

Comments
 (0)