@@ -237,7 +237,8 @@ def send_slack_message(
237237 ) -> str :
238238 r"""Send a message to a Slack channel. When use this function you must
239239 call `get_slack_channel_information` function first to get the
240- `channel id`.
240+ `channel id`. If use user, you must use `get_slack_user_list`
241+ function first to get the user id.
241242
242243 Args:
243244 message (str): The message to send.
@@ -306,6 +307,52 @@ def delete_slack_message(
306307 except SlackApiError as e :
307308 return f"Error deleting message: { e .response ['error' ]} "
308309
310+ def get_slack_user_list (self ) -> str :
311+ r"""Retrieve a list of all users in the Slack workspace.
312+
313+ Returns:
314+ str: A JSON string representing a list of users. Each user
315+ object contains 'id', 'name'.
316+ """
317+ from slack_sdk .errors import SlackApiError
318+
319+ try :
320+ slack_client = self ._login_slack ()
321+ response = slack_client .users_list ()
322+ users = response ["members" ]
323+ filtered_users = [
324+ {
325+ "id" : user ["id" ],
326+ "name" : user ["name" ],
327+ }
328+ for user in users
329+ ]
330+
331+ return json .dumps (filtered_users , ensure_ascii = False )
332+ except SlackApiError as e :
333+ return f"Error retrieving user list: { e .response ['error' ]} "
334+
335+ def get_slack_user_info (self , user_id : str ) -> str :
336+ r"""Retrieve information about a specific user in the Slack workspace.
337+ normally, you don't need to use this method, when you need to get a
338+ user's detailed information, use this method. Use `get_slack_user_list`
339+ function first to get the user id.
340+
341+ Args:
342+ user_id (str): The ID of the user to retrieve information about.
343+
344+ Returns:
345+ str: A JSON string representing the user's information.
346+ """
347+ from slack_sdk .errors import SlackApiError
348+
349+ try :
350+ slack_client = self ._login_slack ()
351+ response = slack_client .users_info (user = user_id )
352+ return json .dumps (response , ensure_ascii = False )
353+ except SlackApiError as e :
354+ return f"Error retrieving user info: { e .response ['error' ]} "
355+
309356 def get_tools (self ) -> List [FunctionTool ]:
310357 r"""Returns a list of FunctionTool objects representing the
311358 functions in the toolkit.
@@ -322,4 +369,6 @@ def get_tools(self) -> List[FunctionTool]:
322369 FunctionTool (self .get_slack_channel_message ),
323370 FunctionTool (self .send_slack_message ),
324371 FunctionTool (self .delete_slack_message ),
372+ FunctionTool (self .get_slack_user_list ),
373+ FunctionTool (self .get_slack_user_info ),
325374 ]
0 commit comments