@@ -390,13 +390,48 @@ def set_description(self, conversation_id: str, description: str):
390390 return set_conversation_description (client , conversation_id , description )
391391
392392 def remove_user (self , conversation_id : str , user_email : str ):
393- """Removes a user from a conversation."""
393+ """Removes a user from a conversation.
394+
395+ Args:
396+ conversation_id: The Slack conversation/channel ID
397+ user_email: The email address of the user to remove
398+
399+ Returns:
400+ The API response if successful, None if user not found
401+
402+ Raises:
403+ SlackApiError: For non-recoverable Slack API errors
404+ """
394405 client = create_slack_client (self .configuration )
395- user_id = resolve_user (client , user_email ).get ("id" )
396- if user_id :
397- return remove_member_from_channel (
398- client = client , conversation_id = conversation_id , user_id = user_id
399- )
406+
407+ try :
408+ user_info = resolve_user (client , user_email )
409+ user_id = user_info .get ("id" )
410+
411+ if user_id :
412+ return remove_member_from_channel (
413+ client = client , conversation_id = conversation_id , user_id = user_id
414+ )
415+ else :
416+ logger .warning (
417+ "Cannot remove user %s from conversation %s: "
418+ "User ID not found in resolve_user response" ,
419+ user_email , conversation_id
420+ )
421+ return None
422+
423+ except SlackApiError as e :
424+ if e .response .get ("error" ) == SlackAPIErrorCode .USERS_NOT_FOUND :
425+ logger .warning (
426+ "User %s not found in Slack workspace. "
427+ "Cannot remove from conversation %s. "
428+ "User may have been deactivated or never had Slack access." ,
429+ user_email , conversation_id
430+ )
431+ return None
432+ else :
433+ # Re-raise for other Slack API errors
434+ raise
400435
401436 def add_bookmark (self , conversation_id : str , weblink : str , title : str ):
402437 """Adds a bookmark to the conversation."""
0 commit comments