visit
The folks at Salesforce have done one better. Taking into account Bolt’s development principles and tooling, they developed the . It’s an opinionated scaffolding framework designed to make it easy to build Slack Apps that integrate with Salesforce data.
SFDCContactEditor
, and choose a workspace where the App can be installed.
On the left side nav bar, click on App Manifest. Your App Manifest defines some metadata about your app, such as the permissions it requests and the events it handles. Paste the following YAML into that box, overwriting what was there by default:
_metadata:
major_version: 1
minor_version: 1
display_information:
name: SFDCContactEditor
features:
app_home:
home_tab_enabled: true
messages_tab_enabled: false
messages_tab_read_only_enabled: true
bot_user:
display_name: SFDCContactEditor
always_online: true
shortcuts:
- name: Whoami
type: global
callback_id: who_am_i
description: shows Salesforce org details
oauth_config:
scopes:
bot:
- chat:write
- chat:write.public
- commands
- users:read
settings:
event_subscriptions:
request_url: //heroku-app.herokuapp.com/slack/events
bot_events:
- app_home_opened
interactivity:
is_enabled: true
request_url: //heroku-app.herokuapp.com/slack/events
org_deploy_enabled: false
socket_mode_enabled: false
token_rotation_enabled: false
Click Save Changes. If you get an error about a URL being unverified, don’t worry—we’ll address that soon!
Next, clone the , and then navigate to the scripts
directory:
git clone //github.com/developerforce/salesforce-slack-starter-kit
cd salesforce-slack-starter-kit/scripts
Install the dependencies there with npm install
; then pop up a folder, and install those dependencies:
npm install
cd ..
npm install
Let’s see this in action. First, make sure you’re authenticated to your Salesforce Dev Hub by running sfdx auth:web:login
. Then, run node scripts/deploy.js
, and a CLI prompt will take over.
sfdc-contact-editor
. Make sure to select a unique name for your Heroku App, since app names need to be unique across all Heroku apps.scratchorg
is fine!
Now, grab a beverage and sit back, as the Starter Kit sets up some accounts for you. It creates a brand new scratch org and a new Heroku app, and it defines some essential environment variables for the deployed app to use. Note: if you receive a failure about a missing OrgCreateCommand
, make sure you have . If you receive a failure about a missing public key or permissions when pushing to Heroku, run heroku keys:add
.
Done deploying Heroku app sfdc-contact-editor
sfdx force:org:open
Now that we have a production version of the app available, we’ll need to make one more change to our Slack configuration to unite the two. Open up your and find the two lines that identify your Heroku endpoint:
request_url: //heroku-app.herokuapp.com/slack/events
Replace the heroku-app
placeholder with the actual name of your Heroku app. Click Save Changes. Slack will inform you that your request URL isn’t verified; click Verify to make that happen!
First, . You’ll be asked to authenticate with Salesforce; click on the button to do so. Then, head into any Slack room, and run the whoami
:
Next, let’s take a quick look at what’s inside the Starter Kit. Open up the project in your IDE, and navigate to the salesforcelib
folder. In here, there’s a file called connect.js
. This is where the entirety of the Salesforce authentication takes place. We don’t need to do anything to this file, but it’s useful to know just how much is being abstracted away for us.
Next, open up the listeners
folder. This folder contains all the app logic for listening to and responding to events from Slack. Open up shortcuts
, then whoami.js
. This file contains all of the functionality for the shortcut we just issued. There are two important things to point out:
ack
. Slack requires that an app acknowledge an event within three seconds of it occurring, and ack
is responsible for sending that message to Slack.const conn = context.sfconnection
—we fetch our connection information from Salesforce.
Lastly, let’s take a look at the user-interface folder. As you might have guessed, this folder contains all of the UI definitions for our Slack app. (We’ll definitely take a deeper look at how to build a UI in our next part.) Inside here, open up the modals folder, then open whoami-response.js
. The Starter Kit takes care of the actual definitions for designing and prompting the UI modal we saw. The only thing we can customize is the box text. Let’s get cheeky and add an exclamation point to the end of this sentence:
Successfully connected to salesforce instance ${instanceurl}. Authenticated with user ${username}!
$ salesforce-slack-starter-kit (main): git add apps/slack-salesforce-starter-app/user-interface/modals/whoami-response.js
$ salesforce-slack-starter-kit (main): git commit -m "Add an exclamation point"
> [email protected] precommit
> lint-staged
✔ Preparing...
✔ Running tasks...
✔ Applying modifications...
✔ Cleaning up...
[main 44aac80] Add an exclamation point
1 file changed, 1 insertion(+), 1 deletion(-)
$ git push heroku main
When Heroku is finished, you can return to Slack, issue the same whoami
shortcut, and see your new change live.
Also Published .