Skip to content
This repository has been archived by the owner. It is now read-only.
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
59 lines (51 sloc) 1.97 KB
# Description:
# Display number of concurrent vistors to the specified site.
# Dependencies:
# None
# Configuration:
# HUBOT_CHARTBEAT_SITES <comma separated string of all
# HUBOT_CHARTBEAT_API_KEY <use global key for access to all sites>
# Commands:
# hubot chart me - Returns active concurrent vistors from the default site specified.
# hubot chart me <host> - Returns active concurrent vistors from the site specified.
# hubot chart bomb - Returns active concurrent visitors from all sites.
# Notes:
# How to find these settings:
# Log into chartbeat then browse to
# Author:
# Drew Delianides
getChart = (msg, apiKey, site) ->
.get() (err, res, body) ->
unless res.statusCode is 200
msg.send "There was a problem with Chartbeat. Do you have access to this domain?"
response = JSON.parse(body)
people = response.people || []
if (people < 1)
msg.send "It doesn't appear that #{site} has any visitors right now"
pluralize = if (people == 1) then "person" else "people"
msg.send "I see #{people} #{pluralize} on #{site} right now!"
module.exports = (robot) ->
robot.respond /chart( me)? (.*)/i, (msg) ->
if (!process.env.HUBOT_CHARTBEAT_SITE && msg.match[2] == 'me')
msg.send "You need to set a default site"
if (!process.env.HUBOT_CHARTBEAT_SITES && msg.match[2] == 'bomb')
msg.send "You need to set a list of sites"
sites = switch msg.match[2]
when "me" then [process.env.HUBOT_CHARTBEAT_SITE]
when "bomb" then process.env.HUBOT_CHARTBEAT_SITES.split(",")
when "*" then process.env.HUBOT_CHARTBEAT_SITES.split(",")
else [msg.match[2]]
apiKey = process.env.HUBOT_CHARTBEAT_API_KEY
getChart(msg, apiKey, site) for site in sites
You can’t perform that action at this time.