Send to Slack

This commit is contained in:
Matthew Stanciu 2020-05-12 19:08:32 -04:00
parent c774239032
commit e79f3f326d

View file

@ -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' })
}