Skip to content

Instantly share code, notes, and snippets.

@incarnate
Created December 6, 2014 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save incarnate/40b38ae3e350f71f88c5 to your computer and use it in GitHub Desktop.
Save incarnate/40b38ae3e350f71f88c5 to your computer and use it in GitHub Desktop.
LiveChat agents Dashing widget

##Preview

Description

Simple Dashing widget to display LiveChat agents status (number online and number accepting chats).

If the number of agents accepting chats drops to 0, a red highlight is displayed.

##Dependencies

rest-client

Add it to dashing's gemfile:

gem 'rest-client'

and run bundle install. Everything should work now :)

##Usage

The easiest way to install is to grab this gist's ID from the URL and use dashing install.

Otherwise, to use this widget, copy livechat_agents.html, livechat_agents.coffee, and livechat_agents.scss into the /widgets/livechat_agents directory. Put the livechat_agents.rb file in your /jobs folder.

To include the widget in a dashboard, add the following snippet to the dashboard layout file:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="livechat_agents" data-view="LivechatAgents" data-title="LiveChat Agents"></div>
</li>

##Settings

You'll need to add a LiveChat login email and API key to the livechat_agents.rb job file.

The jobs runs every thirty seconds by default, you can adjust that by editing the SCHEDULER line in the job file.

class Dashing.LivechatAgents extends Dashing.Widget
ready: ->
# This is fired when the widget is done being rendered
onData: (data) ->
@accessor 'livechat_available', Dashing.AnimatedValue
@accessor 'isTooLow', ->
@get('livechat_available') < 1
<ul>
<li data-bind-class="status">
<h1 class="title" data-bind="title"></h1>
<div>
<div data-addclass-danger="isTooLow">
<h3 data-bind="livechat_available"></h3>
<h4>available</h4>
</div>
<div>
<h3 data-bind="livechat_online"></h3>
<h4>online</h4>
</div>
<p class="updated-at" data-bind="updatedAtMessage"></p>
</div>
</li>
</ul>
#!/usr/bin/env ruby
require 'rest-client'
require 'json'
require 'cgi'
livechat_email = "LIVECHAT LOGIN EMAIL"
livechat_key = "LIVECHAT API KEY"
uri = "https://#{CGI.escape(livechat_email)}:#{CGI.escape(livechat_key)}@api.livechatinc.com/agents"
# :first_in sets how long it takes before the job is first run. In this case, it is run immediately
SCHEDULER.every '30s', :first_in => 0 do |job|
headers = {:'X-API-Version' => "2"}
response = RestClient.get uri, headers
agents = JSON.parse(response.body, symbolize_names: true)
statuses = Hash.new(0)
agents.each{|agent| statuses[agent[:status]] += 1 }
online = statuses["not accepting chats"] + statuses["accepting chats"]
send_event('livechat_agents', { livechat_available: statuses["accepting chats"], livechat_online: online })
end
.widget-livechat-agents {
background-color: #86d751;
h3 {
font-size: 60px;
font-weight: bold;
}
h4 {
font-size: 20px;
font-weight: bold;
text-transform: uppercase;
}
p &.updated-at {
font-size: 10px;
}
.danger {
background: red;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment