Follow these steps to run this code and start clearing up some of your company's jargon!
-
Your server will need to be publicly accessible via the internet.
- Consider using
ngrok
if you're testing this out from your local machine.- For example, if you will be running this bot locally on the default port of 3000, you can run
ngrok http 3000
and you'll get ahttps://x.ngrok.io
forwarding URL. Subsitutex.ngrok.io
for all references ofyour-host
in the rest of this document
- For example, if you will be running this bot locally on the default port of 3000, you can run
- Consider using
-
You'll need the following installed on your server.
- NodeJS and it's package manager
npm
- NodeJS and it's package manager
-
Download this codebase (using
git clone
, for example)
In your preferred web browser:
-
Create a new Slack app at api.slack.com/apps
-
Go to Interactivity & Shortcuts
- Enable Interactivity
- Enter your Interactivity Request URL:
https://your-host/slack/events
- Create a new Shortcut
- Select Global shortcut
- Choose a descriptive name and description for your shortcut, for example:
- Name: Search for a definition
- Description: Search Define
- For the Callback ID, it is important you set it to
shortcuts_phrase_search
- Enter your Select Menus Options Load URL
https://your-host/slack/events
-
Go to Slash Commands
- Create New Command
- Command: /define
- Request URL:
https://your-host/slack/events
- Short Description: Search for phrases
-
Go to OAuth & Permissions to add a bot scope
- Under Redirect URLs
- Add
https://your-host/app_installed
- Click Save URLs
- Add
- Under Scopes and Bot Token Scopes,
- Add
commands
so we can add a shortcut and a slash command - Add
users:read
so that we can lookup the user that executes commands
- Add
- Under Redirect URLs
-
If you plan to install your application to more than one workspace, go to Manage Distribution and activate public distribution
-
Go back to your new app's Basic Information page. We'll need to grab values from it in the next part.
docker pull ghcr.io/slackapi/definition-app:latest
The following steps will use a combination of your server's command line and a web browser:
-
Populate your
.env
file with the contents of.env.example
but with your own values.SLACK_CLIENT_ID= SLACK_CLIENT_SECRET= SLACK_SIGNING_SECRET= APPROVED_WORKSPACES= APPROVED_ENTERPRISES= DB_HOSTNAME= DB_USERNAME= DB_NAME= DB_PASSWORD= BLOCK_GUEST_USAGE=
SLACK_CLIENT_ID
,SLACK_CLIENT_SECRET
, andSLACK_SIGNING_SECRET
can be found on your new application's Basic Information pageAPPROVED_WORKSPACES
, andAPPROVED_ENTERPRISES
are the Workspace or Enterprise ID of the Workspace or Enterprise Grid you want to install the application to. This prevents other workspaces installing the app.DB_HOSTNAME
,DB_USERNAME
etc are the MySQL credentials for the database that will store your definitions.BLOCK_GUEST_USAGE
- By default the tool will allow Multi-Channel Guests to access your definitions. If you set this totrue
, guests will be prevented from querying the tool.
-
Run
npm install
to install code-level dependencies such as Bolt for Javascript etc. -
Start your application! You have two options:
npm start
will start your application in normal mode
At this point, your application should be accessible at
https://your-host
.If you're using ngrok, you'll want to start your tunnel with
ngrok http 3000
(adding-subdomain your-subdomain
if you have a paid Ngrok account)You can verify that your server is up and accessible by going to
https://your-host/
in your browser. If you see an 'Install' Button, you are good to go!
Back in your preferred web browser...
-
Install your app by visiting
https://your-host/
and clicking the 'Install' button. -
Try out your app! Execute your shortcut by entering "Search for a definition" in the quick switcher (CMD+k) or by using the lightning bolt ⚡️ symbol right below the message input field in Slack and filling out the form. You should see a modal appear. There's no definitions by default, but go ahead and add some!