Slackbot to know its name (#3917)

This commit is contained in:
Yuhong Sun 2025-02-05 16:39:42 -08:00 committed by GitHub
parent bd08e6d787
commit c58a7ef819
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -410,13 +410,27 @@ class SlackbotHandler:
def start_socket_client(
self, slack_bot_id: int, tenant_id: str | None, slack_bot_tokens: SlackBotTokens
) -> None:
logger.info(
f"Starting socket client for tenant: {tenant_id}, app: {slack_bot_id}"
)
socket_client: TenantSocketModeClient = _get_socket_client(
slack_bot_tokens, tenant_id, slack_bot_id
)
try:
bot_info = socket_client.web_client.auth_test()
if bot_info["ok"]:
bot_user_id = bot_info["user_id"]
user_info = socket_client.web_client.users_info(user=bot_user_id)
if user_info["ok"]:
bot_name = (
user_info["user"]["real_name"] or user_info["user"]["name"]
)
logger.info(
f"Started socket client for Slackbot with name '{bot_name}' (tenant: {tenant_id}, app: {slack_bot_id})"
)
except Exception as e:
logger.warning(
f"Could not fetch bot name: {e} for tenant: {tenant_id}, app: {slack_bot_id}"
)
# Append the event handler
process_slack_event = create_process_slack_event()
socket_client.socket_mode_request_listeners.append(process_slack_event) # type: ignore