Add notify_target parameter for Telegram bot actions
Proposed change
Currently, chat_id is used as targets for telegram bot actions.
chat_id is not intuitive since it is a numeric identifier.
With the introduction of notify entities in https://github.com/home-assistant/core/pull/149853, we can instead use these entities as targets.
This change introduces a new notify_target parameter which uses the entity selector to allow the user to select telegram bot notify entities for actions.
Detailed changes:
- Scope: Change is for all Telegram bot actions.
-
targetaction parameters:
- Current:
targetparameter is used for specifying chat IDs - New:
targetparameter is now used for specifying notify entities. During this migration period, chat IDs found intargetare automatically copied to the newchat_idfield. A repair issue is also created to inform the user to update their automations/scripts.
- Design consideration: This PR doesn't introduce new entity service but rather, it modifies the existing action to handle notify entities. The integration has lots of actions and introducing new entity service will make the number of actions swell. Furthermore, users are already familiar with the names of the existing actions.
-
Updated action responses (return values): Added new field
entity_idtoServiceResponse. This field is only available ifentity_idwas used in the input. This new output value can be used in complex automations e.g. outputentity_idofsend_messagecan be used as input foredit_message. - Existing fields,
config_entry_idandchat_idare moved into a a new section named "Custom targets". This helps to avoid confusion for new users by hiding those 2 fields and drawing the user's attention to thetargetfield for specifying notify enties as targets. - New behavior: We first build the list of targets based on the
entity_id,config_entry_idandtargetfields. The service is then invoked once for each of the targets. (See_build_targets()in__init__.py)
Type of change
- [ ] Dependency upgrade
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [x] New feature (which adds functionality to an existing integration)
- [ ] Deprecation (breaking change to happen in the future)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
Additional information
- This PR fixes or closes issue: https://github.com/orgs/home-assistant/discussions/881
- This PR is related to issue:
- Link to documentation pull request: https://github.com/home-assistant/home-assistant.io/pull/41823
- Link to developer documentation pull request:
- Link to frontend pull request:
Checklist
- [x] I understand the code I am submitting and can explain how it works.
- [x] The code change is tested and works locally.
- [x] Local tests pass. Your PR cannot be merged unless tests pass
- [x] There is no commented out code in this PR.
- [x] I have followed the development checklist
- [x] I have followed the perfect PR recommendations
- [x] The code has been formatted using Ruff (
ruff format homeassistant tests) - [x] Tests have been added to verify that the new code works.
- [x] Any generated code has been carefully reviewed for correctness and compliance with project standards.
If user exposed functionality or configuration variables are added/changed:
- [x] Documentation added/updated for www.home-assistant.io
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 runningpython3 -m script.gen_requirements_all. - [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
To help with the load of incoming pull requests:
- [ ] I have reviewed two other open pull requests in this repository.
Look good!
More clean and lower possibilities of mistakes
Yep. Looks a very good improvement. I wonder if it would be ideal to allow either target or notify_target to be flagged, but not both. That would simplify also the logic quite a bit, no?
Wouldn't a separate entity service be more suitable? There is a select for the config entry, but the notify entities could correspond to different config entries. That is imho a bit counter-intuitive. The ntfy integration for example has an action (ntfy.publish) to target notify entities.
Wouldn't a separate entity service be more suitable? There is a select for the config entry, but the notify entities could correspond to different config entries. That is imho a bit counter-intuitive. The ntfy integration for example has an action (
ntfy.publish) to target notify entities.
If you would want send a notification to multiples users, you should create multiple actions... This allow use one action to multiples targets
Yep. Looks a very good improvement. I wonder if it would be ideal to allow either target or notify_target to be flagged, but not both. That would simplify also the logic quite a bit, no?
I think that the integration should allow it. if you remove numeric chat will be a breaking change, and sometimes you would want send a notification to regular target and especials targets, so both target should be set in the same action
Wouldn't a separate entity service be more suitable? There is a select for the config entry, but the notify entities could correspond to different config entries. That is imho a bit counter-intuitive. The ntfy integration for example has an action (
ntfy.publish) to target notify entities.
Added v2 screenshot in PR description.
In v2, I moved the config_entry_id and target fields into a new collapsed section named "Custom target".
The intent is that most users should only use the new notify_target field.
If the user wants to send messages to arbitrary chat_ids then they will use the config_entry_id and target fields.
Related PR about sending to arbitrary chat_ids : https://github.com/home-assistant/core/pull/149924
I'd like to see a motivation to why we want to extend the legacy services instead of adding entity service(s) as done for ntfy in #143560
I initially did thought of creating a new action (for example telegram_bot.notify_message but decided to modify the existing telegram_bot.send_message action because of the following reasons:
- avoid breaking changes
- support for future feature request (https://github.com/orgs/home-assistant/discussions/467)
This PR is well and truly needed.
I just went to update my 227 uses of the notify.telegram_xxx action (where xxx is one of five defined chat groups) to the new telegram_bot.send_message action as a repair came up when I installed core-2025.11.0b1.
I found I could not set the newly created telegram bot entities as a targets for this action. I had to list the numeric chat ids.
I will ignore the repair until this is resolved / merged / released.
@hanwg I don't understand that explanation. Why would implementing a more modern approach be a breaking change or prevent implementing future features?
I think what's not clear to me is:
- When do users want to not set up notify entities for certain chats, but instead provide them in a legacy style notify service call?
- If we want to keep extending support for both targeting chats without subentry and targeting chats with a subentry, why is it beneficial to do that in a single service instead of in separate services?
One of the early suggestion was to remove the existing config_entry_id and target parameters and to add the new notify_target parameter for the existing actions. This would have been a breaking change and so this idea was dropped.
It's actually easier to implement separate services/actions and there won't be breaking changes; the only downside is that the integration will have twice as many actions.
I was concerned that having 2 sets of actions (example: the existing telegram_bot.send_message and the new telegram_bot.notify_message) might be confusing for the users.
Most users might not be aware of the new notify_message action since it is not a standard Telegram function like send_message.
@hanwg OK, but when do users want to not set up notify entities for certain chats, but instead provide them in a legacy style notify service call?
I had intended the legacy style (config_entry_id with target) to be used for sending/receiving to arbitrary chat_ids (see: https://github.com/home-assistant/core/pull/149924).
PR is ready for review, if anyone wants to be an early tester, I would greatly appreciate it.
Testing right now as a custom component. For the action send_message it works great. I don't see the new fields for the other actions. Is that on purpose?
It's only for send_message for now.
The some of the other actions have some special handling so it's probably better to do them in a separate PR.
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks :+1: