Files
watchparty/functions/webhooks/ask.js
T
ayushya 54ad629adb v1.6.7/release
- fix hbo space button
- minor reband color
2020-09-04 19:58:46 -04:00

122 lines
2.4 KiB
JavaScript

const nodemailer = require('nodemailer');
const Logger = require('../Logger');
const mLogger = new Logger('webhooks', 'ask');
module.exports = async (req, res) => {
mLogger.start();
try {
const { question, answer } = JSON.parse(req.body);
mLogger.log('PROGRESS', 'GOT QUESTION ANSWER', { question, answer });
res.status(200).send({ message: 'Got answer.' });
const transporter = nodemailer.createTransport({
host: 'smtp.zoho.com',
port: 465,
secure: true,
auth: {
user: 'admin@chromewatchparty.com',
pass: 'Rpk1kLLDUvMh',
},
});
transporter.verify(async (err, suc) => {
if (err) {
mLogger.error('FAILED TO SETUP EMAIL TRANSPORT', err);
} else {
mLogger.log('PROGRESS', 'SET UP EMAIL TRANSPORT', suc);
await transporter.sendMail({
from: '"⚙ ASK WEBHOOK" <admin@chromewatchparty.com>',
to: 'admin+ask@chromewatchparty.com',
subject: `❔ ${question.substring(0, 17)}...`,
text: `
❓ : ${question}
🅰 : ${answer}
==============
PARTY INFO:
${req.body}
`,
html: `
<style>
* {
font-family: sans-serif;
margin: 0;
padding: 0;
}
html,
body {
height: 100%;
width: 100%;
}
#container {
width: calc(100% - 140px);
background: black;
background-color: black;
padding: 35px 70px;
}
#answer {
background: #beff94;
background-color: #beff94;
padding: 30px;
letter-spacing: 1.3px;
}
#container > h5 {
font-size: 18px;
content: 'WATCH PARTY | ASK';
color: #beff94;
display: block;
margin-bottom: 30px;
font-weight: bold;
letter-spacing: 3px;
}
#question {
background: white;
background-color: white;
padding: 30px;
letter-spacing: 1.3px;
}
#question h5 {
font-size: 18px;
content: 'QUESTION';
font-weight: bolder;
letter-spacing: 2px;
display: block;
margin-bottom: 10px;
}
#answer h5 {
font-size: 18px;
content: 'ANSWER';
font-weight: bolder;
letter-spacing: 2px;
display: block;
margin-bottom: 10px;
}
</style>
<div id="container">
<h5>WATCH PARTY | ASK</h5>
<div id="question">
<h5>QUESTION</h5>
${question}
</div>
<div id="answer">
<h5>ANSWER</h5>
${answer}
</div>
<p>
${req.body}
</p>
</div>
`,
});
mLogger.success('SENT EMAIL TO ADMIN');
}
});
} catch (e) {
mLogger.error('FAILED TO PARSE ANSWER', e);
}
};