@@ -15,17 +15,26 @@ Installation
15
15
Usage in Combination with the Mailer Component
16
16
----------------------------------------------
17
17
18
- When using a third-party mailer, you can use the Webhook component to receive
19
- webhook calls from the third-party mailer .
18
+ When using a third-party mailer provider , you can use the Webhook component to
19
+ receive webhook calls from this provider .
20
20
21
- In this example Mailgun is used with ``'mailer_mailgun' `` as the webhook type.
22
- Any type name can be used as long as it is unique. Make sure to use it in the
23
- routing configuration, the webhook URL and the RemoteEvent consumer.
21
+ Currently, the following third-party mailer providers support webhooks:
24
22
25
- Install the third-party mailer as described in the documentation of the
26
- :ref: `Mailer component <mailer_3rd_party_transport >`.
23
+ =============== ==========================================
24
+ Mailer service Parser service name
25
+ =============== ==========================================
26
+ Mailgun ``mailer.webhook.request_parser.mailgun ``
27
+ Postmark ``mailer.webhook.request_parser.postmark ``
28
+ =============== ==========================================
27
29
28
- The Webhook component routing needs to be defined:
30
+ .. note ::
31
+
32
+ Install the third-party mailer provider you want to use as described in the
33
+ documentation of the :ref: `Mailer component <mailer_3rd_party_transport >`.
34
+ Mailgun is used as the provider in this document as an example.
35
+
36
+ To connect the provider to your application, you need to configure the Webhook
37
+ component routing:
29
38
30
39
.. configuration-block ::
31
40
@@ -73,35 +82,27 @@ The Webhook component routing needs to be defined:
73
82
;
74
83
};
75
84
76
- Currently, the following third-party services support webhooks:
77
-
78
- ============== ==========================================
79
- Mailer Service Parser service name
80
- ============== ==========================================
81
- Brevo ``mailer.webhook.request_parser.brevo ``
82
- Mailgun ``mailer.webhook.request_parser.mailgun ``
83
- Mailjet ``mailer.webhook.request_parser.mailjet ``
84
- Postmark ``mailer.webhook.request_parser.postmark ``
85
- Resend ``mailer.webhook.request_parser.resend ``
86
- Sendgrid ``mailer.webhook.request_parser.sendgrid ``
87
- ============== ==========================================
88
-
89
- .. versionadded :: 7.1
90
-
91
- The Resend webhook was introduced in Symfony 7.1.
92
-
93
- Set up the webhook in the third-party mailer. For Mailgun, you can do this
94
- in the control panel. As URL, make sure to use the ``/webhook/mailer_mailgun ``
95
- path behind the domain you're using.
85
+ In this example, we are using ``mailer_mailgun `` as the webhook routing name.
86
+ The routing name must be unique as this is what connects the provider with your
87
+ webhook consumer code.
96
88
97
- Mailgun will provide a secret for the webhook. Add this secret to your ``.env ``
98
- file:
89
+ The webhook routing name is part of the URL you need to configure at the
90
+ third-party mailer provider. The URL is the concatenation of your domain name
91
+ and the routing name you chose in the configuration (like
92
+ ``https://example.com/webhook/mailer_mailgun ``.
99
93
100
- .. code-block :: env
94
+ For Mailgun, you will get a secret for the webhook. Store this secret as
95
+ MAILER_MAILGUN_SECRET (in the :doc: `secrets management system
96
+ </configuration/secrets>` or in a ``.env `` file).
101
97
102
- MAILER_MAILGUN_SECRET=your_secret
98
+ When done, add a :class: `Symfony\\ Component\\ RemoteEvent\\ RemoteEvent ` consumer
99
+ to react to incoming webhooks (the webhook routing name is what connects your
100
+ class to the provider).
103
101
104
- With this done, you can now add a RemoteEvent consumer to react to the webhooks::
102
+ For mailer webhooks, react to the
103
+ :class: `Symfony\\ Component\\ RemoteEvent\\ Event\\ Mailer\\ MailerDeliveryEvent ` or
104
+ :class: `Symfony\\ Component\\ RemoteEvent\\ Event\\ Mailer\\ MailerEngagementEvent `
105
+ events::
105
106
106
107
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
107
108
use Symfony\Component\RemoteEvent\Consumer\ConsumerInterface;
@@ -150,8 +151,8 @@ Twilio ``notifier.webhook.request_parser.twilio``
150
151
Vonage ``notifier.webhook.request_parser.vonage ``
151
152
============ ==========================================
152
153
153
- For SMS transports, an additional `` SmsEvent `` is available in the RemoteEvent
154
- consumer ::
154
+ For SMS webhooks, react to the
155
+ :class: ` Symfony \\ Component \\ RemoteEvent \\ Event \\ Sms \\ SmsEvent ` event ::
155
156
156
157
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
157
158
use Symfony\Component\RemoteEvent\Consumer\ConsumerInterface;
@@ -166,13 +167,13 @@ consumer::
166
167
if ($event instanceof SmsEvent) {
167
168
$this->handleSmsEvent($event);
168
169
} else {
169
- // This is not an sms event
170
+ // This is not an SMS event
170
171
return;
171
172
}
172
173
}
173
174
174
175
private function handleSmsEvent(SmsEvent $event): void
175
176
{
176
- // Handle the sms event
177
+ // Handle the SMS event
177
178
}
178
179
}
0 commit comments