Skip to content

Instantly share code, notes, and snippets.

@manaten
Last active August 29, 2015 14:03
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 manaten/7a7d9c5cc843f1dbf31b to your computer and use it in GitHub Desktop.
Save manaten/7a7d9c5cc843f1dbf31b to your computer and use it in GitHub Desktop.
HubotにQRコード作らせる
# Description:
# Show qr-code.
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# None
#
# URLS:
# /qrcode
#
qr = require 'qr-image'
module.exports = (robot) ->
robot.router.get /\/qr\/(.+)\.png/, (req, res) ->
try
code = qr.image req.params[0], { 'size': 10 }
length = 0
data = []
code.on 'data', (chunk)->
length += chunk.length
data.push chunk
code.on 'end', ->
res.writeHead 200, {'Content-Type': 'image/png', 'Content-Length': length}
res.write v for _, v of data
res.end()
catch e
res.end()
robot.hear /^qrcode\s(.+)/, (msg)->
string = encodeURIComponent msg.match[1]
robot.adapter.notice msg.envelope, "http://manaten.net:9090/qr/#{string}.png"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment