-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsales.ts
24 lines (23 loc) · 1.02 KB
/
sales.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { AvailableSQSFunctions } from "common/types/sqsMessage.js";
import { currentEnvironmentConfig, SQSHandlerFunction } from "./index.js";
import { SESClient } from "@aws-sdk/client-ses";
import QRCode from "qrcode";
import { generateSalesEmail } from "api/functions/ses.js";
import { genericConfig } from "common/config.js";
export const sendSaleEmailhandler: SQSHandlerFunction<
AvailableSQSFunctions.SendSaleEmail
> = async (payload, _metadata, logger) => {
const { qrCodeContent } = payload;
const senderEmail = `sales@${currentEnvironmentConfig["EmailDomain"]}`;
logger.info("Constructing QR Code...");
const qrCode = await QRCode.toBuffer(qrCodeContent, {
errorCorrectionLevel: "H",
});
logger.info("Constructing email...");
const emailCommand = generateSalesEmail(payload, senderEmail, qrCode);
logger.info("Constructing email...");
const sesClient = new SESClient({ region: genericConfig.AwsRegion });
const response = await sesClient.send(emailCommand);
logger.info("Sent!");
return response;
};