Skip to content

Instantly share code, notes, and snippets.

@mager
Created December 28, 2015 23:59
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 mager/01d0210ff456c90a8f69 to your computer and use it in GitHub Desktop.
Save mager/01d0210ff456c90a8f69 to your computer and use it in GitHub Desktop.
Writing a Slackbot in 40 lines of code (Part 3)
app.post('/post', function(req, res){
var parsed_url = url.format({
pathname: 'https://api.genius.com/search',
query: {
access_token: process.env.GENIUS_ACCESS,
q: req.body.text
}
});
request(parsed_url, function (error, response, body) {
if (!error && response.statusCode == 200) {
var data = JSON.parse(body);
var first_url = data.response.hits[0].result.url;
var body = {
response_type: "in_channel",
text: first_url
};
res.send(body);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment