Skip to content

Instantly share code, notes, and snippets.

@plehoux
Last active December 17, 2015 08:29
Show Gist options
  • Save plehoux/5580089 to your computer and use it in GitHub Desktop.
Save plehoux/5580089 to your computer and use it in GitHub Desktop.
Small rake task for a better customer support chat experience with HipChat. Hide link to your support chat room if nobody is there to help. No CHAT ROOM is better than an empty one.
desc 'Update Chat Status'
namespace :scheduler do
task :update_chat_status => :environment do
begin
# Connect to HipChat
hc = HipChat::API.new(HIPCHAT_API_KEY)
# Fetch your support chat room id
room_id = hc.rooms_list['rooms'].find{|r| r['name'] =~ /conferencebadge\.com/i}['room_id']
# Fetch users in room
users_in_room = hc.rooms_show(room_id)['room']['participants'].map{|p| p['user_id']}
# Get your team user ids
help_staff_ids = hc.users_list['users'].map{|u|u['user_id']}
# Update a boolean variable, somewhere, we use an Option table in our database.
set_status (users_in_room & help_staff_ids).any?
rescue
set_status false
raise
end
end
end
def set_status(value)
Option.find_or_create_by_name(:chat_status).update_attribute(:value, value ? 'true' : 'false')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment