Skip to content

Commit 06ea390

Browse files
committed
Implement Novu overrides
1 parent 2bac801 commit 06ea390

File tree

6 files changed

+51
-7
lines changed

6 files changed

+51
-7
lines changed

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

Lines changed: 20 additions & 5 deletions
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|null,
25+
* senderName: string|null,
26+
* replyTo: string|null,
27+
* cc: string[]|null,
28+
* bcc: string[]|null
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|null $subscriberId = null,
2336
private readonly string|null $firstName = null,
@@ -26,6 +39,7 @@ public function __construct(
2639
private readonly string|null $phone = null,
2740
private readonly string|null $avatar = null,
2841
private readonly string|null $locale = null,
42+
private readonly array $overrides = [],
2943
private readonly array $options = [],
3044
) {
3145
}
@@ -34,11 +48,12 @@ public function toArray(): array
3448
{
3549
return array_merge($this->options, [
3650
'firstName' => $this->firstName,
37-
'lastName' => $this->lastName,
38-
'email' => $this->email,
39-
'phone' => $this->phone,
40-
'avatar' => $this->avatar,
41-
'locale' => $this->locale,
51+
'lastName' => $this->lastName,
52+
'email' => $this->email,
53+
'phone' => $this->phone,
54+
'avatar' => $this->avatar,
55+
'locale' => $this->locale,
56+
'overrides' => $this->overrides,
4257
]);
4358
}
4459

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

Lines changed: 19 additions & 0 deletions
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|null,
25+
* senderName: string|null,
26+
* replyTo: string|null,
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|null $firstName = null,
@@ -26,6 +39,7 @@ public function __construct(
2639
private readonly string|null $phone = null,
2740
private readonly string|null $avatar = null,
2841
private readonly string|null $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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function testToArray()
3030
null,
3131
null,
3232
[],
33+
[],
3334
);
3435

3536
$this->assertSame(
@@ -40,6 +41,7 @@ public function testToArray()
4041
'phone' => null,
4142
'avatar' => null,
4243
'locale' => null,
44+
'overrides' => [],
4345
],
4446
$options->toArray()
4547
);

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

Lines changed: 2 additions & 2 deletions
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, [], []))];
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, [], [])));
6767
}
6868
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy