From e79f3f326d877fddba5e4b109eac8303d3a8b28c Mon Sep 17 00:00:00 2001 From: Matthew Stanciu Date: Tue, 12 May 2020 19:08:32 -0400 Subject: [PATCH] Send to Slack --- pages/api/join.js | 61 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/pages/api/join.js b/pages/api/join.js index 119f1569..a5cea2ff 100644 --- a/pages/api/join.js +++ b/pages/api/join.js @@ -1,4 +1,4 @@ -const AirtablePlus = require('airtable-plus') +import AirtablePlus from 'airtable-plus' import fetch from 'isomorphic-unfetch' const joinTable = new AirtablePlus({ @@ -22,13 +22,60 @@ export default async (req, res) => { Student: data.teen, Reason: data.reason }) - fetch('https://hackclub-slacker.glitch.me/newmember', { - method: 'POST', - body: JSON.stringify(data), - headers: { - "Content-Type": "application/json" + if (data.teen) { + let postData = { + channel: 'G0147KPNHU0', //G0132DNFE7J + blocks: [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "Someone just requested to join the Slack." + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": `*Full name:* ${data.name}\n*Email:* ${data.email}\n*Student:* ${data.teen ? 'true' : 'false'}\n*Reason:* ${data.reason}` + } + }, + { + "type": "actions", + "elements": [ + { + "type": "button", + "text": { + "type": "plain_text", + "emoji": true, + "text": "Send Invitation" + }, + "style": "primary", + "action_id": "invite_member" + }, + { + "type": "button", + "text": { + "type": "plain_text", + "emoji": true, + "text": "Deny" + }, + "style": "danger", + "action_id": "deny" + } + ] + } + ] } - }).then(r => r.json()) + fetch('https://slack.com/api/chat.postMessage', { + method: 'post', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${process.env.SLACK_BOT_TOKEN}` + }, + body: JSON.stringify(postData) + }).catch(err => console.log(err)) + } } res.json({ status: 'success' }) }