From 11d76a28819dd139766b643c25f63df1960914c2 Mon Sep 17 00:00:00 2001 From: David Whittaker Date: Mon, 17 Mar 2025 11:22:26 -0700 Subject: [PATCH 1/2] feat(slack): adds ability to remove users from channel --- src/dispatch/plugins/dispatch_slack/enums.py | 1 + src/dispatch/plugins/dispatch_slack/plugin.py | 10 ++++++++++ src/dispatch/plugins/dispatch_slack/service.py | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/src/dispatch/plugins/dispatch_slack/enums.py b/src/dispatch/plugins/dispatch_slack/enums.py index 2e3852eaf75e..79f2a4db2652 100644 --- a/src/dispatch/plugins/dispatch_slack/enums.py +++ b/src/dispatch/plugins/dispatch_slack/enums.py @@ -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" diff --git a/src/dispatch/plugins/dispatch_slack/plugin.py b/src/dispatch/plugins/dispatch_slack/plugin.py index 3d0bb67c9270..2147eb4c855d 100644 --- a/src/dispatch/plugins/dispatch_slack/plugin.py +++ b/src/dispatch/plugins/dispatch_slack/plugin.py @@ -56,6 +56,7 @@ get_user_info_by_id, get_user_profile_by_email, is_user, + kick_member_from_channel, rename_conversation, resolve_user, send_ephemeral_message, @@ -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 kick_user(self, conversation_id: str, user_email: str): + """Kicks a user from a conversation.""" + client = create_slack_client(self.configuration) + user_id = resolve_user(client, user_email).get("id") + if user_id: + return kick_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) diff --git a/src/dispatch/plugins/dispatch_slack/service.py b/src/dispatch/plugins/dispatch_slack/service.py index e5a598c79d5a..392a39b82a6f 100644 --- a/src/dispatch/plugins/dispatch_slack/service.py +++ b/src/dispatch/plugins/dispatch_slack/service.py @@ -348,6 +348,13 @@ def add_conversation_bookmark( ) +def kick_member_from_channel(client: WebClient, conversation_id: str, user_id: str) -> None: + """Kicks 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( From de065b71f9df4baa783ec2d0b1d80fa7fd3ef266 Mon Sep 17 00:00:00 2001 From: David Whittaker Date: Mon, 17 Mar 2025 11:36:42 -0700 Subject: [PATCH 2/2] updates language to remove instead of kick --- src/dispatch/plugins/dispatch_slack/plugin.py | 8 ++++---- src/dispatch/plugins/dispatch_slack/service.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dispatch/plugins/dispatch_slack/plugin.py b/src/dispatch/plugins/dispatch_slack/plugin.py index 2147eb4c855d..336792bfabdb 100644 --- a/src/dispatch/plugins/dispatch_slack/plugin.py +++ b/src/dispatch/plugins/dispatch_slack/plugin.py @@ -56,7 +56,7 @@ get_user_info_by_id, get_user_profile_by_email, is_user, - kick_member_from_channel, + remove_member_from_channel, rename_conversation, resolve_user, send_ephemeral_message, @@ -389,12 +389,12 @@ def set_description(self, conversation_id: str, description: str): client = create_slack_client(self.configuration) return set_conversation_description(client, conversation_id, description) - def kick_user(self, conversation_id: str, user_email: str): - """Kicks a user from a conversation.""" + 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 kick_member_from_channel( + return remove_member_from_channel( client=client, conversation_id=conversation_id, user_id=user_id ) diff --git a/src/dispatch/plugins/dispatch_slack/service.py b/src/dispatch/plugins/dispatch_slack/service.py index 392a39b82a6f..de3986ea680f 100644 --- a/src/dispatch/plugins/dispatch_slack/service.py +++ b/src/dispatch/plugins/dispatch_slack/service.py @@ -348,8 +348,8 @@ def add_conversation_bookmark( ) -def kick_member_from_channel(client: WebClient, conversation_id: str, user_id: str) -> None: - """Kicks a user from a channel.""" +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 )