@@ -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,30 +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
- Sendgrid ``mailer.webhook.request_parser.sendgrid ``
86
- ============== ==========================================
87
-
88
- Set up the webhook in the third-party mailer. For Mailgun, you can do this
89
- in the control panel. As URL, make sure to use the ``/webhook/mailer_mailgun ``
90
- 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.
91
88
92
- Mailgun will provide a secret for the webhook. Add this secret to your ``.env ``
93
- 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 ``.
94
93
95
- .. 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).
96
97
97
- 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).
98
101
99
- 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::
100
106
101
107
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
102
108
use Symfony\Component\RemoteEvent\Consumer\ConsumerInterface;
@@ -145,8 +151,8 @@ Twilio ``notifier.webhook.request_parser.twilio``
145
151
Vonage ``notifier.webhook.request_parser.vonage ``
146
152
============ ==========================================
147
153
148
- For SMS transports, an additional `` SmsEvent `` is available in the RemoteEvent
149
- consumer ::
154
+ For SMS webhooks, react to the
155
+ :class: ` Symfony \\ Component \\ RemoteEvent \\ Event \\ Sms \\ SmsEvent ` event ::
150
156
151
157
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
152
158
use Symfony\Component\RemoteEvent\Consumer\ConsumerInterface;
@@ -161,13 +167,13 @@ consumer::
161
167
if ($event instanceof SmsEvent) {
162
168
$this->handleSmsEvent($event);
163
169
} else {
164
- // This is not an sms event
170
+ // This is not an SMS event
165
171
return;
166
172
}
167
173
}
168
174
169
175
private function handleSmsEvent(SmsEvent $event): void
170
176
{
171
- // Handle the sms event
177
+ // Handle the SMS event
172
178
}
173
179
}
0 commit comments