Translate invalid API token error in telegram_bot (#184442)

This commit is contained in:
Franck Nijhof
2026-10-06 11:37:35 +02:00
committed by GitHub
parent 6e2d8adac7
commit ae69def19c
3 changed files with 8 additions and 2 deletions
@@ -166,8 +166,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: TelegramBotConfigEntry)
try:
await bot.get_me()
except InvalidToken as err:
# pylint: disable-next=home-assistant-exception-not-translated
raise ConfigEntryAuthFailed("Invalid API token for Telegram Bot.") from err
raise ConfigEntryAuthFailed(
translation_domain=DOMAIN,
translation_key="invalid_api_key",
) from err
except TelegramError as err:
# Do not let the message through: the Telegram API URL embeds the bot
# token, and library errors quote that URL.
@@ -198,6 +198,9 @@
"failed_to_load_url": {
"message": "Failed to load URL: {error}"
},
"invalid_api_key": {
"message": "The Telegram bot API token is invalid."
},
"invalid_chat_ids": {
"message": "Invalid chat IDs: {chat_ids}. Please configure the chat IDs for {bot_name}."
},
@@ -1476,6 +1476,7 @@ async def test_async_setup_entry_failed(
await hass.async_block_till_done()
assert mock_broadcast_config_entry.state is ConfigEntryState.SETUP_ERROR
assert mock_broadcast_config_entry.error_reason_translation_key == "invalid_api_key"
async def test_answer_callback_query(