You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: AGENTS.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -107,6 +107,10 @@ Individual packages have their own `AGENTS.md` with package-specific guidance:
107
107
108
108
Block Kit types are defined in the `@slack/types` package. See `packages/types/AGENTS.md` for detailed steps covering interface definition, discriminated union registration, barrel exports, and type tests.
109
109
110
+
## Pull Requests
111
+
112
+
When opening a pull request, use the repository's PR template at `.github/pull_request_template.md` as the PR body — the `gh` CLI does not populate it automatically, so pass the filled-in template explicitly (e.g. via `gh pr create --body-file`). Fill in every section.
113
+
110
114
## Common Pitfalls
111
115
112
116
-**Build in dependency order** — see the dependency graph above.
| Web API | Send data to or query data from Slack using any of [over 220 methods](https://docs.slack.dev/reference/methods). |[`@slack/web-api`](https://docs.slack.dev/tools/node-slack-sdk/web-api)|
24
+
| Web API | Send data to or query data from Slack using any of [over 270 methods](https://docs.slack.dev/reference/methods). |[`@slack/web-api`](https://docs.slack.dev/tools/node-slack-sdk/web-api)|
25
25
| OAuth | Set up the authentication flow using V2 OAuth for Slack apps as well as V1 OAuth for classic Slack apps. |[`@slack/oauth`](https://docs.slack.dev/tools/node-slack-sdk/oauth)|
26
26
| Incoming Webhooks | Send notifications to a single channel which the user picks on installation. |[`@slack/webhook`](https://docs.slack.dev/tools/node-slack-sdk/webhook)|
27
27
| Socket Mode | Listen for incoming messages and a limited set of events happening in Slack, using WebSocket. |[`@slack/socket-mode`](https://docs.slack.dev/tools/node-slack-sdk/socket-mode)|
@@ -51,11 +51,11 @@ package's documentation, linked in the table above.
51
51
52
52
Your app will interact with the Web API through the `WebClient` object, which is an export from `@slack/web-api`. You
53
53
typically instantiate a client with a token you received from Slack. The example below shows how to post a message into
54
-
a channel, DM, MPDM, or group. The `WebClient` object makes it simple to call any of the [**over 130 Web API
54
+
a channel, DM, MPDM, or group. The `WebClient` object makes it simple to call any of the [**over 270 Web API
Copy file name to clipboardExpand all lines: packages/oauth/README.md
+40-5Lines changed: 40 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ It may be helpful to read the tutorials on [getting started](https://docs.slack.
31
31
This package exposes an `InstallProvider` class, which sets up the required configuration and exposes methods such as `generateInstallUrl`, `handleCallback`, `authorize` for use within your apps. At a minimum, `InstallProvider` takes a `clientId` and `clientSecret` (both which can be obtained under the **Basic Information** of your app configuration). `InstallProvider` also requires a `stateSecret`, which is used to encode the generated state, and later used to decode that same state to verify it wasn't tampered with during the OAuth flow. **Note**: This example is not ready for production because it only stores installations (tokens) in memory. Please go to the [storing installations in a database](#storing-installations-in-a-database) section to learn how to plug in your own database.
After the user approves the request to install your app (and grants access to the required permissions), Slack will redirect the user to your specified **redirect url**. You can either set the redirect url in the app’s **OAuth and Permissions** page or pass a `redirectUri` when calling `installProvider.generateInstallUrl`. Your HTTP server should handle requests to the redirect URL by calling the `installProvider.handleCallback()` method. The first two arguments (`req`, `res`) to `installProvider.handleCallback` are required. By default, if the installation is successful the user will be redirected back to your App Home in Slack (or redirected back to the last open workspace in your slack app for classic Slack apps). If the installation is not successful the user will be shown an error page.
99
99
100
100
```javascript
101
-
const { createServer } =require('http');
101
+
import { createServer } from'node:http';
102
102
103
103
constserver=createServer((req, res) => {
104
104
// our redirect_uri is /slack/oauth_redirect
@@ -291,6 +291,41 @@ const installer = new InstallProvider({
291
291
```
292
292
---
293
293
294
+
### Handle errors
295
+
296
+
Methods on `InstallProvider` reject with an `Error` when something goes wrong. Each kind of error is its own class, all extending the `SlackOAuthError` base class, so you can use an `instanceof` check to decide how to respond. For example, `authorize()` throws an `AuthorizationError` when it can't fetch an installation.
Other error classes include `InstallerInitializationError`, `GenerateInstallUrlError`, `MissingStateError`, `InvalidStateError`, `MissingCodeError`, and `UnknownError`. They all extend `SlackOAuthError`, so an `instanceof SlackOAuthError` check catches any of them.
326
+
327
+
---
328
+
294
329
### Setting the log level and using a custom logger
295
330
296
331
The `InstallProvider` will log interesting information to the console by default. You can use the `logLevel` to decide how
@@ -300,7 +335,7 @@ in development, it's sometimes helpful to set this to the most verbose: `LogLeve
To respond to events and send messages back into Slack, we recommend using the `@slack/web-api` package with a [bot token](https://docs.slack.dev/authentication/tokens#bot).
// Attach listeners to events by type. See: https://docs.slack.dev/reference/events/message
@@ -144,13 +144,49 @@ The client also emits events that are part of its lifecycle, but aren't states.
144
144
145
145
---
146
146
147
+
### Handle errors
148
+
149
+
Because the client is an `EventEmitter`, errors are delivered to your `error` listener rather than thrown. Each kind of error is its own class, all extending the `SlackSocketModeError` base class, so you can use an `instanceof` check to decide how to respond.
// Tried to send a message while the client was disconnected.
170
+
console.log('Not connected, will retry...');
171
+
}
172
+
});
173
+
174
+
(async () => {
175
+
awaitclient.start();
176
+
})();
177
+
```
178
+
179
+
Other error classes you might encounter include `SMNoReplyReceivedError` (the server didn't acknowledge a sent message in time) and `SMSendWhileNotReadyError` (a message was sent before the client was fully ready). They all extend `SlackSocketModeError`, so an `instanceof SlackSocketModeError` check catches any of them.
180
+
181
+
---
182
+
147
183
### Logging
148
184
149
185
The `SocketModeClient` will log information to the console by default. You can use the `logLevel` to decide how much or what kind of information should be output. There are a few possible log levels, which you can find in the `LogLevel` export. By default, the value is set to `LogLevel.INFO`. While you're in development, it's sometimes helpful to set this to the most verbose: `LogLevel.DEBUG`.
There are a few more types of errors that you might encounter, each with one of these `code`s:
170
+
Other error classes you might encounter include the following, though this isn't a complete list. They all extend `SlackError`, so an `instanceof SlackError` check catches any error this package throws.
171
171
172
-
*`ErrorCode.RequestError`: A request could not be sent. A common reason for this is that your network connection is
173
-
not available, or `api.slack.com` could not be reached. This error has an `original` property with more details.
172
+
*`WebAPIRequestError`: A request could not be sent. A common reason for this is that your network connection is not available, or `api.slack.com` could not be reached. The underlying error is available on both the standard [`cause`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) property and the `original` property.
174
173
175
-
*`ErrorCode.RateLimitedError`: The Web API cannot fulfill the API method call because your app has made too many
176
-
requests too quickly. This error has a `retryAfter` property with the number of seconds you should wait before trying
177
-
again. See [the documentation on rate limit handling](https://docs.slack.dev/tools/node-slack-sdk/web-api/#rate-limits) to
178
-
understand how the client will automatically deal with these problems for you.
174
+
*`WebAPIRateLimitedError`: The Web API cannot fulfill the API method call because your app has made too many requests too quickly. This error has a `retryAfter` property with the number of seconds you should wait before trying again. See [the documentation on rate limit handling](https://docs.slack.dev/tools/node-slack-sdk/web-api/#rate-limits) to understand how the client will automatically deal with these problems for you.
175
+
176
+
*`WebAPIHTTPError`: The HTTP response contained an unfamiliar status code. The Web API only responds with `200` (yes, even for errors) or `429` (rate limiting). If you receive this error, it's likely due to a problem with a custom `fetch` implementation or a custom API URL. This error has the `statusCode`, `statusMessage`, `headers`, and `body` properties containing more details.
179
177
180
-
*`ErrorCode.HTTPError`: The HTTP response contained an unfamiliar status code. The Web API only responds with `200`
181
-
(yes, even for errors) or `429` (rate limiting). If you receive this error, it's likely due to a problem with a proxy,
182
-
a custom TLS configuration, or a custom API URL. This error has the `statusCode`, `statusMessage`, `headers`, and
183
-
`body` properties containing more details.
184
178
</details>
185
179
186
180
---
@@ -262,7 +256,7 @@ in development, it's sometimes helpful to set this to the most verbose: `LogLeve
0 commit comments