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.
Webhooks can send messages to a text channel without having to log in as a bot. They can also fetch, edit, and delete their own messages.
Incoming Webhooks are a simple way to post messages from apps into Slack. Creating an Incoming Webhook gives you a unique URL to which you send a JSON payload with the message text and some options. You can use all the usual formatting and layout blocks with Incoming Webhooks to make the messages stand out.
An Incoming Webhook lets external applications to share content in Microsoft Teams channels. The webhooks are used as tools to track and notify. The webhooks provide a unique URL, to send a JSON payload with a message in card format.
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
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.
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);
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With