Skip to content

Instantly share code, notes, and snippets.

@kylesuss
Last active August 29, 2015 14:04
Show Gist options
  • Save kylesuss/e028ffea372bdf77fe82 to your computer and use it in GitHub Desktop.
Save kylesuss/e028ffea372bdf77fe82 to your computer and use it in GitHub Desktop.
Simple steps to get Hipchat notifications up and running in 5 minutes. For use with the PunchClockServer from Panic: https://github.com/panicinc/PunchClockServer
# 1. Update the Gemfile
gem 'hipchat'
# 2. Retrieve dependencies via the command line
$ bundle install
# 3. Register a new API Auth Token of type Notification in the Group Admin, which only has access to send messages to rooms (requires admin access).
# 4. For dev, add the API key/token to your .env file
HIPCHAT_TOKEN=[YOUR_TOKEN]
# 5. For production on Heroku, add the HipChat key/token to your list of environment variables
heroku config:set HIPCHAT_TOKEN=[YOUR_TOKEN]
# 6. Make HipChat calls based upon behavior
# A simple example. Post an update to HipChat when someone leaves or arrives.
post '/status/update' do
...
if status_changed
client = HipChat::Client.new(ENV['HIPCHAT_TOKEN'])
if params[:status] === 'In'
# Lounge is the name of our office chat room for general office banter
# PunchClock is the name of the 'user' that posts the message to HipChat. It can be changed to anything.
client['Lounge'].send('PunchClock', "#{params[:name]} arrived at Our Awesome Company.", color: 'purple')
elsif params[:status] === 'Out'
client['Lounge'].send('PunchClock', "#{params[:name]} left Our Awesome Company.", color: 'purple')
end
end
...
end
# Another idea. Post an update to HipChat when someone sends a message to PunchClock.
post '/message/in' do
...
client = HipChat::Client.new(ENV['HIPCHAT_TOKEN'])
client['Lounge'].send('PunchClock', "#{params[:name]} said, '#{params[:message]}'", color: 'purple')
...
end
# 7. Panic (get it?) because your coworkers know where you are at all times.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment