Inject Your App Data Into Help Scout

At Honeybadger we use Help Scout to manage our customer support, and that has worked out well for us. One thing I’ve wanted for quite a while is more integration between Help Scout, our internal dashboard, and the Stripe dashboard. After taking a mini-vacation to attend MicroConf this week, I decided it was time to make my dreams come true. :)

Help Scout allows you to plug “apps” into their UI, and you can build your own apps to populate the sidebar when looking at a help ticket. All you have to do is provide a URL that Help Scout can hit which returns a blob of HTML to be rendered on the page. Your app receives a signed POST request where the payload is some information about the support ticket you are viewing, which includes the email address of the person who created the ticket. Here’s a Rails controller that receives the request, verifies the signature, and returns some HTML for the user found by email address:

require 'base64'
require 'hmac-sha1'

class HelpscoutController < ApplicationController
  skip_before_filter :verify_authenticity_token
  before_filter :verify_signature

  def user
    payload = JSON.parse(request.raw_post)
    if payload['customer'] && payload['customer']['email'] && @user = User.where(email: payload['customer']['email']).first
      render json: { html: render_to_string(action: :user, layout: false) }
      render json: { html: "User not found" }



    def verify_signature
      bail and return false unless (sig = request.headers['X-Helpscout-Signature']).present?

      (hmac ="secret-that-you-enter-in-helpscout's-ui")).update(request.raw_post)

      bail and return false unless sig.strip == Base64.encode64(hmac.digest).strip

    def bail
      render json: { html: "Bad signature" }, status: 403

After fetching the user record, it returns a blob of HTML via a HAML view:

  %li Created on #{l(@user.created_at.to_date, format: :long)}

Then you’re done! Now when you view a ticket in Help Scout you’ll see info from your database about that user in the sidebar.