Open eBitzu opened 6 years ago
Looking at https://api.slack.com/methods/chat.postMessage Seems that postMessage works fine posting on private channels... I've tested right now using postMessage() instead of postMessageToChannel() and it worked ;)
I think this issue is related: https://github.com/18F/standup-slack-bot/issues/82 the TL;DR is that slack does not make private channel's existence public, you need to be summoned in the channel to know it exists.
This is still broken and it's almost 2019. Even if my bot is invited manually to the private channel, it cannot find the private channel when using the https://slack.com/api/chat.postMessage
endpoint. I'm using the OAuth Access Token for the authorization header.
Another thing that makes no sense... who in the world thought it was a good idea to return a 200 status code when the API doesn't send the message and literally returns this in the response data:
{
"ok": false,
"error": "channel_not_found",
"warning": "missing_charset",
"response_metadata": {
"warnings": [
"missing_charset"
]
}
}
Ever heard of a 406 error code? 500?
Straight from the documentation (https://api.slack.com/methods/chat.postMessage) This method posts a message to a public channel, private channel, or direct message/IM channel.
???
For whatever reason, the endpoint only works when the creator of the App is in the channel. How is it even making that connection??
@devlemire this is happening because you are doing this:
I'm using the OAuth Access Token for the authorization header.
OAuth Access Token represents the user who authorized the app, to send messages as the app (bot) you need to use Bot token. This way you should be able to post messages to any channel in which bot exist.
This still does not work even when you use the correct Bot token. Ive switched to https://github.com/xBytez/slackbotapi
I don't think it's about the client library @kilabyte, but I am curious if you have any details, happy to be wrong, but official slack api can be tested manually, without any library. We faced this issue in production and got same exact error described for same exact endpoint.
was facing the issue issue (not able to get the private channel names and id). Got around it by using .getGroups() api
This issue is still existing. when i use postMessage using my user token, it works for both private and public. Using the bot token, it works only for private. Worse still, I added the bot explicitly via install app and then using the mention. It showed that the app wasnt installed. HAs anyone found a fix/work around yet??
This issue is still existing. when i use postMessage using my user token, it works for both private and public. Using the bot token, it works only for private. Worse still, I added the bot explicitly via install app and then using the mention. It showed that the app wasnt installed. HAs anyone found a fix/work around yet??
I did find an approach which worked for me. First of all, I had to add my bot user as an App to the private chat. You can do so by clicking on the channel gear icon next to the search bar and select 'Add App'. Also, my bot has groups:write
permission.
bot.getGroupId('yourGroupName').then(id=>{
console.log('id',id)
bot.postMessage(id, 'cool beans')
})
This worked for me.
@lewkoo I am facing the same issue, I granted that permission to my bot but when I add the bot to a direct message channel I see the error that the can’t be added to the conversation. Am I missing another permission? I was able to successfully add my bot to a public channel though.
@lewkoo I am facing the same issue, I granted that permission to my bot but when I add the bot to a direct message channel I see the error that the can’t be added to the conversation. Am I missing another permission? I was able to successfully add my bot to a public channel though.
@minostro I can not be certain whether your are missing a permission or not, especially since Slack have recently changed their permission structure entirely (see here and here). If I were you and just starting with this, I would upgrade right now since the "old-style" will be deprecated sometime in the future.
Also, I would double check your parameters for postMessage
call. Particularly pay attention to the as_user
parameter. More on that here, section Post to an IM channel
.
@lewkoo yeah, I checked that but I am facing the same issue. The bot cannot post in direct message channels. I keep getting channel_not_found
. I tried adding the bot to the direct message channel and slack says that an error happened when executing that operation. I am using the new slack app by the way, and I am using a slash command so users can interact with my bot.
How I fix this issue:
I removed all the incoming weedhook and all the rights. After I added all the write permission and I reinstall the app (see the screenshot bellow). Another information:
Now it works and I can send files and messages into my private channel. I hope it can help some of you!
@skududufru thanks for sharing this! Unfortunately, this does not fix the issue I am having :( with direct messages. So the thing that I want to accomplish is the following:
DF8GVP9TJ
DF8GVP9TJ
I was able to implement point 3 without any issues. The problem comes with point 4. My slack app does not have the rights to post into this direct message channel when using the bot token. It's successful though when using the user token (but I don't want to use that). The permissions granted to my slack app is as follows:
When I installed the app adding the incoming-webhook
scope, slack asked me what channel the bot should be able to post to, but I want my bot to be able to post to any direct message my slash command has been used.
the bot was invited to the private channel before reinstal it;
yes! I saw that too, but I still cannot post a message by using the bot token =(
I use the channel name, not the ID.
ah ha! I am still using the id of the channel (DF8GVP9TJ
), what would be the channel name in your case? the name of one of the person in the direct message?
ah ha! I am still using the id of the channel (DF8GVP9TJ), what would be the channel name in your case? the name of one of the person in the direct message? Good question, I didn't try that! Maybe for your case, you need to keep the id.
I saw a lot of people facing this issue. I don't think I can help you anymore :/ For my case it was "why it doesn't work" and after "why now it works"?
I remember I remove all the incooming webhook before to reinstal.
I've implemented a slackbot but it seems he can't find private channels even though the bot (app) is on the channel.