From 7331eb1f7177e86cad2bbcd146fa6cc4b987494c Mon Sep 17 00:00:00 2001 From: Max <870074+max-te@users.noreply.github.com> Date: Thu, 2 May 2019 21:14:40 +0200 Subject: [PATCH] Allow removing Telegram reply keyboard (#23467) * Allow removing telegram reply keyboard by setting `keyboard` to an empty list * Telegram keyboard: [] clearing in services.yaml --- homeassistant/components/telegram_bot/__init__.py | 10 +++++++--- homeassistant/components/telegram_bot/services.yaml | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/telegram_bot/__init__.py b/homeassistant/components/telegram_bot/__init__.py index 43f8a26644c..09d4fb0dd88 100644 --- a/homeassistant/components/telegram_bot/__init__.py +++ b/homeassistant/components/telegram_bot/__init__.py @@ -446,11 +446,15 @@ class TelegramNotificationService: params[ATTR_REPLY_TO_MSGID] = data[ATTR_REPLY_TO_MSGID] # Keyboards: if ATTR_KEYBOARD in data: - from telegram import ReplyKeyboardMarkup + from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove keys = data.get(ATTR_KEYBOARD) keys = keys if isinstance(keys, list) else [keys] - params[ATTR_REPLYMARKUP] = ReplyKeyboardMarkup( - [[key.strip() for key in row.split(",")] for row in keys]) + if keys: + params[ATTR_REPLYMARKUP] = ReplyKeyboardMarkup( + [[key.strip() for key in row.split(",")] + for row in keys]) + else: + params[ATTR_REPLYMARKUP] = ReplyKeyboardRemove(True) elif ATTR_KEYBOARD_INLINE in data: from telegram import InlineKeyboardMarkup keys = data.get(ATTR_KEYBOARD_INLINE) diff --git a/homeassistant/components/telegram_bot/services.yaml b/homeassistant/components/telegram_bot/services.yaml index 206898bfda2..ed8720c5877 100644 --- a/homeassistant/components/telegram_bot/services.yaml +++ b/homeassistant/components/telegram_bot/services.yaml @@ -22,7 +22,7 @@ send_message: description: Disables link previews for links in the message. example: true keyboard: - description: List of rows of commands, comma-separated, to make a custom keyboard. + description: List of rows of commands, comma-separated, to make a custom keyboard. Empty list clears a previously set keyboard. example: '["/command1, /command2", "/command3"]' inline_keyboard: description: List of rows of commands, comma-separated, to make a custom inline keyboard with buttons with associated callback data.