Skip to content

Instantly share code, notes, and snippets.

@bmccormack
Last active August 29, 2015 14:13
Show Gist options
  • Save bmccormack/ce3c8c25e46da7805b8f to your computer and use it in GitHub Desktop.
Save bmccormack/ce3c8c25e46da7805b8f to your computer and use it in GitHub Desktop.
Subscribe to conversations in Help Scout

##Introduction

Have you ever wanted to subscribe to conversations in Help Scout? With Help Scout webhooks and webscript.io, now you can! Just add subscribed-yourname as a tag to a conversation (where yourname is the first part of your company email address), and you'll get emailed when a change comes in.

##Set up

  1. Make a webscript.io account. It's free to test.
  2. In webscript.io, make a new script. Copy in the code from the_code.lua (below) in this gist and paste it into the script.
    • Be sure to change the variables at the top.
    • If you need an SMTP server, you can get one from Mandrill in seconds (free accounts can send up to 12K emails per month, so you'll be fine).
    • The email_domain variable is your comapny domain, e.g. @yourcompany.com. This lets multiple people at the same company subscribe
  3. Add the webhooks app in Help Scout.
    • The secret key can be anything (keyboard cat)
    • The Callback URL is the URL of your script. You'll see a link icon next to the title where you can grab the URL. Change it to https for good measure.
    • For the events, I checked everything except "Conversation Created" and "Customer Created"
  4. You're all set! Just tag a case with subscribed-yourname and you'll get emails when someone edits the case or a new reply comes in.

NB: The script assumes you have notifications turned on in Help Scout. It's not going to send you emails if you're already assigned to the conversation or if you're the person who made the edit. You can modify the code if you don't like that.

--recommended: use Mandrill to send stmp email. mandrillapp.com
local username = 'your username'
local password = 'your password'
local server = 'your smtp server'
local email_domain = 'your email domain' --e.g. '@example.com'
local j = json.parse(request.body)
-- uncomment this part for testing
-- email.send {
-- server=server, username=username, password=password,
-- from= 'your_email@example.com',
-- to= 'your_email@example.com',
-- subject=j['subject'],
-- html = request.body
-- }
for k,v in pairs(j['tags']) do
local tag = v
local subscribed = false
local word = 0
for part in string.gmatch(tag, "%P+") do
--look for the word subscribed in the first part of the tag
if word == 0 and part == "subscribed" then
subscribed = true
end
--if subscribed exists, the 2nd part is the person to email
if word == 1 and subscribed then
local email_address = part .. email_domain
--log(email_address)
local id = j["id"]
--log(id)
local number = j["number"]
--log(number)
local subject = j['subject']
--log(subject)
local personType = j['threads'][1]['createdBy']['type']
--log(personType)
local firstName = j['threads'][1]['createdBy']['firstName']
--log(firstName)
local lastName = j['threads'][1]['createdBy']['lastName']
--log(lastName)
local personEmail = j['threads'][1]['createdBy']['email']
--log(personEmail)
local threadBody = j['threads'][1]['body']
--log(threadBody)
local email_body = '<p>You are subscribed to <a href="'
.."https://secure.helpscout.net/conversation/"
..id.."/"..number.."/"
..'">'..subject.."</a></p>"
.."<p>"..personType.." "
..firstName.." "
..lastName
.." with email address "
..personEmail
.." added the following:</p>"
.."<p>"
..threadBody
.."</p>"
assignedEmail = ""
if j['threads'][1]['assignedTo'] then
assignedEmail = j['threads'][1]['assignedTo']['email']
end
if personEmail ~= email_address and assignedEmail ~= email_address then
email.send {
server=server, username=username, password=password,
from= email_address,
to= email_address,
subject=j['subject'],
html = email_body
}
log('email sent')
end
end
word = word + 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment