Main

Slack and Salesforce Integration – Part 2

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:

/pipeline and /case are “in channel” commands: the response is visible to all members of the channel. /contact is “ephemeral”: the response is only visible to the user that issued the command .

Architecture

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:

Command

URL

Method

Custom Name

/pipeline

https://app_name.herokuapp.com/pipeline

POST

Top Opportunities

/contact

https://app_name.herokuapp.com/contact

POST

Salesforce Contacts

/case

https://app_name.herokuapp.com/case

POST

Salesforce cases

You can change the URLs later if you are not sure what your app name will be. The important thing at this point is to generate the token for each command.

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.

Quick question regarding the client secret in heroku- can you offer some guidance around setting up the new app from Salesforce? Not sure what I should be building in order to generate a new client secret.

There are a number of drivers which contribute towards the residential real estate in India; these are highlighted in the illustration below. We have already discussed the housing shortfall which is one of the key drivers; the second most important factor is the Indian diaspora, which tends to get overlooked. If the real estate sector in India is able to initiate some confidence building measures in the coming years, it would go a long way in tapping this huge potential market.

Having never set something up like this, am I missing something obvious? I added a connected app in salesforce and wasn’t sure what to set the callback URL.

John Krech

I get the same error – did you ever find a fix?

Jessica Meyer

Unfortunately I had to drop the project for awhile, so no, but I’d love to pick it back up after awhile so if you have any updates do share! :)

Jaya Prakash Kommu

I got this error when my redirect url in salesforce connected app was incorrect. Check if your call back url in salesforce app is similar to this: https://.herokuapp.com/oauthcallback

rihanna

this worked for me! Thanks!

rihanna

Is there any way to have a command that searches for cases? Similarly to the /contacts command?

Victor

Is it possible to pass more parameters when using the slash command to create a case? Let’s say I want the case to be associated with with an account and contact when created from slack. Is it possible to enter this parameters from slack?

Anupam Shrivastava

Hello there. I am unable to create custom integration on slack so I created an app there and creating slash commands. But I am unable to get any token so what should be copied to Heroku Config Var?