flowdock / hubot-flowdock

Flowdock adapter for Hubot chat bot
94 stars 60 forks source link

adapter does not support robot.messageRoom #78

Closed ChrisLundquist closed 9 years ago

ChrisLundquist commented 9 years ago

Consider the following hubot script:

# Description:
#   This script receives pages in the formats
#        /usr/bin/curl -d host="$HOSTALIAS$" -d output="$SERVICEOUTPUT$" -d description="$SERVICEDESC$" -d type=service -d notificationtype="$NOTIFICATIONTYPE$ -d state="$SERVICESTATE$" $CONTACTADDRESS1$
#        /usr/bin/curl -d host="$HOSTNAME$" -d output="$HOSTOUTPUT$" -d type=host -d notificationtype="$NOTIFICATIONTYPE$" -d state="$HOSTSTATE$" $CONTACTADDRESS1$

module.exports = (robot) ->
  robot.router.post '/hubot/nagios/:room', (req, res) ->
    robot.logger.debug req.params
    robot.logger.debug req.body

    room = req.params.room
    host = req.body.host
    output = req.body.output
    state = req.body.state
    notificationtype = req.body.notificationtype

    if req.body.type == 'host'
      robot.messageRoom "#{room}", "nagios #{notificationtype}: #{host} is #{output}"
    else
      service = req.body.description
      robot.messageRoom "#{room}", "nagios #{notificationtype}: #{host}:#{service} is #{state}: #{output}"

    res.writeHead 204, { 'Content-Length': 0 }
    res.end()

When testing this with curl, flowdock returned a 403.

[Mon Apr 20 2015 19:28:34 GMT+0000 (UTC)] DEBUG { room: 'UBot Fun' }
[Mon Apr 20 2015 19:28:34 GMT+0000 (UTC)] DEBUG {}
[Mon Apr 20 2015 19:28:35 GMT+0000 (UTC)] ERROR Unexpected error in Flowdock client: Error: Received status 403

I expected the human room name of 'UBot Fun' to work.

It seems that the adapter requires a room/flow to be of the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx where x is a hex character.

I propose the adapter translates from human name to GUID by hitting https://api.flowdock.com/flows.json on start and building a hash map.

This would bring functionality inline with the campfire and irc hubot adapters.

I investigated resolving the flow name to GUID per request in my script and it seems I can only hit the index, and that routes like https://api.flowdock.com/flows/find.json?name=Ubot%20Fun do not work to do this.