Skip to content

Instantly share code, notes, and snippets.

@Lordnibbler
Created August 6, 2015 21:43
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 Lordnibbler/2abb750d5006220cde6d to your computer and use it in GitHub Desktop.
Save Lordnibbler/2abb750d5006220cde6d to your computer and use it in GitHub Desktop.
Hubot Giphy Coffeescript
# Commands:
# giphy <term> - Returns a randomly selected gif from a search of the giphy api for <term>
giphy =
api_key: process.env.HUBOT_GIPHY_API_KEY
api_url: 'http://api.giphy.com/v1'
search: (msg, q, callback) ->
endpoint = '/gifs/search'
url = "#{giphy.api_url}#{endpoint}"
msg.http(url)
.query
api_key: giphy.api_key
q: q
.get() (err, res, body) ->
res = JSON.parse(body)
data = res?.data || []
if data.length
img_obj = msg.random data
msg.send(img_obj.images.original.url)
else
msg.send "No results found for #{q}"
module.exports = (robot) ->
robot.respond /giphy (.*)/i, (msg) ->
giphy.search msg, msg.match[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment