简体   繁体   中英

Slack API keeps telling me channel_not_found when attempting to upload an image

Like the title describes, i can't seem to figure out how to upload a local image and have it posted as a message in slack

Currently i am able to post text messages to slack without issue using the webhook url and axios post seen here:

const res = await axios.post(url, {
    text: 'Screenshot',
    channel: channelid

}, {
    headers: {
        authorization: `Bearer ${token}`
    }
});
    

Heres the part of the script that isnt working:

try {

    const result = await client.files.upload({

        channels: channelid,
        initial_comment: "this is the image",

        file: fs.createReadStream(fileName)
    });

    console.log(result);
} catch (error) {
    console.error(error);
}

I dont understand how the channelid works in one and not the other.

Calling a method with an xoxb or xoxp token is different than posting a message with a webhook. When you create the webhook on the Slack Developer settings site, you are asked to choose a channel. The webhook will be able to post into that channel without your app being a channel member. When using the xoxb token your bot needs to be a member of the channel that's being passed in the API call. If it's not a member you can expect a channel_not_found or not_in_channel error.

You should add the bot to the channel using

/invite @bot-name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM