Telegram: sending and deleting a message

I have enabled the Telegram integration in HomeAssistant and can send notifications.

I found that the telegram bot has a “Delete message” service. But it needs a message ID, and it is not clear to me where I can get that for a message that I sent earlier. Same with “Edit message”.

Does the “Send message” service perhaps return a generated ID? How would I get and store that?

In the Telegram app or web interface type in @getidsbot

If that doesnt return your used ID then in the @getidsbot type “/start”

In yaml mode I use:

              - delay: 00:00:10
              - service: telegram_bot.delete_message
                data:
                  chat_id: 123456789
                  message_id: last                    
1 Like

So last is the last message sent by the bot? Or the last message sent by anyone in a chat?

Apparently it is the last message of the bot. That’s close enough for my purposes because currently I only use the bot for one single notification. But should I ever need it for more than one, then last will not be sufficient anymore.

Anyway, thanks for the tip!

Did you get to that point?
Does anyone know of another option like “last” for multiple messages? Or something like “everything sent in the last 24h”.
I think of a clean-up routine to keep the bot-chat empty, but the first message needs to stay, so I cant delete the whole chat every day.

I just use the message deletion options in Telegram app. I have my messages “auto-delete in 1 week”…keeps my Chat bot clean

1 Like

Oh thank you, I didnt know of that function.
Would have saved me some hours :roll_eyes: