I have set up a slack app to allow me to send notifications from my code to a private slack channel.
I have invited the bot to the channel, and when I run the app from the command line, all is good.
However, when I try and run it from a docker container, I get channel not found. If I try and use exactly the same code, and send a message to a bot in a public channel, no issues all is good.
Both bots have permissions, chat:write and chat:write.public
Why would this only be working on some machines and not others?
I know this probably doesn't have enough detail, but I'm not sure what is needed to help diagnose this.
More information:
Thanks to #Suyash Gaur I didn't know about the groups scope. I've now added groups:write and groups:history to the app, but am still getting the same error from the docker version of the app.
The membership of the channel I'm trying to write too shows
cwpr_notifications on Aug 3, 2021
Can post messages to specific channels in slack, send messages as #cwprnotifications, send messages to channels #cwprnotifications isn't a member of, manage private channels that cwpr_notifications has been added to and create new ones, and view messages and other content in private channels that cwpr_notifications has been added to.
I am using a bottoken and channel ID to send the message. Do I need something else for a private channel.
When I first used the bot from the command line run, I had to invite the app to the channel to get it to work, but surely I only need to do that once?
I've confirmed that the environment variables are getting passed in correctly.
With limited set of information provided, I can only say that:
If the public channel is accessible and private channel is not,
It seems like an issue of scopes.
For public channels, scopes start with channels:*
For private channels, scopes start with groups:*
Can you look into the app's configuration and confirm the permissions are configured correctly?
Related
I am trying to create a link to a public channel in a post message to slack programmatically.
Following the documentation, I am posting a slack message containing <#C...> with a valid public channel within my slack workspace. However, the display shows only Private channel info, instead of the actual channel.
Are there additional permissions or setup required?
Got it to work with using <#{normalized_channel_name}>
I am making a private dm bot. I am trying to make the bot make a text channel when the bot joins the server called "private-dm" with the properties of "#everyone: read past messages = False" So it is private and when the bot doesn't see already see a channel names private-dm just in case the bot goes offline. I couldn't find any on_bot_join event in the docs and I also couldn't find anything to make a text channel when it has not detected any with the given name.
on_bot_join is known as on_guild_join.
For the second issue you can just loop over all existing channels using Guild.text_channels & check if any of them has that name. If not, make it.
Is there a way to keep my Slack App from being used in Channels?
I only want the current user to be able to interact with the App directly and it not to show in any channels.
When setting up a app in MS Teams using App Studio there is a option that lets you limit the App to "Personal" I'm looking for something similar in Slack.
I am not sure what use cases you want to prohibit exactly, but in general your app can check each incoming request and decide if and how it wants to react to it.
For example you will always get the user ID of who sent the slash command or message to the bot. You can use that to filter our users that should not have access.
Update
To restrict your app the the app channel you need to do the following:
When receiving a request from the user, first open a direct message channel to the user from the bot user. That will always give you the channel ID of the app channel.
Then reply with a direct message in that app channel
or alternatively check if the received request is from the app channel and ask the user to only talk in app channel if it is not.
See also this answer on how this works in detail.
I have created a bot with a slash command that works, but it only responds to the channel in which the first Incoming Webhook was created. I would like it to respond in whatever channel (public or private) in which it was invoked.
I've tried creating a webhook for each channel and reinstalling the bot in my workspace, but it still reverts to the first channel.
I can see how I could hard code a webhook -> channel mapping in my code (php on my webserver) but that seems like a lot of very specific coding, and how would I ever release the bot to another workspace? I'm sure I'm missing something basic, but I can't work it out.
How do I deploy my bot so that it will respond to a slash command in whichever public or private channel it was invoked?
Fixed it. The example I was following had the webhook URL hard coded in the script. I just realised, upon re-reading the docs, that the actual webhook is passed in the POST data as response_url. Now it's all working fine. RTFM next time
I have no idea how to do it using EventsAPI from Slack.
So, our bot does this:
Creates public channel #test
Invites the bot to the channel using user token
From now on, we are using bot token to post messages on the channel
The problem happens when someone converts public channel to private. The ID of the channel changes and the bot gets error channel_not_found.
Do you have an idea how to track this change and update ID on our system automatically? Bot is still the member of the channel!
I found a way and it was also confirmed by Slack Help team.
Basically when channel is converted to private, you get these events:
channel_deleted with id of your public channel
member_joined_channel with id of new private channel and bot_id
When you get member_joined_channel, retrieve from Slack the name of new channel and if it matches your previous public channel then you know it is the same one but private now.
Slack does not allow to create channels with the same name so this is the indicator.
I just tested it with production app and it works! :)
I don't think that is currently possible.
Naturally, you would expect a specific Slack event for that case to fire, when a channel is converted, but there does not appear to be one. If you need this I would suggest to write a request they add an event for it.
One thing you can do is restricted who can create private channels in your Slack workplace to limit the risk of unintended use.
However, you can prevent this error from occurring by checking which public and private channels exist with conversations.list, and which channels you bot is a member with conversations.member.