Skip to content

Add telegram_sent event#41159

Merged
bdraco merged 5 commits intohome-assistant:devfrom
NikoM87:feature_telegram_sent
Oct 29, 2020
Merged

Add telegram_sent event#41159
bdraco merged 5 commits intohome-assistant:devfrom
NikoM87:feature_telegram_sent

Conversation

@NikoM87
Copy link
Copy Markdown
Contributor

@NikoM87 NikoM87 commented Oct 3, 2020

Breaking change

Proposed change

For the telegram_bot component, for some automations it is necessary to edit or delete messages in history that the bot sent.

As a solution, I propose a new telegram_sent event with the optional message_tag parameter.
The message_tag parameter allows you to distinguish (filter) automation flows.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

automation:
  - alias: Vacuum cleaner started
    trigger:
      entity_id: vacuum.xiaomi_vacuum_cleaner
      platform: state
      from: 'docked'
      to: 'cleaning'
    action:
      - service: telegram_bot.send_message
        data_template:
          message: 'Сleaning in progress'
          message_tag: "msg_start"

  - alias: Save chatId and messageId
    trigger:
      platform: event
      event_type: telegram_sent
      event_data:
        message_tag: "msg_start"
    action:
      - service: input_number.set_value
        data_template:
          entity_id: input_number.chat_id
          value: '{{ trigger.event.data.chat_id }}'
      - service: input_number.set_value
        data_template:
          entity_id: input_number.message_id
          value: '{{ trigger.event.data.message_id }}'

  - alias: Vacuum cleaner docked
    trigger:
      entity_id: vacuum.xiaomi_vacuum_cleaner
      platform: state
      from: 'returning'
      to: 'docked'
    action:
      - service: telegram_bot.edit_message
        data_template:
          chat_id: "{{ states('input_number.chat_id') | int }}"
          message_id: "{{ states('input_number.message_id') | int }}"
          message: 'Cleaning completed'

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

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

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

Copy link
Copy Markdown
Contributor

@hfurubotten hfurubotten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thoughts I had while reading the code, hope they might turn out to be useful improvements 🙂

Comment thread homeassistant/components/telegram_bot/__init__.py Outdated
Comment thread homeassistant/components/telegram_bot/__init__.py Outdated
Comment thread homeassistant/components/telegram_bot/__init__.py Outdated
NikoM87 and others added 3 commits October 4, 2020 01:08
Co-authored-by: Heine Furubotten <hfurubotten@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@ShaneQi ShaneQi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any problem in the code change.

But I'm not in the place to approve this proposal.

Comment thread homeassistant/components/telegram_bot/__init__.py Outdated
@NikoM87 NikoM87 requested a review from bdraco October 18, 2020 19:59
@rbflurry
Copy link
Copy Markdown
Contributor

Any Love for this?

@bdraco bdraco merged commit a396f8f into home-assistant:dev Oct 29, 2020
@NikoM87 NikoM87 deleted the feature_telegram_sent branch May 31, 2021 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants