Skip to content

Commit

Permalink
Flowdock adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Arttu Tervo committed Oct 31, 2011
1 parent 94dc791 commit 513f2e6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bin/hubot
Expand Up @@ -13,7 +13,7 @@ Creator = require '../src/creator'
OptParse = require 'optparse'
PortNumber = parseInt(process.env.PORT) || 8080

Adapters = ["irc", "campfire", "hipchat", "twilio", "xmpp", "groupme", "talker", "twitter"]
Adapters = ["irc", "campfire", "hipchat", "twilio", "xmpp", "groupme", "talker", "twitter", "flowdock"]
Switches = [
[ "-h", "--help", "Display the help information"],
[ "-a", "--adapter ADAPTER", "The Adapter to use"],
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -23,7 +23,8 @@
"irc": "0.2",
"node-xmpp": ">=0.2.6",
"wobot": "0.3.0",
"imap": "0.2.5"
"imap": "0.2.5",
"flowdock": "0.2.0"
},

"main": "./index",
Expand Down
42 changes: 42 additions & 0 deletions src/hubot/flowdock.coffee
@@ -0,0 +1,42 @@
Robot = require "../robot"
flowdock = require "flowdock"

class Flowdock extends Robot
send: (user, strings...) ->
strings.forEach (str) =>
@bot.chatMessage(user.flow.subdomain, user.flow.name, str)

reply: (user, strings...) ->
strings.forEach (str) =>
@send user, "#{user.name}: #{str}"

run: ->
self = @
options =
login_email: process.env.HUBOT_FLOWDOCK_LOGIN_EMAIL
login_password: process.env.HUBOT_FLOWDOCK_LOGIN_PASSWORD

bot = new flowdock.Session(options.login_email, options.login_password)
bot.fetchFlows((flows) =>
flows.forEach (flow) =>
bot.fetchUsers(flow.organization.subdomain, flow.slug, (users) =>
users.forEach (flow_user) =>
return if flow_user.user.disabled == true
user =
id: flow_user.user.id
name: flow_user.user.nick
@userForId(user.id, user)
)
bot.subscribe(flow.organization.subdomain, flow.slug)
)

bot.on "message", (message) =>
return unless message.event == 'message'
flow = bot.flows.filter((flow) -> return flow.name == message.flow)[0]
author = @userForId(message.user)
author.flow = flow
self.receive new Robot.TextMessage(author, message.content)

@bot = bot

module.exports = Flowdock

0 comments on commit 513f2e6

Please sign in to comment.