Telegram Bot: Execute an action after receiving a text message

:face_with_monocle: About this blueprint

Wait for a telegram_text event and execute an action. Can be filtred by user_id and chat_id.

Technical Details
  • Type of blueprint: SCRIPT

:gear: Configuration

Requirements

Blueprint fields

  • Remove received message?: Activate this toggle to delete the received message from chat. Useful for private or secret messages (alarm codes, passwords…).

  • Sequence if message is received: What should happen when receiving the text message.

  • Sequence if message is NOT received: What should happen when NOT receiving any message.

Script variables

These variables can be set up when calling the script. See Passing variables to scripts for more information.

  • timeout: Maximum time to wait for receiving a message, in seconds. Default 30 seconds.

  • filter_user_id: Execute the sequence ONLY IF the text message is received from this user_id. Leave empty to avoid filtering.

  • filter_chat_id: Execute the sequence ONLY IF the text message is received from this chat_id. Leave empty to avoid filtering.

Available variables for templating

Event data received from telegram are parsed as variables so that they are easily used in templates. These variables can be used within this automation:

  • telegram_text: Text 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.

  • telegram_chat_id: Chat id.

Template example

Use format {{ variable_name }} in order to print a variable, as usual in Home Assistant.

Example: Hi {{ telegram_sender_first_name }}! You said: {{ telegram_text }}.

:pushpin: Related blueprints

:heavy_plus_sign: Other blueprints

:arrow_down: How to get this blueprint?

Click the badge to import this Blueprint:

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Or you can also:

  • Copy-paste the content from this link to a new file inside your configuration’s blueprints/automation folder.

Changelog

  • 2022-01-30: Solved issue when not receiving any message.
  • 2022-01-30: New option to remove received message.
  • 2022-01-30: First release.