Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(slack): adds ability to remove users from channel #5835

Merged
merged 3 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/dispatch/plugins/dispatch_slack/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class SlackAPIPostEndpoints(DispatchEnum):
conversations_archive = "conversations.archive"
conversations_create = "conversations.create"
conversations_invite = "conversations.invite"
conversations_kick = "conversations.kick"
conversations_rename = "conversations.rename"
conversations_set_topic = "conversations.setTopic"
conversations_set_purpose = "conversations.setPurpose"
Expand Down
10 changes: 10 additions & 0 deletions src/dispatch/plugins/dispatch_slack/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
get_user_info_by_id,
get_user_profile_by_email,
is_user,
remove_member_from_channel,
rename_conversation,
resolve_user,
send_ephemeral_message,
Expand Down Expand Up @@ -388,6 +389,15 @@ def set_description(self, conversation_id: str, description: str):
client = create_slack_client(self.configuration)
return set_conversation_description(client, conversation_id, description)

def remove_user(self, conversation_id: str, user_email: str):
"""Removes a user from a conversation."""
client = create_slack_client(self.configuration)
user_id = resolve_user(client, user_email).get("id")
if user_id:
return remove_member_from_channel(
client=client, conversation_id=conversation_id, user_id=user_id
)

def add_bookmark(self, conversation_id: str, weblink: str, title: str):
"""Adds a bookmark to the conversation."""
client = create_slack_client(self.configuration)
Expand Down
7 changes: 7 additions & 0 deletions src/dispatch/plugins/dispatch_slack/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,13 @@ def add_conversation_bookmark(
)


def remove_member_from_channel(client: WebClient, conversation_id: str, user_id: str) -> None:
"""Removes a user from a channel."""
return make_call(
client, SlackAPIPostEndpoints.conversations_kick, channel=conversation_id, user=user_id
)


def create_conversation(client: WebClient, name: str, is_private: bool = False) -> dict:
"""Make a new Slack conversation."""
response = make_call(
Expand Down
Loading