Set Up Your Environment
In this project, you will:
- Set up a development environment using various tools.
- Use ngrok, the Slack APIs, and Node SDKs to build and test your bot.
- Build collaboration and interactivity into the bot.
This project was produced in collaboration with Slack, which owns, supports, and maintains the products, services, and features described here.
Ideally, you’re coming to this project with knowledge of what Slack Apps are and what each component of a Slack App can do for you. This is reviewed in the previous module. You can find it by clicking here.
In this project, you use the Slack APIs to build a bot that sends users a Welcome Message and Terms of Service to accept.
But before going on this quest, you set up your environment, including development tools, testing tools, a dedicated Slack workspace, and various resources found on api.slack.com.
To develop a Slack App, it is necessary to have a dedicated folder for all files relating to your project.
First, create a folder on your desktop and name it
first-slack-app. You’re going to be doing all of your work in here.
In case you don’t already have one, download a good text editor—one geared toward writing code. There are a lot of options out there, including Visual Studio Code, Sublime Text, and Atom. These are all available for any platform, so choose one that works for you and install.
Once you’ve installed your text editor, find the folder you’ve created and use your text editor to open the folder. In most text editors, you can click File, Open, and select the folder you’re working in.
If you go to https://api.slack.com/tools, you can see there’s a wide variety of Slack-built tools to make it easier for you to use the Slack APIs.
For the purposes of this module, we use the Node.js tools.
If you don’t have Node.js on your machine, head over to https://nodejs.org/en/download/. It’s generally easiest to select an installer option for the operating system you’re using, as it automatically installs Node.js and npm on your machine.
Once you have node and npm, open Terminal (MAC) or Command Line (Windows) and go to the folder you’ve created.
- In Terminal, type
cd ~/Desktop/first-slack-appthen press enter.
- In Command Line, type
[myUserName]replaced by the user name you have set for your machine. Then press enter.
When you're in the folder, type
npm init to create a package.json file in your folder.
This gives you a setup dialog that ends with the line
package name: (first-slack-app). For the purposes of this module, don’t worry about any of this stuff—just keep pressing the enter key until you reach a line that says
Is this ok? (yes).
From there, press enter one more time;
package.json has been created!
Next, install five libraries:
npm install --save @slack/events-apithen press enter.
npm install --save @slack/clientthen press enter.
npm install --save expressthen press enter.
npm install --save body-parserthen press enter.
npm install dotenv --savethen press enter.
This is what each library does for you.
@slack/events-apigives you the Node client for the Events API.
@slack/clientgives you the Node client for the Web API.
expressis a widely used minimal web framework for Node.js to build a lightweight server.
body-parseris a necessary helper library you won’t touch much that basically helps your server to read incoming requests.
dotenvmakes sure the the environment you set up in future steps interacts appropriately with your code.
If you want to see how your packages were installed, go back to your text editor and open the newly created
package.json in your first-slack-app folder.
You should see a section called
dependencies (starting at line 11) in this file where all the packages you installed show up by name.
Before you start building, you first need a place for Slack to send traffic. Typically, a business would use a dedicated web server for this. But for this module, we do this locally using ngrok.
- Download ngrok from this website: https://ngrok.com/download.
- Unzip the folder that you downloaded, revealing the executable ngrok file. On Mac and Linux, this is simply
ngrok, and on Windows, it’s
- Drag this executable ngrok file into your first-slack-app folder on your desktop.
It’s best to test your Slack App in a Slack workspace set aside for development before deploying into the business workspace where all your Slack users live. That way you can keep the space used for business clean and production data safe.
It’s easy to create a new workspace if you don’t have one dedicated to development already. And it’s free! Just go to Slack’s website, and find the Get Started button on the top right of the screen.
Press the button, follow the steps to create a new workspace, and you’re done.
Now we can get into the real adventure—to api.slack.com!
We won't check any of your setup. Click Verify Step to go to the next step in the project.