> For the complete documentation index, see [llms.txt](https://docs.pandium.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pandium.com/getting-started/pandium-integration-tutorial/pokemon-of-the-day-part-1/write-the-integration-in-typescript/add-the-slack-client.md).

# Add the Slack Client

Now you will import the Slack client from the library @slack/web-api and confirm you can use it to fetch information from Slack.

A Slack client will let us post our daily messages, so let's get our code talking to Slack.

1. Run `npm install @slack/web-api`.

These [docs for this library](https://www.npmjs.com/package/@slack/web-api) show how to create an instance of a Slack client.

2. In `src/index.ts` do the following:
   * [ ] Import the `WebClient` from the Slack library.
   * [ ] Access the Slack token from the secrets object.
   * [ ] Use that token to create an instance of the Slack client. Do this within the `run` function so that your code will be able to use it when it runs.

These [Slack web API docs](https://api.slack.com/methods/users.list) describe the `users.list` endpoint. That will be helpful because you'll need some information about the users in the Pokémon Trainer Academy's Slack workspace in order to send them messages.

3. Use your instance of the Slack client to fetch a list of users in the workspace that your Slack token has access to.

At this point your src/index.ts should look like this:

```typescript
import * as dotenv from 'dotenv'
dotenv.config()
import { WebClient } from '@slack/web-api'
import Pokedex from 'pokedex-promise-v2'
import { Config, Secret, Context } from './lib.js'

const run = async () => {
    const context = new Context()
    const secrets = new Secret()
    const config = new Config()

    console.error(`This run is in mode: ${context['run_mode']}`)
    console.error('------------------------CONFIG------------------------')
    console.error(config)

    console.error('------------------------CONTEXT------------------------')
    console.error(context)

    const pokeClient = new Pokedex()
    const slackClient = new WebClient(secrets.slack_oauth_access_token)

    const { members } = await slackClient.users.list()
    console.error(members)
}

run().then(
    () => {},
    () => {
        process.exitCode = 1
    }
)
```

4. Run `npm run build && npm run start`.

You should see something like this logged - except that the printed array should be filled with users from your Slack workspace.

```
> pokemon-of-the-day@1.0.0 start
> node build/src/

This run is in mode: normal
------------------------CONFIG------------------------
Config {}
------------------------CONTEXT------------------------
Context { run_mode: 'normal' }
[
  {
    id: 'USLACKBOT',
    team_id: 'TCF1SSXMJ',
    name: 'slackbot',
    deleted: false,
    color: '757575',
    real_name: 'Slackbot',
    tz: 'America/Los_Angeles',
    tz_label: 'Pacific Standard Time',
    tz_offset: -28800,
    profile: {
      title: '',
      phone: '',
      skype: '',
      real_name: 'Slackbot',
      real_name_normalized: 'Slackbot',
      display_name: 'Slackbot',
      display_name_normalized: 'Slackbot',
      fields: {},
      status_text: '',
      status_emoji: '',
      status_emoji_display_info: [],
      status_expiration: 0,
      avatar_hash: 'sv41d8cd98f0',
      always_active: true,
      first_name: 'slackbot',
      last_name: '',
      image_24: 'https://a.slack-edge.com/80588/img/slackbot_24.png',
      image_32: 'https://a.slack-edge.com/80588/img/slackbot_32.png',
      image_48: 'https://a.slack-edge.com/80588/img/slackbot_48.png',
      image_72: 'https://a.slack-edge.com/80588/img/slackbot_72.png',
      image_192: 'https://a.slack-edge.com/80588/marketing/img/avatars/slackbot/avatar-slackbot.png',
      image_512: 'https://a.slack-edge.com/80588/img/slackbot_512.png',
      status_text_canonical: '',
      team: 'TCF1SSXMJ'
    },
    is_admin: false,
    is_owner: false,
    is_primary_owner: false,
    is_restricted: false,
    is_ultra_restricted: false,
    is_bot: false,
    is_app_user: false,
    updated: 0,
    is_email_confirmed: false,
    who_can_share_contact_card: 'EVERYONE'
  },
  ...
  ]
```

Review documentation about the Slack Web API to develop a strategy for sending the Pokémon of the Day Slack messages. For example, you'll need to use [the postMessage endpoint](https://api.slack.com/methods/chat.postMessage), and the docs say "If you want your app's bot user to start a 1:1 conversation with another user in a workspace, provide the user's user ID as the `channel` value"

That means you'll need the Slack member IDs of the Pokémon trainers who the Academy said should receive the daily messages. Consult the list of Slack members which was logged in the last run, and take note of those ID's (if you don't happen to see any Pokémon trainers you should at least be able to find yourself and note your own ID 😉)

Now that you know the Slack client works, so you can remove the logic for fetching and logging out the Slack users from src/index.ts.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.pandium.com/getting-started/pandium-integration-tutorial/pokemon-of-the-day-part-1/write-the-integration-in-typescript/add-the-slack-client.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
