Skip to content

Telegram Bot enhancements with callback queries and new notification services #7454

Merged
balloob merged 2 commits into
home-assistant:devfrom
azogue:telegram_bot-callbacks
May 10, 2017
Merged

Telegram Bot enhancements with callback queries and new notification services #7454
balloob merged 2 commits into
home-assistant:devfrom
azogue:telegram_bot-callbacks

Conversation

@azogue
Copy link
Copy Markdown
Member

@azogue azogue commented May 5, 2017

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:

  • 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.

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#2573
home-assistant/home-assistant.io#2508

Example entry for configuration.yaml (if applicable):

# Telegram Notifier
notify:
  - platform: telegram
    name: telegram_bot
    chat_id: [USER1_CHAT_ID]

# Telegram Bot
telegram_bot:
  platform: webhooks
  api_key: [TELEGRAM_BOT_API_KEY]
  allowed_chat_ids:
    - [USER1_CHAT_ID]
    - [USER2_CHAT_ID]

Checklist:

If user exposed functionality or configuration variables are added/changed:

- 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.
@mention-bot
Copy link
Copy Markdown

@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.

@azogue
Copy link
Copy Markdown
Member Author

azogue commented May 5, 2017

@balloob, I'm very sorry for the mess, I hope the next attempt will be easier for me.

I created this new PR with just one commit from a new local branch, this one without conflicts, and now I will close the other one (PR #7294).

@balloob
Copy link
Copy Markdown
Member

balloob commented May 10, 2017

🎉🎉🎉🎉🎉🎉🎉🎉 Looks great. Don't worry about the mess, you brought it all together nicely in the end.

@balloob balloob merged commit b30c352 into home-assistant:dev May 10, 2017
@azogue azogue deleted the telegram_bot-callbacks branch May 13, 2017 08:21
@MartinHjelmare
Copy link
Copy Markdown
Member

This should have been marked a breaking change.

@sibbl
Copy link
Copy Markdown

sibbl commented May 21, 2017

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

@azogue
Copy link
Copy Markdown
Member Author

azogue commented May 21, 2017

It's a bug (my bug!). I have fixed and tested it, so for a quickfix, I can do a PR

@MartinHjelmare
Copy link
Copy Markdown
Member

It's now also required to set up the telegram_bot component even only for telegram notify platform.
This is the PR for the docs that was merged:
home-assistant/home-assistant.io#2508

The docs PR linked previously above was closed.

@azogue
Copy link
Copy Markdown
Member Author

azogue commented May 21, 2017

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...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants