Hello,
As I know Telegram Bot allows to edit/delete just last message in a chat by using magic “last” constant for message_id. But… sometimes HA should be able to edit/delete ANY (not just last) important message in chat. For this purpose, a special service call could be implemented - returning last_message_id as input_number.
The good example of such a scenario (know as “singleton-notification”) could be:
-
HA sends Telegram Notification is that one of “PCs is not used” (e.g. by detecting low CPU usage for last 30 minutes) also… giving the options to “turn PC off” or decide to “leave it running” by selecting one of the options on Telegram Keyboard. Any User action should delete this message and… this is OK, this can be realized right now done right now, as it’s a straightforward reaction to the callback (callback provides message_id)
-
Now, imagine that nobody takes an action on this Telegram message and after a few minutes new notifications are generated by HA (not related to PC) in the same chat. The message giving the option to “turn off PC” is no longer the last one.
-
Now, in case of someone goes back to PC and its CPU goes up again (or PC is turned off manually) the HA should automatically delete the message in a chat - the old message allowing to “turn PC off” remotely. Otherwise users still see the option to “turn PC off” even if conditions have changed.
For this purpose, I think it’s worth to implement service getting the value of the last message_id for given chat_id. The value could be stored (using special input_number entity) by triggering secondary action of telegram_bot.get_last_message_id executing it immediately after notification is sent.
Service Proposal
service telegram_bot.get_last_message_id
attributes:
- chat_id: the chat id for which we want to extract the last message_id
- message_id_variable: the return variable, the name of input_number entity, which will be set to the value of the last message_id for given chat_id
NOTE: As I can see in GitHub the method _get_last_message_id(…) is already implemented in telegram_bot. I guess it should be quite easy to expose it as a service call.