I want to add a simple user-password authentication to my coffescript for a Hubot. This should act like a "bridge" to send messages to rocketchat. I managed to make a HTTP-Post request without authentication to work.
The script i got so far works pretty good but without authentication:
module.exports = (robot) ->
robot.router.post '/hubot/say', (req, res) ->
recipient = req.body.recipient
message = req.body.message
dm = req.body.directmessage
response = "OK"
robot.logger.info "DM: #{dm}; Recipient: #{recipient}; Message: #{message}"
if dm == '0'
#robot.logger.info "Message '#{message}' received for room #{recipient}"
room = recipient
user = robot.brain.userForId 'broadcast'
user.room = room
user.type = 'groupchat'
if message
robot.adapter.send({room, user: {} }, message)
if dm == '1'
user = recipient
if message
robot.adapter.sendDirect({ user: { name: "#{user}"} }, message)
res.writeHead 200, {'Content-Type': 'text/plain'}
res.end response