Authorize Your Bot
https://api.slack.com/ gives you a launching pad to begin building your Slack App. Time to dive in!
- Navigate to
https://api.slack.com/ and click Start Building.
- Click Create New App. This takes you to the Create a Slack App menu where you can name your bot.
- Name your bot
- Select your newly created workspace.
- Click Create App.
- Make sure your Slack App is selected in the API screen, as indicated in the top left of the screen above the navigation menu.
From here, it’s all about setting up permissions.
Slack gives you the ability to control how, where, and when your Slack App posts and retrieves information. This is done through Permissions. Permissions keep your Slack App secure and let you be transparent to your users about what you’re doing with it.
There’s a lot of Permissions available but we focus on the critical ones for this project—
- Select OAuth and Permissions from the left-hand menu.
- Scroll down to the Scopes section and search for and select
chat:write:botfrom the dropdown.
- Also search for and select
- Click Save Changes.
While there is a short description of the permissions on screen, let’s dig a little deeper so we know exactly what they’re doing.
chat:write:botpermission gives you the ability to send people messages as your bot user.
users:readpermission lets you access your workspace’s profile information. It’s also necessary for you to detect a new user.
The concept of installing your Slack App can seem strange since you haven’t built anything yet. But in this case, “installing” means to associate your Slack App with your workspace, and officially grant it access according to the permissions you gave in the previous step.
- Scroll back to the top and click Install App to Workspace.
- On the next screen, click Authorize. You’ll be taken back to the OAuth and Permissions page, which should now display an OAuth Access Token—a string of characters that starts with “xoxp.” This token lets Slack know that your Slack App has the right
permissions you’ve set up.
- Click Copy on the token field. This comes into play later.
It’s time to make your token usable by your code. You do this in your text editor.
- Go to your text editor. In the editor, you should still have your
first-slack-appfolder open, along with a file on the side
- Create a new file. You can do this by selecting File then New or New File in the menu.
- Without typing anything, click File again, then Save As, and save the file as
- Now enter your token. To do this, replace
<place token here>with your token in the following line
SLACK_TOKEN=<place token here>in line one of the .env file.
- Save this file again.
Congratulations, you’ve made your token usable by your code! This step gives you authorization to use the Slack APIs. Now let’s start giving your code the power to do stuff.
We won't check any of your setup. Click Verify Step to go to the next step in the project.