How to add a Member to Channel with Discordgo - go

I want to implement a "Ticket" funktion in my discordgo Bot.
The channels for the tickets are created in a category that is only visible for team members. So, i want to add the User to the Channel but i dont find a solution for this.
My question is now: is there even a way to make this, or can i give up on this

Related

Slack `member_joined_channel` - how to check if my bot was invited?

I want to send a message to any public channel that my bot gets added to. I notice there's the member_joined_channel event as documentated here, however I'm not sure how to figure out when to determine if my bot was the invited member. I know there's the user property, but I don't want to hardcode my bot's user ID.
I'm not familiar with the slack API, but i found this endpoint :
https://api.slack.com/types/conversation
In the response, you have a flag is_member which contains what you need I think :
is_member indicates whether the user, bot user or Slack app associated
with the token making the API call is itself a member of the
conversation.
EDIT:
then, you can retreive the list of public channel and have this flag on every channel accessible :
https://api.slack.com/methods/conversations.list
If you are writing a WebSocket-based "RTM" bot, you can listen for the channel_joined event, which is sent only for your own user/bot.
For the more typical Webhook-based bot, the best choice is to listen for the member_joined_channel event and compare the user field if you want an event-based implementation. Hardcoding or otherwise storing your bot's user id is a necessity.
Otherwise, as suggested in the previous answer, you can periodically query all conversations with the conversations.list method and check if you have become a member using the is_member field.
In case one of these methods does not provide the is_private field that you need to determine whether a channel is public, you can use the conversations.info method, which returns a channel object with the is_private field.
Coversation info is your friend https://api.slack.com/methods/conversations.info

How to automatically add group members to slack channel that fits a certain REGEX

Whenever there is a channel with the name that matches a certain regex, we want to add a certain group of members to these channel automatically. For example, if a new slack channel with the name that matches the regex INC-.* is created, slack group #incidentmembers will be added to that new slack channel automatically
Is there a way to configure this in Slack?
There's no native way to do this in Slack, but you could build something using the public APIs. Specifically you would
Listen to the channel_created event which fires when a public channel is created, which you can then regex as you see fit.
Grab the membership of the relevant User Group using usergroups.users.list (if the membership is static you could probably skip this)
Use conversations.invite to add the users to the channel
One limitation of this approach is that you won't get channel_created events for private channels. There's no way around this I'm afraid.

Slack API Channel name to conversation id

I have an old slack app that relies on channel.join. I need to migrate conversations.join. The APIs have two different keys. Channels allows you to use the channel name, and conversations requires a conversation id. How do you convert them? conversations.list -> loop?
You will probably have to loop. The new API is very focused on IDs and the advice is to store the IDs of the channels you want to join not their names, because name can be changed at any time. It feels like they’re saying you can join by name if you want but we won’t make it easy for you :) It's probably good advice tbh.

Get list of channels a user is a member of

Writing a slack bot and I would like to be able to get a list of all the channels my bot is a member of. One way to do this is to call https://slack.com/api/channels.list, get a (potentially large) list of all channels and then search for the channels that the current (bot) user is a member of. This works fine, but seems very heavy handed.
Is there a better way? To get just the channels that a given user is a member of?
I think users.conversations is what you're looking for. Without additional params it will return all public channels the calling user is a member of.
No, there is no shorter way to get this information.
Actually, Slack recommends to use the new conversations methods for this task, since the members property in all other methods, e.g. channels.list has recently been changed to only return a truncated user list. See here for details.
With conversations you have to make an additional call per channel to get all channels a user is a member of. However it will work with all types of channels (e.g. public channels, private channels) at the same time.
The basic approach is:
Get the list of all conversations from conversations.list
Get the list of members per conversation form conversations.members.
So if you want your Slack app to be future proof and also work with large number of users better use the conversations methods for your task.
FYI you can now list user channels/conversations using:
https://api.slack.com/methods/users.conversations

Is that possible to nest a slack channel inside another slack channel?

Say, I have a channel named teamA, and also got a channel named subTeamB, and subTeamB is actually a sub-team of team A, e.g. all members in subTeamB included in teamA.
In this case, is that possible to have subTeamB nested inside teamA?
No, you can not have channels within a channel in Slack.
As a workaround you could name the channels in a way that they reflect sub-channels.
Examples:
#teamA-subTeamA
#teamA-subTeamB
This is also what Slack recommends on its documentation page about Organizing and naming channels.
They did say they were working on it, or something to better organize:
https://twitter.com/slackhq/status/503652089755873280
Makes sense. We're exploring better ways to organize / group large
amounts of channels. Stay tuned! ✨— Slack (#SlackHQ) January
9, 2016

Resources