1

I am very new to slack api integration using node js. I am trying to get channels history. Even I tried with chat.postMessage. But it threw me the following error every time:

{ Error: An API error occurred: channel_not_found
at platformErrorFromResult (..\node_modules\@slack\client\dist\WebClient.js:747:42)
    at __await.makeRequest.then (..\node_modules\@slack\client\dist\WebClient.js:464:39)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)   
code: 'slackclient_platform_error',   
data:    
{ ok: false,
     error: 'channel_not_found',
     scopes:
      [ 'identify',
        'bot',
        'commands',
        'channels:history',
        'chat:write:user',
        'chat:write:bot' ],
     acceptedScopes: [ 'channels:history' ]*** } }

Here is my code snippet,

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

    const token = "OAuth Access Token"; // passing OAuth Access Token
    const web = new WebClient(token);

    web.channels.history({ channel: appID})
        .then((res) => {
            console.log('Message sent: ', res.ts);
        })
        .catch(console.error);

Could someone please help me what i am missing here?

  1. When should i use "Bot User OAuth Access Token" and "OAuth Access Token"?
  2. What is channel ID?
  3. Is APP ID called as channel ID?

Thanks in advance

Saan
  • 11
  • 1
  • 5

1 Answers1

5

Bot token vs. user token

In general you are acting on behalf of your bot user with the bot token and on behalf of the user who installed your Slack app with the user token.

So e.g. you can only access a private channel with your bot token if your bot user is a member of that private channel. Accordingly the user token gives you access to all private channel that the user is a member of.

In addition there are some API methods that do not work with a bot token and therefore require you to use a user token. (Check the documentation for each API method to find out which you need). In general I would recommend to stick with the bot token whenever possible.

Channel ID

The channel ID is the ID of a channel and unique for your workspace. In general all objects in a Slack workspace (e.g. users, channels, files, apps, messages) have each their own ID and most API methods require you to use that ID if you want to access an object.

To get the ID of an object you can use the corresponding list API methods, which exist for most objects. e.g. for channels call channels.list and go through the list to find the ID for the channel you are looking for (e.g. by comparing the channel name).

Pro tip: You can call most API methods directly from your browser, which can be very handy if you just want to find out an ID quickly. e.g. https://slack.com/api/channels.list?token=TOKEN to get the list of channels.

App ID vs. Channel ID

No. The app ID and channel ID are different IDs and have nothing to do with each other. See section above for details on how to get the channel ID.

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114