Use event_data from Telegram in action

Is it possible to use the args from a telegram webhook in a data_template action?

I’ve tried the following but it doesn’t work.

- alias: 'Kitchen Telegram Speak'
  trigger:
    platform: event
    event_type: telegram_command
    event_data:
      command: '/speak'
  action:
    - service: notify.kitchen_echo
      data_template:
        message: "Message from {{ event_data.from_first }}. {{ event_data.args }}"

An hour later and I have the solution!

(kitchen echo is lannouncer)

- alias: 'Kitchen Telegram Speak'
  trigger:
    platform: event
    event_type: telegram_command
    event_data:
      command: '/speak'
  action:
    - service: notify.kitchen_echo
      data_template:
        message: >
          Message from {{ trigger.event.data["from_first"] }}. {% for state in trigger.event.data["args"] %} {{ state }} {% endfor %}

trigger.event.data[] gets the event_data

7 Likes

@daniel-stoneuk can you advise how you chose:

event_data:
   command: '/speak'

I am trying a similar automation on an event and receiving

homeassistant.exceptions.TemplateError: UndefinedError: 'trigger' is undefined