The CHAOSS Slack Bot is built on the Bolt for JavaScript framework. You can get started by following the guide below to set up a new Slack app using socket mode.
-
First, we recommend creating a new workspace where you won’t disrupt real work getting done.
-
To create a Slack app and install it in your workspace, click here.
-
You should see a modal with two options for configuration. Choose the
From scratch
option. -
Click on the
Create App
button to go to the Basic Information page.
The bot currently has these OAuth Scopes enabled, so enable those for full functionality of the bot. If you're adding a new function, you might need more permissions. See the set up for adding new functions below.
A comprehensive list of permission scopes is available at api.slack.com/scopes.
-
Scroll up to the top of the OAuth & Permissions page and click Install App to Workspace. You’ll be led through Slack’s OAuth UI, where you should allow your app to be installed to your development workspace. See sample below.
Click on 'Allow' to confirm that the intallation was successful done on the Slack platform.
-
Once you authorize the installation, you will be led to OAuth & Permissions page and see a Bot User OAuth Access Token.
Treat your token like a password and keep it safe. Your app uses it to post and retrieve information from Slack workspaces.
- Navigate to your project folder
$ cd chaoss-slack-bot
- Copy your Signing Secret from the Basic Information page and then store it in a new environment variable.
- Copy your bot (xoxb) token from the OAuth & Permissions page and store it in another environment variable.
For Linux and macOS:
$ export SLACK_SIGNING_SECRET=<your-signing-secret>
$ export SLACK_BOT_TOKEN=xoxb-<your-bot-token>
For Windows:
- Create a new
.env
file in the root of your project. - Copy the content of the .env.example file and paste in the new .env file you created.
- Insert your tokens into the quotes. Make sure you include the .env file in your
.gitignore
file, to avoid exposing your secret keys.
To listen for events happening in a Slack workspace (like when a message is posted or when a reaction is posted to a message) you’ll use the Events API to subscribe to event types. CHAOSS Slack Bot uses Socket Mode.
- Head to your app’s configuration page (click on the app from your app management page). Navigate to Socket Mode on the left side menu and toggle to enable.
-
Go to Basic Information and scroll down under the App Token section and click Generate Token and Scopes to generate an app token. Add the
connections:write
scope to this token and save the generated xapp token. -
Scroll down to Subscribe to Bot Events and select the events you want your bot to listen to. CHAOSS Slack Bot currently subcribes to these events. The other available events are documented at api.slack.com/events.
-
Follow the rest of the instructions in the CONTRIBUTING.md.
After creating your app, you will see the options to add new function to your app.
- Select from the function you want to add from the list of feature provided and follow the prompt.
- Example:
Adapted from Getting started with Bolt for JavaScript.