Skip to content

Commit

Permalink
Replace email template
Browse files Browse the repository at this point in the history
  • Loading branch information
kdid committed Oct 9, 2023
1 parent 708f99d commit 0f2f30e
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 100 deletions.
8 changes: 4 additions & 4 deletions lambdas/assets/email.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Meadow AV Download</title>
<title>NUL Meadow AV Download</title>
<meta content='IE=edge' http-equiv='X-UA-Compatible' />
<style>
p {
Expand Down Expand Up @@ -121,13 +121,13 @@ <h1>
Hello,
</h2>
<p>
Your request for AV Download of <a href="{{referer}}work/{{workId}}">{{title}}</a> (accession: {{accession}}) has been
Your request for {{fileType}} download of <b>{{fileSetLabel}}</b> (file set id: {{fileSetId}}) has been
fulfilled. Click below to download your file:
</p>
<p style='text-align: center'>
<a href='{{downloadKey}}'>
<a href='{{downloadLink}}'>
<!-- icon licensed under Creative Commons (Attribution 3.0 Unported): https://www.iconfinder.com/icons/285629/zip_file_icon -->
<img src="https://iiif.dc.library.northwestern.edu/iiif/2/00000000-0000-0000-0000-000000000002/square/100,100/0/default.jpg" alt="{{downloadKey}}" />
<img src="https://iiif.dc.library.northwestern.edu/iiif/2/00000000-0000-0000-0000-000000000002/square/100,100/0/default.jpg" alt="{{downloadLink}}" />
</a>
</p>
<p style='text-align: center; font-style: italic'>
Expand Down
5 changes: 3 additions & 2 deletions lambdas/assets/email.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Hello,
A zipped archive of {{title}} with accession: {{accession}} has been created. Your download will be available for 24 hours.

The zip file can be downloaded from {{downloadKey}}
Your request for {{fileType}} download of {{fileSetLabel}} (file set id: {{fileSetId}}) has been fulfilled. Your download will be available for 24 hours.

The zip file can be downloaded from {{downloadLink}}
2 changes: 1 addition & 1 deletion lambdas/get-download-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports.handler = async (event) => {

console.log("url", url)

return {downloadLink: url, params: {downloadlink: url}
return {downloadLink: url}

};

Expand Down
68 changes: 0 additions & 68 deletions lambdas/send-email.js

This file was deleted.

43 changes: 43 additions & 0 deletions lambdas/send-templated-email.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const { SESClient, SendTemplatedEmailCommand } = require("@aws-sdk/client-ses");

module.exports.handler = async (event) => {
console.log("SEND EMAIL LAMBDA");
console.log(event);

const sesClient = new SESClient();
const templateName = event.template;
const toAddress = event.to;
const fromAddress = event.from;

const params = event.params
const sendTemplatedEmailCommand = createSendTemplatedEmailCommand(
toAddress,
fromAddress,
templateName,
params
);

try {
const result = await sesClient.send(sendTemplatedEmailCommand);
console.log("sendTemplatedEmailCommand", result)
} catch (err) {
console.log("Failed to send template email", err);
return err;
}
return {success: true}
};


const createSendTemplatedEmailCommand = (
toAddress,
fromAddress,
templateName,
params
) => {
return new SendTemplatedEmailCommand({
Destination: { ToAddresses: [toAddress] },
TemplateData: JSON.stringify(params),
Source: `Northwestern University Libraries <${fromAddress}>`,
Template: templateName,
});
};
27 changes: 10 additions & 17 deletions src/handlers/get-file-set-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function processDownload(doc, email) {
const sourceLocation = s3Location(fileSet.streaming_url); // camelCase streaming url?
const destinationBucket = process.env.MEDIA_CONVERT_DESTINATION_BUCKET;
const fileSetId = path.parse(url.pathname).name
const label = fileSet.label
const fileSetLabel = fileSet.label
const workId = fileSet.work_id
const fileType = fileSet.mime_type.split("/")[0]
const destinationKey = `downloads/${fileSetId}.mp4`;
Expand Down Expand Up @@ -91,22 +91,15 @@ function processDownload(doc, email) {
},
sendEmailInput: {
to: email,
downloadLink: "",
template: "work-archiver-template",
sender: process.env.REPOSITORY_EMAIL,
fileSetId,
fileSetLabel: label,
workId,
fileType,
// params: {
// to: email,
// downloadLink: "",
// sender: process.env.REPOSITORY_EMAIL,
// fileSetId,
// fileSetLabel: label,
// workId,
// fileType,
// }
template: "av-download-template",
from: process.env.REPOSITORY_EMAIL,
params: {
downloadLink: "",
fileSetId,
fileSetLabel,
workId,
fileType,
}
},
}),
};
Expand Down
18 changes: 12 additions & 6 deletions state_machines/av_download.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,22 @@
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:getDownloadLinkFunction",
"InputPath": "$.presignedUrlInput",
"ResultPath": "$.downloadLinkOutput",
"Next": "sendEmail"
"Next": "sendTemplatedEmail"
},
"sendEmail": {
"sendTemplatedEmail": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:sendEmailFunction",
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:sendTemplatedEmailFunction",
"Parameters": {
"to.$": "$.sendEmailInput.to",
"downloadLink.$": "$.downloadLinkOutput.downloadLink",
"sender.$": "$.sendEmailInput.sender",
"template.$": "$.sendEmailInput.template"
"from.$": "$.sendEmailInput.from",
"template.$": "$.sendEmailInput.template",
"params": {
"downloadLink.$": "$.downloadLinkOutput.downloadLink",
"fileSetId.$": "$.sendEmailInput.params.fileSetId",
"fileSetLabel.$": "$.sendEmailInput.params.fileSetLabel",
"workId.$": "$.sendEmailInput.params.workId",
"fileType.$": "$.sendEmailInput.params.fileType"
}
},
"End": true
}
Expand Down
4 changes: 2 additions & 2 deletions template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,12 @@ Resources:
CodeUri: ./lambdas
Handler: get-download-link.handler
Description: Creates presigned url
sendEmailFunction:
sendTemplatedEmailFunction:
Type: AWS::Serverless::Function
Properties:
Runtime: nodejs18.x
CodeUri: ./lambdas
Handler: send-email.handler
Handler: send-templated-email.handler
Description: Sends email
dcApi:
Type: AWS::Serverless::HttpApi
Expand Down

0 comments on commit 0f2f30e

Please sign in to comment.