Telegram Bot enhancements with callback queries and new notification services #7454
Conversation
- Receive callback queries and produce `telegram_callback` events.
- Custom reply_markup (keyboard or inline_keyboard) for every type of message (message, photo, location & document).
- `disable_notification`, `disable_web_page_preview`, `reply_to_message_id` and `parse_mode` optional keyword args.
- Line break between title and message fields: `'{}\n{}'.format(title, message)`
- Move Telegram notification services to `telegram_bot` component and forward service calls from the telegram notify service to the telegram component, so now the `notify.telegram` platform depends of `telegram_bot`, and there is no need for `api_key` in the notifier configuration. The notifier calls the new notification services of the bot component:
- telegram_bot/send_message
- telegram_bot/send_photo
- telegram_bot/send_document
- telegram_bot/send_location
- telegram_bot/edit_message
- telegram_bot/edit_caption
- telegram_bot/edit_replymarkup
- telegram_bot/answer_callback_query
- Added descriptions of the new notification services with a services.yaml file.
- CONFIG_SCHEMA instead of PLATFORM_SCHEMA for the `telegram_bot` component, so only one platform is allowed.
- Async component setup.
|
@azogue, thanks for your PR! By analyzing the history of the files in this pull request, we identified @fabaff, @pvizeli and @MartinHjelmare to be potential reviewers. |
|
🎉🎉🎉🎉🎉🎉🎉🎉 Looks great. Don't worry about the mess, you brought it all together nicely in the end. |
|
This should have been marked a breaking change. |
|
Fully agree that this is breaking since it restricts it to user chats only. Group chat IDs are negative and not allowed anymore. Is this just a bug or was this new limitation intended? Update: nevermind, I just found #7688 |
|
It's a bug (my bug!). I have fixed and tested it, so for a quickfix, I can do a PR |
|
It's now also required to set up the The docs PR linked previously above was closed. |
|
I've done a new PR #7689 to allow send and receive msgs to/from groups. But yes, the PR evolved into a breaking-change and the label was missed... |
Telegram Bot with callback queries:
When making inline keyboards with the telegram notify platform, if pressed, they send data like this:
{"chat_instance": "XXXXXXXXXXXXXXXXXXX", "data": "[/data sent]", "from": {"username": "[USERNAME]", "last_name": "[LAST_NAME]", "first_name": "[FIRST_NAME]", "id": 123456789}, "id": "1234567890123456789", "message": {origin_message_dict}which isn't processed correctly with the current telegram_bot platform. With these changes, when received, HA sends a telegram_callback event with the callback data, the chat instance, the original message and a unique id of the callback.
Also, some changes in the telegram notifier for using more features of the Telegram API 2.0.
Changes:
telegram_callbackevents.disable_notification,disable_web_page_preview,reply_to_message_idandparse_modeoptional keyword args.'{}\n{}'.format(title, message)telegram_botcomponent and forward service calls from the telegram notify service to the telegram component, so now thenotify.telegramplatform depends oftelegram_bot, and there is no need forapi_keyin the notifier configuration. The notifier calls the new notification services of the bot component:telegram_botcomponent, so only one platform is allowed.With these changes it is now very easy to make a custom bot witch presents messages and buttons with posible responses, and change dynamically these messages and inline keyboards guiding the user in some sort of a wizard menu.
Related issue (if applicable): new version without conflicts of PR #7294
Pull request in home-assistant.github.io with documentation (if applicable):
home-assistant/home-assistant.io#2573home-assistant/home-assistant.io#2508
Example entry for
configuration.yaml(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed: