Skip to content

Commit 898ef43

Browse files
hanwgfrenck
authored andcommitted
Fix Telegram bots using plain text parser failing to load on restart (home-assistant#148050)
1 parent f806e6b commit 898ef43

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

homeassistant/components/telegram_bot/bot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,7 @@ def _make_row_inline_keyboard(row_keyboard: Any) -> list[InlineKeyboardButton]:
374374
}
375375
if data is not None:
376376
if ATTR_PARSER in data:
377-
params[ATTR_PARSER] = self._parsers.get(
378-
data[ATTR_PARSER], self.parse_mode
379-
)
377+
params[ATTR_PARSER] = data[ATTR_PARSER]
380378
if ATTR_TIMEOUT in data:
381379
params[ATTR_TIMEOUT] = data[ATTR_TIMEOUT]
382380
if ATTR_DISABLE_NOTIF in data:
@@ -408,6 +406,8 @@ def _make_row_inline_keyboard(row_keyboard: Any) -> list[InlineKeyboardButton]:
408406
params[ATTR_REPLYMARKUP] = InlineKeyboardMarkup(
409407
[_make_row_inline_keyboard(row) for row in keys]
410408
)
409+
if params[ATTR_PARSER] == PARSER_PLAIN_TEXT:
410+
params[ATTR_PARSER] = None
411411
return params
412412

413413
async def _send_msg(

homeassistant/components/telegram_bot/config_flow.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ async def async_step_init(
159159
"""Manage the options."""
160160

161161
if user_input is not None:
162-
if user_input[ATTR_PARSER] == PARSER_PLAIN_TEXT:
163-
user_input[ATTR_PARSER] = None
164162
return self.async_create_entry(data=user_input)
165163

166164
return self.async_show_form(

homeassistant/components/telegram_bot/services.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ send_photo:
109109
- "markdown"
110110
- "markdownv2"
111111
- "plain_text"
112+
translation_key: "parse_mode"
112113
disable_notification:
113114
selector:
114115
boolean:
@@ -261,6 +262,7 @@ send_animation:
261262
- "markdown"
262263
- "markdownv2"
263264
- "plain_text"
265+
translation_key: "parse_mode"
264266
disable_notification:
265267
selector:
266268
boolean:
@@ -341,6 +343,7 @@ send_video:
341343
- "markdown"
342344
- "markdownv2"
343345
- "plain_text"
346+
translation_key: "parse_mode"
344347
disable_notification:
345348
selector:
346349
boolean:
@@ -493,6 +496,7 @@ send_document:
493496
- "markdown"
494497
- "markdownv2"
495498
- "plain_text"
499+
translation_key: "parse_mode"
496500
disable_notification:
497501
selector:
498502
boolean:
@@ -670,6 +674,7 @@ edit_message:
670674
- "markdown"
671675
- "markdownv2"
672676
- "plain_text"
677+
translation_key: "parse_mode"
673678
disable_web_page_preview:
674679
selector:
675680
boolean:

tests/components/telegram_bot/test_config_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async def test_options_flow(
6363
await hass.async_block_till_done()
6464

6565
assert result["type"] == FlowResultType.CREATE_ENTRY
66-
assert result["data"][ATTR_PARSER] is None
66+
assert result["data"][ATTR_PARSER] == PARSER_PLAIN_TEXT
6767

6868

6969
async def test_reconfigure_flow_broadcast(

tests/components/telegram_bot/test_telegram_bot.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
ATTR_VERIFY_SSL,
5151
CONF_CONFIG_ENTRY_ID,
5252
DOMAIN,
53+
PARSER_PLAIN_TEXT,
5354
PLATFORM_BROADCAST,
5455
SECTION_ADVANCED_SETTINGS,
5556
SERVICE_ANSWER_CALLBACK_QUERY,
@@ -183,6 +184,7 @@ async def test_send_message(
183184
(
184185
{
185186
ATTR_MESSAGE: "test_message",
187+
ATTR_PARSER: PARSER_PLAIN_TEXT,
186188
ATTR_KEYBOARD_INLINE: "command1:/cmd1,/cmd2,mock_link:https://mock_link",
187189
},
188190
InlineKeyboardMarkup(
@@ -199,6 +201,7 @@ async def test_send_message(
199201
(
200202
{
201203
ATTR_MESSAGE: "test_message",
204+
ATTR_PARSER: PARSER_PLAIN_TEXT,
202205
ATTR_KEYBOARD_INLINE: [
203206
[["command1", "/cmd1"]],
204207
[["mock_link", "https://mock_link"]],
@@ -250,7 +253,7 @@ async def test_send_message_with_inline_keyboard(
250253
mock_send_message.assert_called_once_with(
251254
12345678,
252255
"test_message",
253-
parse_mode=ParseMode.MARKDOWN,
256+
parse_mode=None,
254257
disable_web_page_preview=None,
255258
disable_notification=False,
256259
reply_to_message_id=None,

0 commit comments

Comments
 (0)