INNER CODE UNIT · Python
set_locale
seratch/ChatGPT-in-Slack · main_prod.py:130
def set_locale(
context: BoltContext,
client: WebClient,
logger: logging.Logger,
next_,
):
bot_scopes = context.authorize_result.bot_scopes
if bot_scopes is not None and "users:read" in bot_scopes:
user_id = context.actor_user_id or context.user_id
try:
user_info = client.users_info(user=user_id, include_locale=True)
context["locale"] = user_info.get("user", {}).get("locale")
except SlackApiError as e:
logger.debug(f"Failed to fetch user info due to {e}")
pass
next_()
@app.middleware