10000 feature #51577 [Notifier][Novu] Implement overrides (wouter-toppy) · symfony/symfony@a19c534 · GitHub
[go: up one dir, main page]

Skip to content

Commit a19c534

Browse files
feature #51577 [Notifier][Novu] Implement overrides (wouter-toppy)
This PR was merged into the 6.4 branch. Discussion ---------- [Notifier][Novu] Implement overrides | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #51576 | License | MIT Implement [Novu Overrides](https://docs.novu.co/channels/email/#sending-email-overrides) Commits ------- 722cd1a [Notifier][Novu] Implement overrides
2 parents 91a3a4f + 722cd1a commit a19c534

File tree

6 files changed

+56
-2
lines changed

6 files changed

+56
-2
lines changed

src/Symfony/Component/Notifier/Bridge/Novu/NovuOptions.php

+15
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818
*/
1919
class NovuOptions implements MessageOptionsInterface
2020
{
21+
/**
22+
* @param array{
23+
* email?: array{
24+
* from?: string,
25+
* senderName?: string,
26+
* replyTo?: string,
27+
* cc?: string[],
28+
* bcc?: string[]
29+
* }|null
30+
* } $overrides
31+
*
32+
* @see https://docs.novu.co/channels/email/#sending-email-overrides
33+
*/
2134
public function __construct(
2235
private readonly ?string $subscriberId = null,
2336
private readonly ?string $firstName = null,
@@ -26,6 +39,7 @@ public function __construct(
2639
private readonly ?string $phone = null,
2740
private readonly ?string $avatar = null,
2841
private readonly ?string $locale = null,
42+
private readonly array $overrides = [],
2943
private readonly array $options = [],
3044
) {
3145
}
@@ -39,6 +53,7 @@ public function toArray(): array
3953
'phone' => $this->phone,
4054
'avatar' => $this->avatar,
4155
'locale' => $this->locale,
56+
'overrides' => $this->overrides,
4257
]);
4358
}
4459

src/Symfony/Component/Notifier/Bridge/Novu/NovuSubscriberRecipient.php

+19
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818
*/
1919
class NovuSubscriberRecipient implements RecipientInterface
2020
{
21+
/**
22+
* @param array{
23+
* email?: array{
24+
* from?: string,
25+
* senderName?: string,
26+
* replyTo?: string,
27+
* cc?: string[],
28+
* bcc?: string[]
29+
* }|null
30+
* } $overrides
31+
*
32+
* @see https://docs.novu.co/channels/email/#sending-email-overrides
33+
*/
2134
public function __construct(
2235
private readonly string $subscriberId,
2336
private readonly ?string $firstName = null,
@@ -26,6 +39,7 @@ public function __construct(
2639
private readonly ?string $phone = null,
2740
private readonly ?string $avatar = null,
2841
private readonly ?string $locale = null,
42+
private readonly array $overrides = [],
2943
) {
3044
}
3145

@@ -63,4 +77,9 @@ public function getLocale(): ?string
6377
{
6478
return $this->locale;
6579
}
80+
81+
public function getOverrides(): array
82+
{
83+
return $this->overrides;
84+
}
6685
}

src/Symfony/Component/Notifier/Bridge/Novu/NovuTransport.php

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ protected function doSend(MessageInterface $message): SentMessage
6868
'locale' => $options['locale'],
6969
],
7070
'payload' => json_decode($message->getContent()),
71+
'overrides' => $options['overrides'] ?? [],
7172
];
7273

7374
$endpoint = sprintf('https://%s/v1/events/trigger', $this->getEndpoint());

src/Symfony/Component/Notifier/Bridge/Novu/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class NovuNotification extends Notification implements PushNotificationInterface
3131
$recipient->getPhone(),
3232
$recipient->getAvatar(),
3333
$recipient->getLocale(),
34+
$recipient->getOverrides(),
3435
[],
3536
),
3637
);
@@ -60,6 +61,12 @@ $this->notifier->send(
6061
null,
6162
null,
6263
null,
64+
[
65+
'email' => [
66+
'from' => 'no-reply@toppy.nl',
67+
'senderName' => 'No-Reply',
68+
],
69+
],
6370
),
6471
);
6572
```

src/Symfony/Component/Notifier/Bridge/Novu/Tests/NovuOptionsTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ public function testToArray()
2929
null,
3030
null,
3131
null,
32+
[
33+
'email' => [
34+
'from' => 'no-reply@example.com',
35+
'senderName' => 'No-Reply',
36+
],
37+
],
3238
[],
3339
);
3440

@@ -40,6 +46,12 @@ public function testToArray()
4046
'phone' => null,
4147
'avatar' => null,
4248
'locale' => null,
49+
'overrides' => [
50+
'email' => [
51+
'from' => 'no-reply@example.com',
52+
'senderName' => 'No-Reply',
53+
],
54+
],
4355
],
4456
$options->toArray()
4557
);

src/Symfony/Component/Notifier/Bridge/Novu/Tests/NovuTransportTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function toStringProvider(): iterable
3737

3838
public static function supportedMessagesProvider(): iterable
3939
{
40-
yield [new PushMessage('test', '{}', new NovuOptions(123, null, null, 'test@example.com', null, null, null, []))];
40+
yield [new PushMessage('test', '{}', new NovuOptions(123, null, null, 'test@example.com', null, null, null, ['email' => ['from' => 'no-reply@example.com', 'senderName' => 'No-Reply']], []))];
4141
}
4242

4343
public static function unsupportedMessagesProvider(): iterable
@@ -63,6 +63,6 @@ public function testWithErrorResponseThrows()
6363
$this->expectException(TransportException::class);
6464
$this->expectExceptionMessageMatches('/400: "subscriberId under property to is not configured"/');
6565

66-
$transport->send(new PushMessage('test', '{}', new NovuOptions(123, null, null, 'test@example.com', null, null, null, [])));
66+
$transport->send(new PushMessage('test', '{}', new NovuOptions(123, null, null, 'test@example.com', null, null, null, ['email' => ['from' => 'no-reply@example.com', 'senderName' => 'No-Reply']], [])));
6767
}
6868
}

0 commit comments

Comments
 (0)
0