blueprint: author: marc-romu domain: automation name: 'Telegram Bot: Respond to Telegram Command by executing an action' description: > Listen to a Telegram Command and execute an action if listened ## "Command" field Command to listen for. Must start with '/'. _Example:_ `/start` ## "Bot" field Bot username. It is used when there is more than one bot in a group chat. _Example:_ `my_bot_username_bot` ## "Sequence" field What should happen when receiving this command. You can use variables explained below. ## Available telegram variables in this blueprint These variables are received from telegram. You can use them in templates within this automation: - `telegram_args`: List of words sent after command. You can get each word by its index: `telegram_args[0]`, `telegram_args[1]`, etc. - `telegram_args_as_text`: Single plain text string from arguments' list. Useful if you need full text, not single words. - `telegram_chat_id`: Chat id. It is the same as sender's user id in case it is a private message. - `telegram_sender_first_name`: Sender's first name. - `telegram_sender_last_name`: Sender's last name. - `telegram_sender_full_name`: Sender's full name, as `first_name + " " + last_name` - `telegram_sender_user_id`: Sender's user id. #### Template example Use format `{{ variable_name }}` to indicate that it is a template, as usual in Home Assistant. `Hi {{ telegram_sender_first_name }}! You said {{ telegram_args_as_text }} after the command.` input: telegram_command: name: Command description: 'REQUIRED. Example: /start' selector: text: multiline: false telegram_bot: name: Bot description: 'REQUIRED. Telegram bot username. Example: my_bot' default: 'bot_not_specified_in_automation' selector: text: multiline: false sequence: name: Sequence description: "What should happen when receiving this command. You can use variables explained above." selector: action: {} mode: parallel max: 10 max_exceeded: warning trigger_variables: telegram_command: !input 'telegram_command' telegram_bot: !input 'telegram_bot' telegram_command_at_bot: "{{ telegram_command ~ '@' ~ telegram_bot }}" trigger: - platform: event id: "telegram_command" event_type: telegram_command event_data: command: "{{ telegram_command }}" - platform: event id: "telegram_callback" event_type: telegram_callback event_data: data: "{{ telegram_command }}" - platform: event id: "telegram_command" event_type: telegram_command event_data: command: "{{ telegram_command_at_bot }}" - platform: event id: "telegram_callback" event_type: telegram_callback event_data: data: "{{ telegram_command_at_bot }}" variables: trigger_event_type: "{{ trigger.event.event_type }}" telegram_command: !input 'telegram_command' telegram_bot: !input 'telegram_bot' telegram_command_at_bot: "{{ telegram_command ~ '@' ~ telegram_bot }}" telegram_args: "{{ trigger.event.data['args'] }}" telegram_args_as_text: "{% for arg in telegram_args %}{{ arg }} {% endfor %}" telegram_chat_id: "{{ trigger.event.data['chat_id'] }}" telegram_sender_first_name: "{{ trigger.event.data['from_first'] }}" telegram_sender_last_name: "{{ trigger.event.data['from_last'] }}" telegram_sender_full_name: "{{ telegram_sender_first_name }} {{ telegram_sender_last_name }}" telegram_sender_user_id: "{{ trigger.event.data['user_id'] }}" condition: action: !input 'sequence'