admin管理员组文章数量:1310662
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
3 Answers
Reset to default 6You 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.
版权声明:本文标题:javascript - Slack API keeps telling me channel_not_found when attempting to upload an image - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741868803a2402068.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论