In order to interact with the Slack API, you will need to set up an authentication token. This token will not be shared, so both partners must follow these steps.
-
Go to https://api.slack.com/apps
- You might have to sign in using your Slack credentials
-
Click the green
Create New App
button -
Fill out the details in the modal window
- For the name of your app use
ClassName - YourName - API Project
- For the workspace, use the Slack workspace for your cohort
- Click the green
Create App
button
- For the name of your app use
-
Click
Add features and functionality
, thenPermissions
-
Scroll down to
Scopes
, and add the following three permissions:chat:write:bot
channels:read
users:read
- Click the green
Save Changes
button
-
Install and authorize the app:
- Scroll to the top of the page and click the green
Install App to Workspace
button - Check that your app's permissions are correct and click the green
Authorize
button
- Scroll to the top of the page and click the green
-
You should now see an
OAuth Access Token
. Copy this and paste it into your app's.env
file.- The
.env
file should already be in the provided.gitignore
, but it doesn't hurt to double check!
- The
Your application should now be able to access Slack!
To verify that you've set up the Slack token correctly, work with your partner to write a script that does the following:
- Use the
dotenv
gem to load environment variables - Use HTTParty to send a
GET
request to thechannels.list
endpoint - Check that the request completed successfully, and print relevant information to the console if it didn't
- Loop through the results and print out the name of each channel
If your tokens are set up correctly, each of you should be able to run this script.