Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Dec 11, 2024
1 parent 00e054e commit 84bf5e4
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 23 deletions.
32 changes: 16 additions & 16 deletions expose/api/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions expose/api/src/Consumer/Handler/DownloadRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
]
);
}
Expand Down
6 changes: 6 additions & 0 deletions lib/php/notify-bundle/src/Notification/NotifierInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ public function notifyUser(
string $notificationId,
array $parameters = [],
): void;

public function sendEmail(
string $email,
string $notificationId,
array $parameters = [],
): void;
}
16 changes: 13 additions & 3 deletions lib/php/notify-bundle/src/Notification/SymfonyNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
24 changes: 24 additions & 0 deletions novu/bridge/app/novu/workflows/expose/download-link.ts
Original file line number Diff line number Diff line change
@@ -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"),
})
},
);
1 change: 1 addition & 0 deletions novu/bridge/app/novu/workflows/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./welcome-onboarding-email";
export * from "./uploader/commit-acknowledged";
export * from "./expose/download-link";

0 comments on commit 84bf5e4

Please sign in to comment.