In my previous post, I demonstrated how to access Slack from Salesforce. I shared an example showing how to use Slack Webhooks and ProcessBuilder to automatically post messages to Slack channels when specific events happen in Salesforce (for example, when the status of an opportunity changes).
In this post, I cover the other side of the integration. I’ll demonstrate how to access Salesforce from Slack using Slash Commands. As an example of this integration scenario, I’ll share three Slash commands:
- /pipeline [number to show]: Show the top Salesforce opportunities in the Slack UI
- /contact [searchkey]: Search contacts by name from the Slack UI
- /case [subject:description]: Create a case from the Slack UI
Watch the video below to see these commands in action in Slack:
To perform this integration, I wrote a lightweight Node.js app that acts as a message broker between Slack and Salesforce. When the Node.js application receives a request from Slack, it checks whether the token provided with the request is valid: if it matches the Slack token (generated when the slash command was created), a REST service is invoked to perform the requested action in Salesforce. If the token is not valid, an error is returned to the Slack client.
Follow the steps below to install this integration in your own environment:
Step 1: Create the Slash Commands
In Slack, create the three Slash Commands defines as follows:
Step 2: Deploy your Instance of the Node.js App
The easiest way to deploy your instance of the Node.js App is to click Deploy to Heroku button, and fill in the deployment wizard. You need to provide the username and password of an integration user in Salesforce. If you are testing this in a Developer Edition, you can enter your own credentials. For each command, you also need to provide the token generated when you created the command in Step 1.
- Make sure you are logged in to the Heroku Dashboard
- Click the Button below to deploy the application on Heroku.
Your own instance of the application is automatically deployed.
The source code for the Node.js application is available in this repository.