Sydney C.
Sydney C.

Reputation: 978

Channel_not_found: authed_user cannot post a message to a channel via Slack API

I'm trying to post a message on a channel a user belongs via the Slack Api as an authed_user.

here is the flow:

  1. User gives permissions with scopes 'chat:write,channels:write,channels:history'
  2. I receive a token along with some more information from Slack that looks like xoxp-122474-a bunch of numbers
  3. I create a Slack Client with the token and sends a request with:
 const { WebClient } = require('@slack/web-api');

 const client = new WebClient(token.access_token);

 await client.chat.postMessage({
      channel: channelId, // = Something similar to C02E2K5CCUZ
      as_user: true,
      text: "here is some text",
    });

I get an error from the slack API, 'channel_not_found' but I checked the channel does exists + the user is in the channel.

What should I do to make this work? Am I missing anything?

Thank you !

Upvotes: 0

Views: 425

Answers (1)

sandra
sandra

Reputation: 1566

It's possible that error is a red herring. The as_user parameter might be messing you up. That parameter can only be used for legacy apps. You can still use chat.postMessage but make sure you are also requesting the [chat:write.customize][1] scope. You will then be able to customize the posting user by defining the username and icon_urlparameters in your API call.

Upvotes: 1

Related Questions