channel_not_found exception while sending the message through incoming webhook

23,067

Solution 1

Assuming you mean by "someone else channel ID" the ID of a private channel that someone else is a member of (but you are not) this is normal Slack behavior.

You can not send a message to a private channel that you (as the user that created the incoming webhook) are not a member of. In fact all private channels that you are not a member of are invisible to you and that behavior is the same for incoming webhook and the Slack API.

A workarounds around this feature that I have used is to create the incoming webhook with a special admin user (e.g. "Slack Admin") and make sure he is invited into all relevant private channels

Solution 2

If you are using new Slack Bot Token Scopes, make sure that you are also using the Bot User OAuth Access Token and not the legacy user-based OAuth Access Token. The OAuth Access Token will not fail immediately, but will always be restricted by the rights of the user who requested the app installation.

This results in IMs between the bot user and other workspace users not being visible, as Erik described.

Solution 3

I ran into this same issue and had to specify the header types. After setting the bot to have access to the channel as a user, I needed to bake the Content-Type to JSON (a tad frustrating because request's default header is JSON).

const sendAPIresp = (obj) => {
    var options = {
        method: 'POST',
        url: 'https://slack.com/api/chat.postMessage',
        headers:
        {
            Authorization: 'Bearer NOMNOMNOM',
            'Content-Type': 'application/json'
        },
        body:
        {
            channel: 'THECOOLKIDSCLUB',
            text: 'Hello from the world',
        },
        json: true
    };

    request(options, function (error, response, body) {
        if (error) throw new Error(error);

        console.log(body);
    });
}
Share:
23,067

Related videos on Youtube

prabhakar Reddy G
Author by

prabhakar Reddy G

Updated on July 09, 2022

Comments

  • prabhakar Reddy G
    prabhakar Reddy G almost 2 years

    Am using incoming webhooks to send messages, however am overiding the channelID to send to particular channel(as mentioned in here:https://api.slack.com/incoming-webhooks) by using something like this

       {
    "channel": "#my_channel",
    "text": "This message will appear in #other-channel"
      } 
    

    Am able to receive messages into slack when i give my channelID, but when i give someone else channelID(valid channel ID), am getting channel_not_found exception.

    Please let me know what might went wrong.

  • prabhakar Reddy G
    prabhakar Reddy G over 7 years
    Oh got it!!!.......But can you bit elaborate on the workaround you mentioned above please!!! I have to solve this issue ASAP

Related