Skip to content

Commit

Permalink
add rsvp confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
davidteather committed Oct 2, 2023
1 parent 0ebbf6e commit f7b5d3f
Showing 1 changed file with 75 additions and 52 deletions.
127 changes: 75 additions & 52 deletions lambda/index.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,90 @@
const AWS = require('aws-sdk');
const AWS = require("aws-sdk");
const SES = new AWS.SES();

exports.handler = async (event) => {
const body = JSON.parse(event.body);

var to_email = "";
var first_name = "";
var last_name = "";

// iterate over body.data.fields and get the values for the fields we want
for (var i = 0; i < body.data.fields.length; i++) {
// handle the RSVP confirmation emails
const body = JSON.parse(event.body);
var to_email = "";
var first_name = "";

if (body.data.fields[i].key == "question_7R91WA") {
to_email = body.data.fields[i].value;
}
var is_rsvp = false;
var is_rsvp_yes = false;

if (body.data.fields[i].key == "question_ja95yE") {
first_name = body.data.fields[i].value;
}
// iterate over body.data.fields and get the values for the fields we want
for (var i = 0; i < body.data.fields.length; i++) {
if (
body.data.fields[i].key == "question_7R91WA" ||
body.data.fields[i].key == "question_gDJEBP"
) {
to_email = body.data.fields[i].value;
}

if (body.data.fields[i].key == "question_2Ex1eV") {
last_name = body.data.fields[i].value;
}
if (
body.data.fields[i].key == "question_ja95yE" ||
body.data.fields[i].key == "question_aQARbb"
) {
first_name = body.data.fields[i].value;
}

if (to_email == "" || first_name == "" || last_name == "") {
return {
statusCode: 500,
body: JSON.stringify({ error: "Missing required fields" }),
};
if (body.data.fields[i].key == "question_7RaQlR") {
is_rsvp = true;
is_rsvp_yes =
body.data.fields[i].value[0] == "3b086c77-00f6-4cf9-87d1-346df95b19f1";
}
}

var subject = "";
var body_text = "";
if (is_rsvp) {
subject = "MadHacks RSVP Confirmation"; // is_rsvp_yes
if (is_rsvp_yes) {
body_text = "Hello " + first_name + "," + "\n\nWe're excited to see you at MadHacks Fall 2023! Please join our Discord server for more information https://discord.gg/VgrNq2XgMe .\n\nBest,\nMadHacks Team";
} else {
body_text = "Hello " + first_name + "," + "\n\nWe're sorry to hear that you can't make it to MadHacks Fall 2023. We hope to see you at our next event!\n\nBest,\nMadHacks Team"
}
} else {
// confirmation email
subject = "Confirmation Of Application To MadHacks Fall 2023";
body_text =
"Hello " +
first_name +
",\n\nThank you for applying to MadHacks Fall 2023! We will be reviewing your application and will get back to you soon.\n\nBest,\nMadHacks Team";
}

const subject = "Confirmation Of Application To MadHacks Fall 2023"
const body_text = "Hello " + first_name + ",\n\nThank you for applying to MadHacks Fall 2023! We will be reviewing your application and will get back to you soon.\n\nBest,\nMadHacks Team"
if (to_email == "" || first_name == "") {
return {
statusCode: 500,
body: JSON.stringify({ error: "Missing required fields" }),
};
}

const params = {
Source: process.env.FROM_EMAIL,
Destination: {
ToAddresses: [to_email]
const params = {
Source: process.env.FROM_EMAIL,
Destination: {
ToAddresses: [to_email],
},
Message: {
Subject: {
Data: subject,
},
Body: {
Text: {
Data: body_text,
},
Message: {
Subject: {
Data: subject
},
Body: {
Text: {
Data: body_text
}
}
}
};
},
},
};

try {
await SES.sendEmail(params).promise();
return {
statusCode: 200,
body: JSON.stringify({ message: 'Email sent!' }),
};
} catch (error) {
return {
statusCode: 500,
body: JSON.stringify({ error: error.message }),
};
}
try {
await SES.sendEmail(params).promise();
return {
statusCode: 200,
body: JSON.stringify({ message: "Email sent!" }),
};
} catch (error) {
return {
statusCode: 500,
body: JSON.stringify({ error: error.message }),
};
}
};

0 comments on commit f7b5d3f

Please sign in to comment.