diff --git a/src/Symfony/Component/Notifier/Bridge/Novu/NovuOptions.php b/src/Symfony/Component/Notifier/Bridge/Novu/NovuOptions.php index 728c03e5d8bc8..5d8ce57a34f44 100644 --- a/src/Symfony/Component/Notifier/Bridge/Novu/NovuOptions.php +++ b/src/Symfony/Component/Notifier/Bridge/Novu/NovuOptions.php @@ -18,6 +18,19 @@ */ class NovuOptions implements MessageOptionsInterface { + /** + * @param array{ + * email?: array{ + * from?: string, + * senderName?: string, + * replyTo?: string, + * cc?: string[], + * bcc?: string[] + * }|null + * } $overrides + * + * @see https://docs.novu.co/channels/email/#sending-email-overrides + */ public function __construct( private readonly ?string $subscriberId = null, private readonly ?string $firstName = null, @@ -26,6 +39,7 @@ public function __construct( private readonly ?string $phone = null, private readonly ?string $avatar = null, private readonly ?string $locale = null, + private readonly array $overrides = [], private readonly array $options = [], ) { } @@ -39,6 +53,7 @@ public function toArray(): array 'phone' => $this->phone, 'avatar' => $this->avatar, 'locale' => $this->locale, + 'overrides' => $this->overrides, ]); } diff --git a/src/Symfony/Component/Notifier/Bridge/Novu/NovuSubscriberRecipient.php b/src/Symfony/Component/Notifier/Bridge/Novu/NovuSubscriberRecipient.php index d1358145e2dda..ade1710a30884 100644 --- a/src/Symfony/Component/Notifier/Bridge/Novu/NovuSubscriberRecipient.php +++ b/src/Symfony/Component/Notifier/Bridge/Novu/NovuSubscriberRecipient.php @@ -18,6 +18,19 @@ */ class NovuSubscriberRecipient implements RecipientInterface { + /** + * @param array{ + * email?: array{ + * from?: string, + * senderName?: string, + * replyTo?: string, + * cc?: string[], + * bcc?: string[] + * }|null + * } $overrides + * + * @see https://docs.novu.co/channels/email/#sending-email-overrides + */ public function __construct( private readonly string $subscriberId, private readonly ?string $firstName = null, @@ -26,6 +39,7 @@ public function __construct( private readonly ?string $phone = null, private readonly ?string $avatar = null, private readonly ?string $locale = null, + private readonly array $overrides = [], ) { } @@ -63,4 +77,9 @@ public function getLocale(): ?string { return $this->locale; } + + public function getOverrides(): array + { + return $this->overrides; + } } diff --git a/src/Symfony/Component/Notifier/Bridge/Novu/NovuTransport.php b/src/Symfony/Component/Notifier/Bridge/Novu/NovuTransport.php index dc6b7a46e9ad8..c2debb1a36642 100644 --- a/src/Symfony/Component/Notifier/Bridge/Novu/NovuTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/Novu/NovuTransport.php @@ -68,6 +68,7 @@ protected function doSend(MessageInterface $message): SentMessage 'locale' => $options['locale'], ], 'payload' => json_decode($message->getContent()), + 'overrides' => $options['overrides'] ?? [], ]; $endpoint = sprintf('https://%s/v1/events/trigger', $this->getEndpoint()); diff --git a/src/Symfony/Component/Notifier/Bridge/Novu/README.md b/src/Symfony/Component/Notifier/Bridge/Novu/README.md index 9dd92568e1176..5888f0aba996c 100644 --- a/src/Symfony/Component/Notifier/Bridge/Novu/README.md +++ b/src/Symfony/Component/Notifier/Bridge/Novu/README.md @@ -31,6 +31,7 @@ class NovuNotification extends Notification implements PushNotificationInterface $recipient->getPhone(), $recipient->getAvatar(), $recipient->getLocale(), + $recipient->getOverrides(), [], ), ); @@ -60,6 +61,12 @@ $this->notifier->send( null, null, null, + [ + 'email' => [ + 'from' => 'no-reply@toppy.nl', + 'senderName' => 'No-Reply', + ], + ], ), ); ``` diff --git a/src/Symfony/Component/Notifier/Bridge/Novu/Tests/NovuOptionsTest.php b/src/Symfony/Component/Notifier/Bridge/Novu/Tests/NovuOptionsTest.php index 6d1125bf18bb0..8ad8dc349bff0 100644 --- a/src/Symfony/Component/Notifier/Bridge/Novu/Tests/NovuOptionsTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Novu/Tests/NovuOptionsTest.php @@ -29,6 +29,12 @@ public function testToArray() null, null, null, + [ + 'email' => [ + 'from' => 'no-reply@example.com', + 'senderName' => 'No-Reply', + ], + ], [], ); @@ -40,6 +46,12 @@ public function testToArray() 'phone' => null, 'avatar' => null, 'locale' => null, + 'overrides' => [ + 'email' => [ + 'from' => 'no-reply@example.com', + 'senderName' => 'No-Reply', + ], + ], ], $options->toArray() ); diff --git a/src/Symfony/Component/Notifier/Bridge/Novu/Tests/NovuTransportTest.php b/src/Symfony/Component/Notifier/Bridge/Novu/Tests/NovuTransportTest.php index b94183e4f464c..a386ea62d70e6 100644 --- a/src/Symfony/Component/Notifier/Bridge/Novu/Tests/NovuTransportTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Novu/Tests/NovuTransportTest.php @@ -37,7 +37,7 @@ public static function toStringProvider(): iterable public static function supportedMessagesProvider(): iterable { - yield [new PushMessage('test', '{}', new NovuOptions(123, null, null, 'test@example.com', null, null, null, []))]; + yield [new PushMessage('test', '{}', new NovuOptions(123, null, null, 'test@example.com', null, null, null, ['email' => ['from' => 'no-reply@example.com', 'senderName' => 'No-Reply']], []))]; } public static function unsupportedMessagesProvider(): iterable @@ -63,6 +63,6 @@ public function testWithErrorResponseThrows() $this->expectException(TransportException::class); $this->expectExceptionMessageMatches('/400: "subscriberId under property to is not configured"/'); - $transport->send(new PushMessage('test', '{}', new NovuOptions(123, null, null, 'test@example.com', null, null, null, []))); + $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']], []))); } }