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.

  1. Make sure you are logged in to the Heroku Dashboard
  2. Click the Button below to deploy the application on Heroku.

    Deploy

Your own instance of the application is automatically deployed.

Make sure you understand the security implications before deploying the application in a production environment

Source Code

The source code for the Node.js application is available in this repository.

7 Responses to Slack and Salesforce Integration – Part 2

  1. agario March 8, 2016 at 10:07 pm #

    good of nice bloge

  2. dan March 10, 2016 at 3:01 pm #

    Thanks Christophe, this is great stuff.

    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.

  3. resim kursu March 28, 2016 at 4:08 pm #

    En güzel ortamda en güzel eğitimler en kaliteli hocalar ile en’lerin kulubu olan ruyaavcısı ekibi ile gerçekleştirilmektedir. Güzel sanatlara hazırlıkta bir numaralı adresiniz olan kurumumuz mezun ettiği öğrencilerden aldığı olumlu sonuçlar ve çevrelerindeki yönlendirmeler ile bizlere en çok referans olan şahıslardır. Atölyemizi incelemek için size bir telefon kadar yakınız. İster Avcılar isterseniz Esenyurt iki şubemiz ile haftanın yedi iş günü sizlere hizmet vermekteyiz. Avcılarda metrobüse yürüme mesafesinde olan resim kursu muz Size bir adım kadar yakın… Bakırköy resim kursu ile kalitenin farkına atölyemizde varacaksınız.

    http://ruyaavcisi.com/

  4. Matthew Evans April 4, 2016 at 7:48 am #

    Great article, why do you use Heroku and not expose a REST apex web service on Salesforce directly? Security, scale, other?

  5. Chandler Anderson May 12, 2016 at 2:07 pm #

    My Heroku log keeps coming up with this:

    2016-05-12T18:03:17.284619+00:00 app[web.1]: TypeError: Cannot read property ‘instance_url’ of undefined
    2016-05-12T18:03:17.284662+00:00 app[web.1]: at Connection._apiRequest (/app/node_modules/nforce/index.js:905:17)
    2016-05-12T18:03:17.284713+00:00 app[web.1]: at IncomingMessage.emit (events.js:179:7)

    Suggestions?

  6. propchill May 16, 2016 at 8:05 am #

    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.

    Real Estate Property In india

Trackbacks/Pingbacks

  1. Slack and Salesforce Integration | Christophe Coenraets - January 21, 2016

    […] to Slack” scenario, leaving “Slack to Salesforce” for another post (now available here). As an example, we will create a custom integration that automatically posts a message to the […]

Leave a Reply

css.php