Skip to content

Instantly share code, notes, and snippets.

@aaronjensen
Created January 14, 2011 06:05
Show Gist options
  • Save aaronjensen/779248 to your computer and use it in GitHub Desktop.
Save aaronjensen/779248 to your computer and use it in GitHub Desktop.
Connects Zen's XMPP to your HipChat. Run with ruby zen_to_hipchat.rb start
# Needs Ruby 1.8.7
# gem install hipchat
# gem install xmpp4r-simple
# gem install daemons
# run with ruby zen_to_hipchat.rb start
require 'rubygems'
require 'hipchat'
require 'xmpp4r-simple'
require 'daemons'
hipchat_api_key = '123456789abcdef' # API key from HipChat Admin pages
hipchat_room = 'RoomName' # Name or ID of your HipChat room
hipchat_name = 'Zen' # Name you want the bot to use, can be anything, doesn't need an account
jabber_username = 'user@gmail.com' # Gmail accounts work best, can't get GAFYD accounts working w/ Zen
jabber_password = 'password'
client = HipChat::Client.new(hipchat_api_key)
def get_html(msg)
msg.first_element("html").first_element("body").to_s.gsub(/\<\/?body.*?\>/,'')
end
def get_link(msg)
link = ''
msg.first_element("html").first_element("body").each_element_with_attribute('href') { |e|
link = e.attributes['href']
}
link
end
Daemons.run_proc do
im = Jabber::Simple.new(jabber_username, jabber_password)
while true do
im.reconnect if !im.connected?
im.received_messages { |msg|
client[hipchat_room].send(hipchat_name, get_html(msg), false) if msg.type == :chat
}
sleep 2
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment