|
2 | 2 | title: Getting Started |
3 | 3 | --- |
4 | 4 |
|
5 | | -This tutorial will show you how to use the packages in this Node Slack SDK to get a simple Slack app running. If you've |
| 5 | +This guide shows how to use the packages in the Node Slack SDK to get a simple Slack app running. If you've |
6 | 6 | never used the Slack APIs before, you're in the right place. Welcome, and let's get started! |
7 | 7 |
|
8 | 8 | ## Create a Slack app |
9 | 9 |
|
10 | | -The first step is to [create a new app](https://api.slack.com/apps?new_granular_bot_app=1) with Slack at the API website. Give your app a |
11 | | -fun name and choose a Development Slack Workspace. We recommend using a workspace where you aren't going to disrupt real |
12 | | -work getting done — you can create a new one for free. After you create an app, you'll be greeted with some basic information. |
| 10 | +The first step is to [create a new app](https://api.slack.com/apps?new_app=1). Give your app a fun name and choose a development Slack workspace. We recommend using a workspace where you aren't going to disrupt real work getting done — you can create a new one for free. After you create an app, you'll be greeted with some basic information. |
13 | 11 |
|
14 | | -In this guide we'll be **calling a method of Web API** to post a message to a channel. The Web API is the foundation of |
15 | | -the Slack Platform, and almost every Slack app uses it. Aside from posting messages, the Web API allows your app to call |
16 | | -[methods](https://api.slack.com/methods) that can be used for everything from creating a channel to updating a user's |
17 | | -status. Before we can call any methods, we need to configure our new app with the proper permissions. |
| 12 | +In this guide, we'll be calling a method of the Web API to post a message to a channel. The Web API is the foundation of |
| 13 | +the Slack platform, and nearly every Slack app uses it. Aside from posting messages, the Web API allows your app to call |
| 14 | +[methods](https://docs.slack.dev/reference/methods) that can be used for everything from creating a channel to updating a user's status. Before we can call any methods, we first need to configure our new app with the proper permissions. |
18 | 15 |
|
19 | 16 | ## Get a token to use the Web API |
20 | 17 |
|
21 | | -Navigate to **OAuth & Permissions** and scroll down to the section for scopes. Slack describes the various permissions |
22 | | -your app could obtain from an installing bot as **scopes**. There are [over 80 scopes](https://api.slack.com/scopes)! |
23 | | -Some are broad and authorize your app to access lots of data, while others are very specific and let your app touch just |
24 | | -a tiny sliver. Your users (and their IT admins) will have opinions about which data your app should access, and only |
25 | | -agree to install the app if the data permissions seem reasonable, so we recommend finding the scope(s) with the least |
26 | | -amount of privilege for your app's needs. In this guide we will use the Web API to post a message. The scope required |
27 | | -for this is called [`chat:write`](https://api.slack.com/scopes/chat:write). Scroll down to "Bot Token Scopes", ensure this section is expanded, then click "Add an OAuth Scope", find the |
28 | | -[`chat:write`](https://api.slack.com/scopes/chat:write) scope and select it to add it to your app. |
| 18 | +In your [app settings](https://api.slack.com/apps), select the app you created and navigate to **OAuth & Permissions** in the left nav. Scroll down to the section for scopes. Slack describes the various permissions |
| 19 | +your app could obtain from an installing bot as scopes. There are [over 80 scopes](https://docs.slack.dev/reference/scopes)! Some are broad and authorize your app to access lots of data, while others are very specific and let your app touch just a tiny sliver. Your users (and their IT admins) will have opinions about which data your app should access and only agree to install the app if the data permissions seem reasonable, so we recommend finding the scope(s) with the least amount of privilege for your app's needs. In this guide, we will use the Web API to post a message. The scope required for this is [`chat:write`](https://docs.slack.dev/reference/scopes/chat.write). Scroll down to **Bot Token Scopes**, ensure this section is expanded, then click **Add an OAuth Scope**, find the [`chat:write`](https://docs.slack.dev/reference/scopes/chat.writee) scope and select it to add it to your app. |
29 | 20 |
|
30 | | -Now our app has described which scope it desires in the workspace, but we haven't added it to your workspace yet. To install your app, scroll up to the top of the page and click the **Install to Workspace** button. You'll be taken to the app installation page. This page is where you grant the bot user permission to install the app in your development workspace with specific capabilities. |
| 21 | +Now our app has declared which scope it desires in the workspace, but we haven't added it to your workspace yet. To install your app, scroll up to the top of the page and click the **Install to Workspace** button. You'll be taken to the app installation page. This page is where you grant the bot user permission to install the app in your development workspace with specific capabilities. |
31 | 22 |
|
32 | | -Go ahead and click "Allow". This will install the app on the workspace and generate the token we'll need. |
| 23 | +Click **Allow**. This will install the app on the workspace and generate the token we'll need. |
33 | 24 |
|
34 | | -When you return to the **OAuth & Permissions** page copy the **Bot User OAuth Access Token** (it should begin with `xoxb`). Treat |
35 | | -this value like a password and keep it safe. The Web API uses tokens to authenticate the requests your app makes. In |
36 | | -a later step, you'll be asked to use this token in your code. |
| 25 | +When you return to the **OAuth & Permissions** page, copy the **Bot User OAuth Access Token** (it should begin with `xoxb`). Treat this value like a password and keep it safe. The Web API uses tokens to authenticate the requests your app makes. In a later step, you'll be asked to use this token in your code. |
37 | 26 |
|
38 | 27 | ## Set up your local project |
39 | 28 |
|
@@ -72,15 +61,15 @@ If you see the same output as above, we're ready to start. |
72 | 61 |
|
73 | 62 | ## Send a message with the Web API |
74 | 63 |
|
75 | | -In this guide we'll post a simple message that contains the current time. We'll also follow the best practice of keeping |
| 64 | +In this guide, we'll post a simple message that contains the current time. We'll also follow the best practice of keeping |
76 | 65 | secrets outside of your code (do not hardcode sensitive data). |
77 | 66 |
|
78 | 67 | Before we move forward, add the bot user you created above to the `#general` channel in your workspace. Bots need to be |
79 | 68 | invited to channels to be able to post in them. You can do this by going to the `#general` channel inside slack in your workspace and |
80 | 69 | type `/invite @YourBotUser` with the display name of your bot user. |
81 | 70 |
|
82 | 71 | Store the access token in a new environment variable. The following example works on Linux and MacOS; but [similar |
83 | | -commands are available on Windows](https://superuser.com/a/212153/94970). Replace the value with OAuth Access Token that |
| 72 | +commands are available on Windows](https://superuser.com/a/212153/94970). Replace the value with OAuth Access token that |
84 | 73 | you copied earlier. |
85 | 74 |
|
86 | 75 | ```shell |
@@ -132,9 +121,8 @@ You just built your first Slack app with Node.js! 🎉 |
132 | 121 | There's plenty more to learn and explore about the Node Slack SDK and the Slack platform. Here are some ideas about where to look next: |
133 | 122 |
|
134 | 123 | * This tutorial only used two of **over 200 Web API methods** available. [Look through |
135 | | - them](https://api.slack.com/methods) to get ideas about what to build next! |
| 124 | + them](https://docs.slack.dev/reference/methods) to get ideas about what to build next! |
136 | 125 |
|
137 | 126 | * You now know how to build a Slack app for a single workspace, [learn how to implement Slack |
138 | | -OAuth](https://api.slack.com/authentication/oauth-v2) to make your app installable in many workspaces. If you are using |
139 | | - [Passport](http://www.passportjs.org/) to handle authentication, you may find the |
| 127 | +OAuth](https://docs.slack.dev/authentication/installing-with-oauth) to make your app installable in many workspaces. If you are using [Passport](http://www.passportjs.org/) to handle authentication, you may find the |
140 | 128 | [`@aoberoi/passport-slack`](https://github.com/aoberoi/passport-slack) strategy package helpful. |
0 commit comments