Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Shopify <3 Adhearsion

titanous
October 08, 2011

Shopify <3 Adhearsion

At Shopify, we have 15,000 stores and we handle all sales and support calls in house. We needed a fast, flexible and reliable way of handling these calls, and none of the applications we found met our needs. So we did what any good geek would do: we rolled our own. Adhearsion made this possible. It simplified the onerous task of building an Asterisk-based app. Within less than a month, we had a functional app used in production by all of our agents, serving real customers. Along with showing callers, queue stats, and agent statuses, our "Q" app also displays information about customers and their shops; allowing agents to better serve them.

Presentation by @pushmatrix and @titanous

titanous

October 08, 2011
Tweet

Other Decks in Programming

Transcript

  1. We hire humans. This is our sales & support team

    at our annual volleyball game. Our phone support team only has 4 members. They look after -->
  2. 15,000 customers 15000 customers!!, and although we strive to make

    Shopify as simple as possible, we still do get support calls.
  3. 800 calls per week We get ~800 calls per week,

    and we want to make sure our team has the best tools possible to answer them.
  4. one problem but we had 1 problem. The third party

    hosted phone solution we were using had some limitations. We wanted it to be more integrated with Shopify. We needed our agents to have all necessary information at their finger tips, so they didn’t have to dig around for it.
  5. http://www.flickr.com/photos/mandj98/5079617428/ But then Adhearsion came along: our knight in shining

    armor! It would help us conquer the dark beast that is Asterisk. And indeed, it did.
  6. Q With Adhearsion, we were able to make our own

    internal phone tool called “Q”
  7. Now we were able to go to our “00” support

    agents and say “James, this is no ordinary pen”.
  8. “It’s a blazing fast phone system that uses Adhearsion, and

    best of all, it’s written in ruby!”
  9. AMI Adhearsion talks to Asterisk over AMI. This allows us

    to receive events and trigger actions.
  10. Drb The web interface is powered by Sinatra, which uses

    Drb to get information about the queue status.
  11. HTTP When an event comes into Adhearsion, lookups are performed,

    stats are logged, and then we use Faye to push data to the browser. Faye is a dead-simple pub-sub server that we communicate with over HTTP.
  12. HTTP Websockets Faye pushes the events to the browser using

    websockets, which allows the UI to be very responsive.
  13. Asterisk queues.conf [support] eventmemberstatus = yes eventwhencalled = yes Let’s

    look at some of the code behind Q. These two options turn on a bunch of AMI events that are very useful, like QueueMemberStatus.
  14. Adhearsion events.rb case event.name when 'Join' STATS.join(event.headers) publish_with_stats '/caller/join', EventJson.caller_join(event.headers)

    when 'QueueMemberStatus' STATS.change_status(headers) Bayeux.publish '/agent/status', EventJson.agent_status(event.headers) ... This is a snippet from our Adhearsion event handler. As AMI events come in, we log statistics, and then publish a JSON object derived from the event with Faye. Some events will cause updated stats to be included in the JSON.
  15. stats.rb def join(headers) position = headers['Position'] queue = Queue.name(headers['Queue']) record

    'call', queue update_max queue + ':callers', position end This is one of the stats methods that logs data to redis. We wrote a bunch of simple methods to log counters, averages, and maximums in redis.
  16. Sinatra get '/' do @status = AdhearsionDRb.queuestatus \ :queue =>

    'support' @stats = STATS.to_hash erb :index end We use Drb to fetch the current queue status, and get the current stats from Redis, they are rendered out as JSON into the template. Q has a lot of moving parts. From changing agent statuses, to updating the queue list, to showing who’s on phone with who... we needed a way to tie all those together without a whole lot of glue code.
  17. Copyright Chrissymay: http://www.flickr.com/photos/chrissy404/5717843555/sizes/l/in/set-72157623147639795/ Batman.js is a coffeescript MVC framework that

    lets you create highly interactive single page web apps. It’s designed to be fast. Really fast. In fact, let’s make a mini version of Q right now. https://github.com/pushmatrix/MiniQ