mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Update Telegram bot to support URLs in inlineKeyboard (#70445)
* Update Telegram bot to support URLs in inlineKeyboard Update creation of InlineKeyboardButton to support url case, on top of callbacks * linting * Apply suggestions from code review --------- Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
parent
8b563120b5
commit
36b0fc17df
@ -529,11 +529,18 @@ class TelegramNotificationService:
|
|||||||
(text_b2, data_callback_b2), ...]
|
(text_b2, data_callback_b2), ...]
|
||||||
- a string like: `/cmd1, /cmd2, /cmd3`
|
- a string like: `/cmd1, /cmd2, /cmd3`
|
||||||
- or a string like: `text_b1:/cmd1, text_b2:/cmd2`
|
- or a string like: `text_b1:/cmd1, text_b2:/cmd2`
|
||||||
|
- also supports urls instead of callback commands
|
||||||
"""
|
"""
|
||||||
buttons = []
|
buttons = []
|
||||||
if isinstance(row_keyboard, str):
|
if isinstance(row_keyboard, str):
|
||||||
for key in row_keyboard.split(","):
|
for key in row_keyboard.split(","):
|
||||||
if ":/" in key:
|
if ":/" in key:
|
||||||
|
# check if command or URL
|
||||||
|
if key.startswith("https://"):
|
||||||
|
label = key.split(",")[0]
|
||||||
|
url = key[len(label) + 1 :]
|
||||||
|
buttons.append(InlineKeyboardButton(label, url=url))
|
||||||
|
else:
|
||||||
# commands like: 'Label:/cmd' become ('Label', '/cmd')
|
# commands like: 'Label:/cmd' become ('Label', '/cmd')
|
||||||
label = key.split(":/")[0]
|
label = key.split(":/")[0]
|
||||||
command = key[len(label) + 1 :]
|
command = key[len(label) + 1 :]
|
||||||
@ -547,6 +554,9 @@ class TelegramNotificationService:
|
|||||||
elif isinstance(row_keyboard, list):
|
elif isinstance(row_keyboard, list):
|
||||||
for entry in row_keyboard:
|
for entry in row_keyboard:
|
||||||
text_btn, data_btn = entry
|
text_btn, data_btn = entry
|
||||||
|
if data_btn.startswith("https://"):
|
||||||
|
buttons.append(InlineKeyboardButton(text_btn, url=data_btn))
|
||||||
|
else:
|
||||||
buttons.append(
|
buttons.append(
|
||||||
InlineKeyboardButton(text_btn, callback_data=data_btn)
|
InlineKeyboardButton(text_btn, callback_data=data_btn)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user