Ready to Fly

CI Workflow codecov

Sample app to showcase Slack + Salesforce integrations.

This app has been created using the Salesforce Slack Starter Kit. For a detailed explanation of the app architecture and the scaffolding script, take a look at Salesforce Slack Starter Kit’s README.

Prerequisites

To be able to run this project you will need:

  • git (download here)
  • node >= 14 (download here)
  • Salesforce Dev Hub
    • If you don’t have one, sign up for a Developer Edition org and then follow the instructions to enable Dev Hub.
  • sfdx CLI >= sfdx-cli/7.129.0 (download here)
  • Heroku account (signup)
  • heroku CLI (download here)
  • Slack Workspace

Setup Steps

Configuring Slack App

  1. Open https://api.slack.com/apps/new and choose “From an app manifest”
  2. Choose the workspace you want to install the application to
  3. Copy the contents of manifest.yml into the text box that says *Paste your manifest code here* and click Next
  4. Review the configuration and click Create
  5. In Basic Information scroll down to the Display Information section. Upload a picture for the app. You can use this logo
  6. Now click Install App on the left menu. Then click the Install to Workspace button and then click on Allow

Running the Scaffolding Script

The scripts/deploy.js script scaffolds all the entities needed for the sample app to work. To run the scaffolding script follow these instructions:

$ sfdx auth:web:login -d -a DevHub  # Authenticate using your Dev Hub org credentials (only needed if using JWT bearer flow)
$ heroku login  # Login with your Heroku account (or create one)
$ git clone https://github.com/trailheadapps/ready-to-fly
$ cd ready-to-fly/scripts
$ npm install
$ cd ..
$ node scripts/deploy.js
  1. During the set up process, the script will prompt you to enter value for SLACK_BOT_TOKEN. To enter this value open your apps configuration page from this list, click OAuth & Permissions in the left hand menu, then copy the value in Bot User OAuth Token and paste into terminal.

  2. The script will prompt you for slack signing secret SLACK_SIGNING_SECRET. To enter this value open your apps configuration page from this list, click Basic Information and scroll to the section App Credentials and click show button and copy the Signing Secret and paste into terminal.

Note: as ready to fly performs calls from Salesforce to Slack, we’ve modified the Salesforce Slack Starter Kit script to also deploy a remote site setting and a custom metadata type record that are used for callouts. We’ve also included the setup of some sample data.

Setting Heroku Instance in your Slack App

This is the last step, you will need to enter the current Heroku Instance url in Slack App.

  • To enter this value open your apps configuration page from this list, click App Manifest. Find the request_url fields (there will be two to update) in the manifest and modify it to replace heroku-app with your actual heroku domain name. Note at the end of this step your url should look like https://<heroku-domain>.herokuapp.com/slack/events.
  • Once done that, you’ll be prompted to verify the events endpoint. Click on ‘verify’. You’re ready to navigate to the app home!

How to Build and Deploy Code

  • For Salesforce metadata synchronization use sfdx force:source:pull to retrieve and sfdx force:source:push to deploy metadata from orgs to local project folder force-app

  • For the Bolt Node.js app use the steps below:

    • cd into apps/ready-to-fly folder cd apps/ready-to-fly
    • add git remote to app repo using heroku git:remote -a <heroku app name>
    • run git push heroku main to push code to Heroku

Local Development

  • For local Development, first make sure to deploy the app on Heroku as listed in the section above.
  • Authenticate to Salesforce from the app home page by clicking on Authorize with Salesforce button.
  • Once successfully authenticated, perform the steps below:
    1. Navigate to config file, and enable socket mode by uncommenting the socketMode and appToken in config file.
      const slack = { ...... port: process.env.PORT || 3000, socketMode: true, appToken: process.env.SLACK_APP_TOKEN };
    2. Generate an App Level Token in the Slack App by navigating to your Slack app at api.slack.com and scrolling to the section App-Level Tokens
    3. Populate the .env file with SLACK_APP_TOKEN variable obtained in previous step
    4. Comment out both request_url lines in the slack app’s App Manifest, and also set the socket_mode_enabled to true. Do this via the apps configuration page from this list, click App Manifest menu item for your app.
    5. cd into apps/ready-to-fly folder cd apps/ready-to-fly
    6. Run npm install
    7. Run node app.js

At this point you should see the Node.js app recieving events from Slack directly in VSCode terminal.

Note about Managers

The Managers dropdown that appears when you create a travel request is populated with information pulled from Salesforce. Concretelly, we take a look at the standard Nanager field on the User object, and pull two levels of Managers. You can change that behaviour to adapt it to your needs.

GitHub

View Github