Skip to content

Instantly share code, notes, and snippets.

@mgp
Created October 31, 2014 00:58
Show Gist options
  • Save mgp/365a5bacc6e50a5b96ab to your computer and use it in GitHub Desktop.
Save mgp/365a5bacc6e50a5b96ab to your computer and use it in GitHub Desktop.
Share Bot
# Description:
# Forwards messages to ShareBears
request = require('request')
module.exports = (robot) ->
robot.respond /.*/i, (msg) ->
sender = msg.envelope.user.mention_name
body = msg.match[0].substring(10)
formData = { user_id: sender, text: body }
handler = (response) ->
if response.statusCode == 201
sharedUrl = response.headers['location']
msg.send('This is now shared at ' + sharedUrl)
else
msg.send('Sorry, there was an error sharing this :(')
request.post('http://localhost:9000/posts', {form: formData})
.on('response', handler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment