From 84bf5e4001b2a62ecce4578e2d666f110c8446bf Mon Sep 17 00:00:00 2001 From: Arthur de Moulins Date: Wed, 11 Dec 2024 12:23:31 +0100 Subject: [PATCH] WIP --- expose/api/composer.lock | 32 +++++++++---------- .../Handler/DownloadRequestHandler.php | 8 ++--- .../src/Notification/NotifierInterface.php | 6 ++++ .../src/Notification/SymfonyNotifier.php | 16 ++++++++-- .../novu/workflows/expose/download-link.ts | 24 ++++++++++++++ novu/bridge/app/novu/workflows/index.ts | 1 + 6 files changed, 64 insertions(+), 23 deletions(-) create mode 100644 novu/bridge/app/novu/workflows/expose/download-link.ts diff --git a/expose/api/composer.lock b/expose/api/composer.lock index 87a9d5bbe..882e1a233 100644 --- a/expose/api/composer.lock +++ b/expose/api/composer.lock @@ -833,16 +833,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.334.2", + "version": "3.334.3", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "b19afc076bb1cc2617bdef76efd41587596109e7" + "reference": "6576a9fcfc6ae7c76aed3c6fa4c3864060f72d04" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/b19afc076bb1cc2617bdef76efd41587596109e7", - "reference": "b19afc076bb1cc2617bdef76efd41587596109e7", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/6576a9fcfc6ae7c76aed3c6fa4c3864060f72d04", + "reference": "6576a9fcfc6ae7c76aed3c6fa4c3864060f72d04", "shasum": "" }, "require": { @@ -925,9 +925,9 @@ "support": { "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "issues": "https://github.com/aws/aws-sdk-php/issues", - "source": "https://github.com/aws/aws-sdk-php/tree/3.334.2" + "source": "https://github.com/aws/aws-sdk-php/tree/3.334.3" }, - "time": "2024-12-09T19:30:23+00:00" + "time": "2024-12-10T19:41:55+00:00" }, { "name": "brick/math", @@ -8600,8 +8600,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -8766,8 +8766,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -11151,16 +11151,16 @@ }, { "name": "twig/twig", - "version": "v3.16.0", + "version": "v3.17.0", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "475ad2dc97d65d8631393e721e7e44fb544f0561" + "reference": "d3a64b742a5e74c57e3964d766e1032982145872" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/475ad2dc97d65d8631393e721e7e44fb544f0561", - "reference": "475ad2dc97d65d8631393e721e7e44fb544f0561", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/d3a64b742a5e74c57e3964d766e1032982145872", + "reference": "d3a64b742a5e74c57e3964d766e1032982145872", "shasum": "" }, "require": { @@ -11215,7 +11215,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.16.0" + "source": "https://github.com/twigphp/Twig/tree/v3.17.0" }, "funding": [ { @@ -11227,7 +11227,7 @@ "type": "tidelift" } ], - "time": "2024-11-29T08:27:05+00:00" + "time": "2024-12-10T15:19:11+00:00" }, { "name": "webmozart/assert", diff --git a/expose/api/src/Consumer/Handler/DownloadRequestHandler.php b/expose/api/src/Consumer/Handler/DownloadRequestHandler.php index 0d79db576..bed832e13 100644 --- a/expose/api/src/Consumer/Handler/DownloadRequestHandler.php +++ b/expose/api/src/Consumer/Handler/DownloadRequestHandler.php @@ -5,7 +5,7 @@ namespace App\Consumer\Handler; use Alchemy\CoreBundle\Util\DoctrineUtil; -use Alchemy\NotifyBundle\src\NotifierInterface; +use Alchemy\NotifyBundle\Notification\NotifierInterface; use App\Entity\DownloadRequest; use App\Security\Authentication\JWTManager; use Doctrine\ORM\EntityManagerInterface; @@ -44,10 +44,10 @@ public function __invoke(DownloadRequest $message): void $this->notifier->sendEmail( $downloadRequest->getEmail(), - 'expose/download_link', - $downloadRequest->getLocale(), + 'expose-download-link', [ - 'download_url' => $downloadUrl, + 'locale' => $downloadRequest->getLocale(), + 'downloadUrl' => $downloadUrl, ] ); } diff --git a/lib/php/notify-bundle/src/Notification/NotifierInterface.php b/lib/php/notify-bundle/src/Notification/NotifierInterface.php index 895ac1611..21f853279 100644 --- a/lib/php/notify-bundle/src/Notification/NotifierInterface.php +++ b/lib/php/notify-bundle/src/Notification/NotifierInterface.php @@ -11,4 +11,10 @@ public function notifyUser( string $notificationId, array $parameters = [], ): void; + + public function sendEmail( + string $email, + string $notificationId, + array $parameters = [], + ): void; } diff --git a/lib/php/notify-bundle/src/Notification/SymfonyNotifier.php b/lib/php/notify-bundle/src/Notification/SymfonyNotifier.php index 1a7917e96..2d9bb82ca 100644 --- a/lib/php/notify-bundle/src/Notification/SymfonyNotifier.php +++ b/lib/php/notify-bundle/src/Notification/SymfonyNotifier.php @@ -20,17 +20,27 @@ public function __construct( } public function notifyUser(string $userId, string $notificationId, array $parameters = []): void + { + $recipient = new NovuSubscriberRecipient($userId); + $this->sendNotification($recipient, $notificationId, $parameters, 'user'); + } + + public function sendEmail(string $email, string $notificationId, array $parameters = []): void + { + $recipient = new NovuSubscriberRecipient($email, email: $email); + $this->sendNotification($recipient, $notificationId, $parameters); + } + + private function sendNotification(NovuSubscriberRecipient $recipient, string $notificationId, array $parameters): void { $content = json_encode($parameters, JSON_THROW_ON_ERROR); - $this->logger->debug(sprintf('Send notification to user "%s" with template "%s"', $userId, $notificationId), [ + $this->logger->debug(sprintf('Send notification "%s" with template "%s"', $recipient->getSubscriberId(), $notificationId), [ 'content' => $content, ]); $notification = new NovuNotification($notificationId); $notification->content($content); - $recipient = new NovuSubscriberRecipient($userId); - $this->notifier->send($notification, $recipient); } } diff --git a/novu/bridge/app/novu/workflows/expose/download-link.ts b/novu/bridge/app/novu/workflows/expose/download-link.ts new file mode 100644 index 000000000..32b093aa9 --- /dev/null +++ b/novu/bridge/app/novu/workflows/expose/download-link.ts @@ -0,0 +1,24 @@ +import {workflow} from "@novu/framework"; +import {z} from "zod"; + +export const exposeDownloadLink = workflow( + "expose-download-link", + async ({step, payload}) => { + await step.email("Email", async () => { + return { + subject: `Your download link is ready!`, + body: `You can download your file from the following link: ${payload.downloadUrl}`, + }; + }); + }, + { + payloadSchema: z.object({ + downloadUrl: z + .string() + .describe("The URL link to download the file"), + locale: z + .string() + .describe("The user's locale"), + }) + }, +); diff --git a/novu/bridge/app/novu/workflows/index.ts b/novu/bridge/app/novu/workflows/index.ts index 7d8f49c21..f5f5b1874 100644 --- a/novu/bridge/app/novu/workflows/index.ts +++ b/novu/bridge/app/novu/workflows/index.ts @@ -1,2 +1,3 @@ export * from "./welcome-onboarding-email"; export * from "./uploader/commit-acknowledged"; +export * from "./expose/download-link";