From 513f2e605da36e9efe80b15b8fc426b7c7d6d93c Mon Sep 17 00:00:00 2001 From: Arttu Tervo Date: Mon, 31 Oct 2011 14:21:19 +0200 Subject: [PATCH] Flowdock adapter --- bin/hubot | 2 +- package.json | 3 ++- src/hubot/flowdock.coffee | 42 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/hubot/flowdock.coffee diff --git a/bin/hubot b/bin/hubot index e8a6ebda7..1e1ebc4c6 100755 --- a/bin/hubot +++ b/bin/hubot @@ -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"], diff --git a/package.json b/package.json index 2e33fd122..6d6799f14 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/hubot/flowdock.coffee b/src/hubot/flowdock.coffee new file mode 100644 index 000000000..70098cab5 --- /dev/null +++ b/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