Skip to content

Instantly share code, notes, and snippets.

@avoidwork
Last active August 21, 2017 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avoidwork/5c4c89de305601d57b7c88efc2704e51 to your computer and use it in GitHub Desktop.
Save avoidwork/5c4c89de305601d57b7c88efc2704e51 to your computer and use it in GitHub Desktop.
'/slack': (req, res) => {
if (req.query.code !== void 0) {
let form = new FormData();
form.append('code', req.query.code);
form.append('client_id', config.slack.client_id);
form.append('client_secret', config.slack.client_secret);
fetch('https://slack.com/api/oauth.access', {method: 'POST', body: form, headers: form.getHeaders()}).then(res => res.json()).then(data => {
if (data.ok) {
stores.slack.set(data.team_id, data).then(() => res.redirect('/?added=slack'));
} else {
throw new Error(data.error);
}
}).catch(err => {
log(String.raw`type=error, source=slackButton, message="${(err.message || err.stack || err)}", timestamp=${new Date().toISOString()}`);
res.redirect('/?error=slack');
})
} else {
res.redirect('/');
}
}
@avoidwork
Copy link
Author

node.js code to handle a slack button callback; using tenso, but the API is almost completely compatible with express.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment