Skip to content

Missing Bot Identification in Telegram Integration Events #149799

@vasmarfas

Description

@vasmarfas

The problem

After adding support for multiple Telegram bots in Home Assistant, there's no way to distinguish which bot received a message in automation triggers. This causes all automations listening to telegram_text events to trigger regardless of which bot actually received the message.

Current Behavior
When a message is sent to any configured Telegram bot, the telegram_text event is fired with the following data structure:

event_type: telegram_text
data:
  id: 5357
  chat_id: 1234556789
  date: "2025-07-31T21:51:27+00:00"
  message_thread_id: null
  text: "status"
  user_id: 1234556789
  from_first: "Vasiliy"
  from_last: null

Issue: There's no identifier indicating which bot received the message.
Expected Behavior
The event data should include bot identification information, such as:

event_type: telegram_text
data:
  id: 5357
  chat_id: 1234556789
  bot_id: "987654321"   # or bot_username, config_entry_id, etc.
  bot_username: "my_water_bot"
  config_entry_id: "01K1H4Z8VPC00JCCP7V7PBRAQN"
  date: "2025-07-31T21:51:27+00:00"
  text: "status"
  user_id: 1234556789
  from_first: "Vasiliy"
  from_last: null

Use Case
I have two Telegram bots configured:

Water Monitoring Bot - handles commands like checkstatus, testwater
Gates Bot - handles commands like status, open, close

Both bots receive messages from the same users, but currently there's no way to create separate automations that respond only to their respective bot's messages.

Proposed Solution
Add one or more of the following fields to the telegram_text event data:

bot_id - Telegram bot ID
bot_username - Bot username (without @)
config_entry_id - Home Assistant config entry ID
bot_name - Friendly name from HA configuration

This would allow automations to filter events like:
yamlconditions:

  • condition: template
    value_template: "{{ trigger.event.data.bot_username == 'my_water_bot' }}"

What version of Home Assistant Core has the issue?

core-2025.7.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Telegram

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

alias: Telegram Water Bot Commands
description: Telegram Water Bot Commands
triggers:
  - event_type: telegram_text
    trigger: event
conditions:
  - condition: template
    value_template: "{{ trigger.event.data.bot_id == 123456789 }}" // <- Not working
    enabled: false
actions:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ trigger.event.data.text in ['/start', '/menu', 'menu', 'Menu']
              }}
            alias: menu
        sequence:
          - data:
              target: "{{ trigger.event.data.chat_id }}"
              message: Бот мониторинга воды
              inline_keyboard:
                - Проверить статус:/checkstatus
                - Тест датчика воды:/testwater
                - Тест светодиода:/testled
              config_entry_id: 01K02EC6xxxxF11YQHFCP3
            action: telegram_bot.send_message
      - conditions:
          - condition: template
            value_template: >-
              {{ trigger.event.data.text in ['/checkstatus', 'checkstatus',
              'Checkstatus', '1'] }}
        sequence:
          - data:
              target: "{{ trigger.event.data.chat_id }}"
              message: Проверяю...
              config_entry_id: 01K02EC6xxxxx11YQHFCP3
            action: telegram_bot.send_message
          - data:
              target: "{{ trigger.event.data.chat_id }}"
              message: >
                🔍 Статус системы: 💧 Уровень воды: {% if
                is_state('binary_sensor.botwater_water_level_high', 'on') %}🔴
                ВЫСОКИЙ (ОПАСНО!){% else %}🟢 НОРМАЛЬНЫЙ{% endif %} 🚰 Насос: {%
                if is_state('binary_sensor.botwater_water_pump_status', 'on')
                %}🔴 НЕТ НАПОРА{% else %}🟢 НАПОР ОК{% endif %} 📊 Sensor: {{
                states('sensor.botwater_pump_led_sensor') }}V
              config_entry_id: 01K02xxxxF11YQHFCP3
            action: telegram_bot.send_message
        alias: checkstatus
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.text in ['/testwater', 'testwater'] }}"
        sequence:
          - target:
              entity_id: button.botwater_test_water_level
            action: button.press
            data: {}
        alias: testwater
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.text in ['/testled', 'testled'] }}"
        sequence:
          - target:
              entity_id: button.botwater_test_led
            action: button.press
            data: {}
        alias: testled
    default:
      - data:
          target: "{{ trigger.event.data.chat_id }}"
          message: Неизвестная команда
          config_entry_id: 01K02EC65xxxxxx1YQHFCP3
        action: telegram_bot.send_message
        enabled: false
mode: single

Anything in the logs that might be useful for us?

In automation trigger this data:

variables:
  trigger:
    id: "0"
    idx: "0"
    alias: null
    platform: event
    event:
      event_type: telegram_text
      data:
        id: 5357
        chat_id: 1234556789
        date: "2025-07-31T21:51:27+00:00"
        message_thread_id: null
        text: status
        user_id: 1234556789
        from_first: Vasiliy
        from_last: null
      origin: LOCAL
      time_fired: "2025-07-31T21:51:28.005542+00:00"
      context:
        id: 01K1HxxxxxxWB0PAEEX1RGYMQ
        parent_id: null
        user_id: null
    description: event 'telegram_text'
context:
  id: 01K1H7FZxxxxxAEEX1RGYMQ
  parent_id: null
  user_id: null

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions