Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove workspace app references from docs #668

Merged
merged 2 commits into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions docs/_pages/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ This guide introduces fundamentals of the Slack Developer Kit for Node.js and Sl
## Create a Slack app

The first step is to [register a new app](https://api.slack.com/apps/new) with Slack at the API
website. You have the option to build a user-token app or a workspace app. 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 workspace for free.

> ⚠️ For this guide, we'll assume you're building a [workspace app](https://api.slack.com/workspace-apps-preview). Workspace apps support Slack's latest and greatest platform features. However, most steps are the same for user-token apps.
website. 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 workspace for free.

After you create an app, you'll be greeted with some basic information. In this guide we'll be making a request to the Web API to post a message to a channel. Aside from posting messages, the Web API allows your app to call [methods](https://api.slack.com/methods) that can be used for everything from creating a channel to searching messages. Let's configure our new app with proper permissions.

Expand All @@ -31,13 +29,13 @@ various permissions your app could obtain from a user as **scopes**. There are a
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, 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 called `chat:write` (or `chat:write:user` for user-token apps). Use the dropdown or start typing its name to select and add the scope, then click "Save Changes".
Web API to post a message. The scope required for this is called `chat:write:user`. Use the dropdown or start typing its name to select and add the scope, then click "Save Changes".

Our app has described which scope it desires in the workspace, but a user hasn't authorized those scopes for the development workspace yet. Scroll up and click "Install App". You'll be taken to your app installation page. This page is asking you for permission to install the app in your development workspace with specific capabilities. That's right, the development workspace is like every other workspace -- apps must be authorized by a user each time it asks for more permissions.

Go ahead and click "Continue". The next page asks you which conversations the app should be able to post messages in. In this case, choose "No channels", which still allows the app to directly message users who install the App -- which means you.

When you return to the OAuth & Permissions page copy the OAuth Access Token (it should begin with `xoxa`). Treat this value like a password and keep it safe. The Web API uses tokens to to authenticate the requests your app makes. In a later step, you'll be asked to use this token in your code.
When you return to the OAuth & Permissions page copy the OAuth Access Token (it should begin with `xoxp`). Treat this value like a password and keep it safe. The Web API uses tokens to to authenticate the requests your app makes. In a later step, you'll be asked to use this token in your code.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amended fix for
(it should begin with p)
to
(it should begin with xoxp)


## Set up your local project

Expand Down Expand Up @@ -85,7 +83,7 @@ but [similar commands are available on Windows](https://superuser.com/a/212153/9
value with OAuth Access Token that you copied above.

```shell
$ export SLACK_ACCESS_TOKEN=xoxa-...
$ export SLACK_ACCESS_TOKEN=xoxp-...
```

Create a file called `tutorial.js` and add the following code:
Expand Down
176 changes: 91 additions & 85 deletions docs/_pages/web_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ how to post a message into a channel, DM, MPDM, or group. This will require the
```javascript
const { WebClient } = require('@slack/client');

// An access token (from your Slack app or custom integration - xoxa, xoxp, or xoxb)
// An access token (from your Slack app or custom integration - xoxp, xoxb)
const token = process.env.SLACK_TOKEN;

const web = new WebClient(token);
Expand Down Expand Up @@ -123,7 +123,7 @@ scope.
const fs = require('fs');
const { WebClient } = require('@slack/client');

// An access token (from your Slack app or custom integration - xoxa, xoxp, or xoxb)
// An access token (from your Slack app or custom integration - xoxp, xoxb, or the deprecated xoxa)
const token = process.env.SLACK_TOKEN;

const web = new WebClient(token);
Expand Down Expand Up @@ -151,89 +151,10 @@ web.files.upload({

---

### Getting a list of channels

The `conversations.list` method can be used to get a list of all channels in a Slack team.
This [Conversations API](https://api.slack.com/docs/conversations-api) method returns a list of all [channel-like conversations](https://api.slack.com/types/conversation) in a workspace. The "channels" returned depend on what the calling token has access to and the directives placed in the `types` parameter. See the [conversations.list](https://api.slack.com/methods/conversations.list) documentation for details.

```javascript
const { WebClient } = require('@slack/client');

// An access token (from your Slack app or custom integration - xoxa, xoxp, or xoxb)
const token = process.env.SLACK_TOKEN;

const web = new WebClient(token);

function getAllChannels() {
// See: https://api.slack.com/methods/conversations.list#arguments
const param = {
exclude_archived: true,
types: 'public_channel',
// Only get first 100 items
limit: 100
};
return web.conversations.list(param).then(results => { return results.channels });
}

getAllChannels()
.then(console.log) // prints out the list of channels
.catch(console.error);
```

**NOTE**: The example above can only get a specific number of items (by `limit` arguments). See the [Pagination](#pagination) section for the detailed description as to how you can handle pagination in API methods so that you can get full items even if you don't know how many items are there.

---

### Calling methods on behalf of users

When using [workspace tokens](https://api.slack.com/docs/working-with-workspace-tokens), some methods allow your app
to perform the action [on behalf of a user](https://api.slack.com/docs/working-for-users). To use one of these methods,
your app will provide the user's ID as an option named `on_behalf_of`.

```javascript
const { WebClient } = require('@slack/client');

// An access token (from your Slack workspace app - xoxa)
const token = process.env.SLACK_TOKEN;

// A user ID - this may be found in events or requests such as slash commands, interactive messages, actions, or dialogs
const userId = 'U0123456';

const web = new WebClient(token);

// https://api.slack.com/methods/users.identity
web.users.identity({ on_behalf_of: userId })
.then((res) => {
// `res` contains information about the user. the specific structure depends on the scopes your app was allowed.
console.log(res);
})
.catch(console.error);
```

---

### Using a callback instead of a Promise

Every web API method can also be called with a callback function that takes `cb(error, response)`.
If you prefer callbacks over promises, here is the example above translated for callbacks:

```javascript
web.channels.list({}, (err, res) => {
if (err) {
return console.error(err);
}

// `res` contains information about the channels
res.channels.forEach(c => console.log(c.name));
});

```

Note that when calling a method with no required arguments, you **still need to provide an empty options object**.

---

### Using refresh tokens
> WARNING: This feature is only supported for the now-deprecated workspace app tokens (xoxa). Refresh
> tokens will be available in the future to classic Slack apps in a couple of months. You may find more
> details [on the related blog post.](https://medium.com/slack-developer-blog/an-update-on-workspace-apps-aabc9e42a98b).

If you're using workspace apps, refresh tokens can be used to obtain short-lived access tokens that power your Web API calls from the `WebClient` (this is *required* for distributed apps). This can increase the security of your app since, in the event of a token being exposed accidentally, it won't be able to be used against your app or users after a short time. To enable the `WebClient` to automatically refresh and swap your access tokens, you need to pass your app's refresh token, client ID, and client secret in the `WebClientOptions`.

Expand Down Expand Up @@ -326,6 +247,9 @@ web.on('token_refreshed', (event) => {
---

### Manually handling token rotation
> WARNING: This feature is only supported for the now-deprecated workspace app tokens (xoxa). Token
> rotation will be available in the future to classic Slack apps in a couple of months. You may find more
> details [on the related blog post.](https://medium.com/slack-developer-blog/an-update-on-workspace-apps-aabc9e42a98b).

Note: Before implementing it on your own, it's suggested you read through the [token rotation documentation](http://api.slack.com/docs/rotating-and-refreshing-credentials).

Expand Down Expand Up @@ -391,6 +315,88 @@ sendMessage({ channel: conversationId, text: 'Hello world!' })

---

### Getting a list of channels

The `conversations.list` method can be used to get a list of all channels in a Slack team.
This [Conversations API](https://api.slack.com/docs/conversations-api) method returns a list of all [channel-like conversations](https://api.slack.com/types/conversation) in a workspace. The "channels" returned depend on what the calling token has access to and the directives placed in the `types` parameter. See the [conversations.list](https://api.slack.com/methods/conversations.list) documentation for details.

```javascript
const { WebClient } = require('@slack/client');

// An access token (from your Slack app or custom integration - xoxp, or xoxb)
const token = process.env.SLACK_TOKEN;

const web = new WebClient(token);

function getAllChannels() {
// See: https://api.slack.com/methods/conversations.list#arguments
const param = {
exclude_archived: true,
types: 'public_channel',
// Only get first 100 items
limit: 100
};
return web.conversations.list(param).then(results => { return results.channels });
}

getAllChannels()
.then(console.log) // prints out the list of channels
.catch(console.error);
```

**NOTE**: The example above can only get a specific number of items (by `limit` arguments). See the [Pagination](#pagination) section for the detailed description as to how you can handle pagination in API methods so that you can get full items even if you don't know how many items are there.

---

### Calling methods on behalf of users

When using [user tokens](https://api.slack.com/docs/token-types#user), some methods allow your app
to perform the action _on behalf of a user_. To use one of these methods,
your app will provide the user's ID as an option named `on_behalf_of`.

```javascript
const { WebClient } = require('@slack/client');

// An access token (from your Slack app - xoxp)
const token = process.env.SLACK_TOKEN;

// A user ID - this may be found in events or requests such as slash commands, interactive messages, actions, or dialogs
const userId = 'U0123456';

const web = new WebClient(token);

// https://api.slack.com/methods/users.identity
web.users.identity({ on_behalf_of: userId })
.then((res) => {
// `res` contains information about the user. the specific structure depends on the scopes your app was allowed.
console.log(res);
})
.catch(console.error);
```

---

### Using a callback instead of a Promise

Every web API method can also be called with a callback function that takes `cb(error, response)`.
If you prefer callbacks over promises, here is the example above translated for callbacks:

```javascript
web.channels.list({}, (err, res) => {
if (err) {
return console.error(err);
}

// `res` contains information about the channels
res.channels.forEach(c => console.log(c.name));
});

```

Note that when calling a method with no required arguments, you **still need to provide an empty options object**.

---

### Changing the retry configuration

The `WebClient` will retry any request that fails for a recoverable error. The policy is
Expand Down Expand Up @@ -515,7 +521,7 @@ illustrating below.
```javascript
const { WebClient } = require('@slack/client');

// An access token (from your Slack app or custom integration - xoxa, xoxp, or xoxb)
// An access token (from your Slack app or custom integration - xoxp, or xoxb)
const token = process.env.SLACK_TOKEN;

const web = new WebClient(token);
Expand Down
4 changes: 2 additions & 2 deletions docs/_reference/WebClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ a convenience wrapper for calling the [WebClient#apiCall](WebClient#apiCall) met

| Name | Type | Description |
| --- | --- | --- |
| token | <code>string</code> \| <code>undefined</code> | Authentication and authorization token for accessing Slack Web API (usually begins with `xoxa`, xoxp`, or `xoxb`) |
| [refreshToken] | <code>string</code> | OAuth 2.0 refresh token used to automatically create new access tokens (`token`) when the current is expired. |
| token | <code>string</code> \| <code>undefined</code> | Authentication and authorization token for accessing Slack Web API (usually begins with `xoxp` or `xoxb`) |
| [refreshToken] | <code>string</code> | OAuth 2.0 refresh token used to automatically create new access tokens (`token`) when the current is expired. __Warning: This is only available to the legacy workspace apps.__ |
| [clientId] | <code>string</code> | OAuth 2.0 client identifier |
| [clientSecret] | <code>string</code> | OAuth 2.0 client secret |
| [slackApiUrl] | <code>string</code> | The base URL for reaching Slack's Web API. Consider changing this value for testing purposes. |
Expand Down