How to automate the sending and deletion of Telegram messages?

Hi there,

I have been setting up telegram bot notifications in to my HA configuration. All good and I was happy to see that I could set up automations using the UI to turn on things and send a Telegram notification. However I would like to then delete the notification some few minutes later to reduce the message clutter on my BOT. It is possible to add another action to the established Automation and add a delay of the required time, then add another action to Call service and delete messages, however I have been playing to get this working but no luck yet. To send a message from the Automation I only have to set the message and the title and not worry about the Chat ID. However I do not know what to enter for the deletion of the message. Does anyone have some suggestions?

From my Automations.yaml file, here is the automation including the message bot part to send notification which all works fine, just never deletes the message:

 - id: '1614088427892'
  alias: Hot Water Heater ON
  description: Switch on Contactor if Solar production above 2000w and exporting to
  - platform: numeric_state
    entity_id: sensor.hauxtonenvoy_current_energy_production
    above: '1999'
  - condition: numeric_state
    entity_id: sensor.inst_energy_difference
    above: '0'
  - condition: device
    type: is_off
    device_id: f44ede254035005d7dc09d266aca7bba
    entity_id: switch.bf265fb7b0e1bbfdc1rzbg
    domain: switch
  - type: turn_on
    device_id: f44ede254035005d7dc09d266aca7bba
    entity_id: switch.bf265fb7b0e1bbfdc1rzbg
    domain: switch
  - service: telegram_bot.send_message
      message: Hotwater Immersion turned ON
      title: Home
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - service: telegram_bot.delete_message
      message: last
  mode: single

Where is the message_id and the chat_id?

1 Like

Hi, I would like to know if with one command it is possible to delete ALL chat messages.
I would like to make an automation that every day at a set time deletes all messages.


You can set the telegram app to delete old messages. Open your message contact then to right menu clear chat history, then use the slide bar to delete anything older that 24 hours.

in the Telegram app (ios) there is no such option

not even for the web version that option is available

it only works in chats, not bots

Nowadays it’s possible to set an auto-delete intervals on bots