最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Slack API keeps telling me channel_not_found when attempting to upload an image - Stack Overflow

programmeradmin0浏览0评论

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_ment: "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.

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_ment: "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.

Share Improve this question edited Jun 23, 2022 at 20:49 Christopher Schneider 3,9152 gold badges26 silver badges39 bronze badges asked Jun 23, 2022 at 20:23 mmTestpertmmTestpert 131 silver badge3 bronze badges 1
  • What isn't working? Is there an error? – Christopher Schneider Commented Jun 23, 2022 at 20:50
Add a ment  | 

3 Answers 3

Reset to default 6

You should add the bot to the channel using

/invite @bot-name

This could happen due to multiple reasons,

  • Slack bot is not integrated to respective channel
  • Slack bot is not invited to respective channel
  • You are incorrectly using Channel Name to upload file instead of Channel ID

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.

发布评论

评论列表(0)

  1. 暂无评论