Created
December 28, 2015 23:59
-
-
Save mager/01d0210ff456c90a8f69 to your computer and use it in GitHub Desktop.
Writing a Slackbot in 40 lines of code (Part 3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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