How to handle Telegram commands?

I am trying to handle telegram commands with an event trigger automation. However, it apparently works very iffily. If I do this:

- trigger:
      platform: event
      event_type: telegram_command
  action:
      service: telegram_bot.send_message
      data:
        message: something {{ trigger.event.data.command }}

I expect the command name to be answered back to me via Telegram. Instead, I get the message text literally. However, if I try this:

- trigger:
      platform: event
      event_type: telegram_command
  action:
      service: telegram_bot.send_message
      data:
        message: {{ trigger.event.data.command }}

So I just put the template in the message without any prefix, then I get an error message that my configuration is invalid.

Error loading /home/homeassistant/.homeassistant/configuration.yaml: invalid key: "OrderedDict([('trigger.event.data.command', None)])"
  in "/home/homeassistant/.homeassistant/automations.yaml", line 232, column 0

How do I access the event data from the automation?

I think You are missing the command

- trigger:
      platform: event
      event_type: telegram_command
     event_data:
      command: "/speak"
1 Like