Connecting Slack and Salesforce

An overview of what we’ve built at Slack to make our sales process work, and how you can do this too!

Amazing apps for sales teams are one of our top integration requests from customers. Our own sales team here at Slack is growing, and we’ve built a couple of useful bots and apps to connect Slack with Salesforce. We figured it’d be useful to tell our story of connecting Slack and Salesforce, so the following is a step by step overview of the process. We hope this is helpful to your own team, or for anyone looking for inspiration to build a Slack-Salesforce app.

Salesforce is also going to be hosting a webinar with us on this topic on May 12th. If you’re interested you can sign up here.

Step One: Build lead routing and notify account executives in Slack

Our first step was to organize, prioritize, and assign leads to account managers. Our Leads Bot automatically takes incoming leads and assigns them to managers, then reports that into an accounts channel. We also use an API made by Clearbit to help route leads.

Step Two: Reminder Bot

Leads bot was great, but some of our leads were slipping through the cracks when we found unacceptable response times to new leads. In order to remedy this situation, we built a reminder bot that gives account managers a gentle nudge for unanswered leads. With this in place, we went from an average response time of 6 hours down to 3–4 hours.

Step three: Accounts stats

The team wanted to stay up to date on total metrics so we sent reporting from Salesforce and billing in the form of summary reports into Slack.

Step four: a custom slash command

When the CEO asked if we could build a custom slash command that would give pertinent information for a specific account, we went ahead and built it.

Step five: A CSM bot

When we built up a new Customer Service Management (CSM) team, we built another bot similar to Leads Bot that assigned accounts to CSMs.

So: how did we build all this? With an amazing Sales Engineer and heavy use of both of our APIs. But the majority of the magic happens within Salesforce.

In Salesforce

Leads bot and assignment bot: use triggers. for leads and assignments create trigger classes within Salesforce that would execute upon an event, like create or update. The triggers call a defined class which runs the logic to return the information you’re looking for. For example: LeadTriggerHandler.aspx class returns the lead information: AE name, lead name & email, company name, link to lead.

Summaries of leads and reminder bot: use scheduled jobs. For weekly summaries of events you create jobs that run on a defined schedule. The jobs execute a defined class which returns the information you’re expecting. On top of this, we also use scheduled jobs for our reminder bot.

Slash accounts requires a visualforce page. This page calls a class which returns defined information depending on the data passed over in the json payload for the slash command. Validate the token that is passed over in the json payload, then the text in the command is parsed into a search term used to lookup account info. Once the account information is determined, use automatic properties to get and set the json string to be displayed as an ephemeral message in channel:public String jsonString { get; set; }

In Slack

Each bot has an additional class within Salesforce which contains the end point URL for the chat.postMessage method, you can find that here: https://api.slack.com/methods/chat.postMessage. We created custom labels within Salesforce to match most of the variables required in the API Post.

  • Token — token for the Sales Bot
  • Channel — the public channel we are looking to post the information to
  • Text — The displayed information. This comes from the class which is executed via the trigger or scheduled job.
  • Username — the displayed username for the bot
  • Icon_emoji — the selected emoji

So the string endPointURL looks like this

‘https://slack.com/api/chat.postMessage?token='+System.Label.Token + ‘&channel=’ + System.Label.leadsbot + ‘&text=’ + encodedMessage + ‘&username=’ +System.Label.leadsbot+ ‘&icon_emojil=’+system.label.leadsbotemoji;

What’s neat about this? All of the logic happens in Salesforce. Once the data is manipulated and the message is constructed, it is really very simple to get the info into Slack — just an API call away. The possibilities of what you can do to connect Slack and Salesforce are many — whatever is currently documented in Salesforce can be piped into Slack easily, which helps our team at Slack stay on the same page. We’ve found these apps increase transparency, efficiency and our ability to gather data and we hope that they can be helpful to you as well! If you’d like to see a deeper take from the team at Salesforce, they’ve written up an even simpler overview of how to build an integration: https://developer.salesforce.com/blogs/developer-relations/2016/05/slack-salesforce-integration.html.