Search code examples
slackslack-api

Posting to Slack channels with bot access token


I have visited https://api.slack.com/apps/APP_ID/oauth and updated the scopes to include files:write:user, clicked Save Changes and reinstalled my app to ensure the scope changes take effect.

I do the following to post to a channel that my bot is a member of:

web.files
  .upload({
    filename,
    file: fs.createReadStream(filename),
    channels: ['{CHANNEL_ID}']
  })

However, I still get the following error message:

{ ok: false,
  error: 'invalid_channel',
  channel: '["{CHANNEL_ID}"]',
  scopes: [ 'identify', 'bot:basic' ],
  acceptedScopes: [ 'files:write:user', 'post' ] } }

What am I doing wrong?


Solution

  • My mistake was that I was using an array of channel IDs, rather than what the library expects which is a string containing a:

    Comma-separated list of channel names or IDs