From aa6ff2de41e09bf97cd65d12fbdce2c91a1a10db Mon Sep 17 00:00:00 2001 From: Ayushya Amitabh Date: Thu, 20 Aug 2020 12:37:03 -0400 Subject: [PATCH] v1.6.3/release - webhooks ask --- functions/package-lock.json | 7 ++- functions/package.json | 3 +- functions/webhooks/ask.js | 112 +++++++++++++++++++++++++++++++++++- 3 files changed, 117 insertions(+), 5 deletions(-) diff --git a/functions/package-lock.json b/functions/package-lock.json index 2f4e9e8..adedcfb 100644 --- a/functions/package-lock.json +++ b/functions/package-lock.json @@ -1,6 +1,6 @@ { "name": "watch-party-api", - "version": "1.6.2", + "version": "1.6.3", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1894,6 +1894,11 @@ "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.9.1.tgz", "integrity": "sha512-G6RlQt5Sb4GMBzXvhfkeFmbqR6MzhtnT7VTHuLadjkii3rdYHNdw0m8zA4BTxVIh68FicCQ2NSUANpsqkr9jvQ==" }, + "nodemailer": { + "version": "6.4.11", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.4.11.tgz", + "integrity": "sha512-BVZBDi+aJV4O38rxsUh164Dk1NCqgh6Cm0rQSb9SK/DHGll/DrCMnycVDD7msJgZCnmVa8ASo8EZzR7jsgTukQ==" + }, "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", diff --git a/functions/package.json b/functions/package.json index 94f8e11..8551949 100644 --- a/functions/package.json +++ b/functions/package.json @@ -18,7 +18,8 @@ "express": "^4.17.1", "firebase-admin": "^9.0.0", "firebase-functions": "^3.3.0", - "node-fetch": "^2.6.0" + "node-fetch": "^2.6.0", + "nodemailer": "^6.4.11" }, "devDependencies": { "eslint": "^5.12.0", diff --git a/functions/webhooks/ask.js b/functions/webhooks/ask.js index 08521eb..0640a5d 100644 --- a/functions/webhooks/ask.js +++ b/functions/webhooks/ask.js @@ -1,9 +1,115 @@ +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); - console.info(`[RECEIVED]\tWEBHOOKS/ASK\tQ:${question}\tA:${answer}`); - res.status(200).send({ message: "Got answer." }); + 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" ', + to: 'admin+ask@chromewatchparty.com', + subject: `❔ ${question.substring(0, 17)}...`, + text: ` + ❓ : ${question} + 🅰 : ${answer} + `, + html: ` + +
+
WATCH PARTY | ASK
+
+
QUESTION
+ ${question} +
+
+
ANSWER
+ ${answer} +
+
+ `, + }); + mLogger.success('SENT EMAIL TO ADMIN'); + } + }); } catch (e) { - console.info(`[ERROR]\tWEBHOOKS/ASK/Failed To Parse\tBody:${req.body}`); + mLogger.error('FAILED TO PARSE ANSWER', e); } };