Can't get Telegram inline_keyboard to work

I have a Telegram bot setup but cannot get any inline_keyboard commands to work. I have a test automation that turns off a light for “/command1.” If I manually type /command1 in Telegram, the light turns off. If I set up a notification with the keyboard parameter, the Command1 button turns off the light. But, if I use the inline_keyboard setup for my notification, clicking the Command1 button in Telegram just shows a spinning circle and nothing happens.

I have tried both polling and webhooks.
I have tried both parse_modes
Not sure where else to go.

inline_keyboard looks so much cleaner and professional to me so it would be nice to get it working. Here is my config:

CONFIG

telegram_bot:
  - platform: polling
    parse_mode: html
    api_key: !secret telegram_bot
    allowed_chat_ids:
      - chat id

NOTIFY

- name: test_telegram
  platform: telegram
  chat_id: chat id

AUTOMATION 1

  - alias: Telegram test2
    trigger:
      - platform: event
        event_type: telegram_command
        event_data:
          command: '/command1'
    action:
      - service: light.turn_off
        entity_id: light.upstairs

AUTOMATION 2

  - alias: test telegram
    trigger:
      - platform: state
        entity_id: light.upstairs
        to: 'on'
    action:
      - service: notify.test_telegram
        data:
          title: 'This is a test message'
          message: 'Hello there this is a test'
          data:
            inline_keyboard:
              - "/command1"

Figured it out. I have to use the telegram_callback event type for inline_keyboards.

1 Like

Can you please share the working configuration? I’m facing the same problem right now. Tried it with the telegram_callback event allready, but it’s not working.

What I want to do is to send an message to the bot (like /ping ) and in return he sends me a reply with the inline keyboard where I can select a command that should be executed.

1 Like

anyone found the solution? is this a bug within home assistant?

This is part of my telegram configuration. I use it to control lights, creating hass backup and sending it with telegram etc.

###################
# Telegram, Notify
###################

- id: '4000'
  alias: 'startup notification'
  initial_state: true
  hide_entity: true
  trigger:
    - platform: homeassistant
      event: start
  action:
    - service: notify.telegram
      data:
        message: 'Automata started'
        data:
          keyboard:
            - '/start'
    - service: notify.telegram
      data:
        message: 'Control panel'
        data:
          inline_keyboard:
            - 'Lights:/lights, Status:/status, Security:/security'
            - 'System:/system, Help:/help'

- id: '4001'
  alias: 'telegram alarm'
  hide_entity: true
  trigger:
    - platform: event
      event_type: telegram_callback
      event_data:
        data: '/security'
  action:
    - service: telegram_bot.answer_callback_query
      data_template:
        callback_query_id: '{{ trigger.event.data.id }}'
        message: 'Alarm control'
    - service: telegram_bot.edit_message
      data_template:
        message_id: 'last'
        chat_id: '{{ trigger.event.data.user_id }}'
        message: >
            {% if is_state("input_boolean.burglar_alarm_door", "off") %}Alarm is OFF. {% else %}Alarm is ON. {% endif %}
            {% if is_state("input_boolean.away_scene", "off") %}Presence simulation is OFF. {% else %}Presence simulation is ON. {% endif %}
        inline_keyboard:
          - 'Away ON:/away_on, Away OFF:/away_off'
          - 'Alarm ON:/alarm_on, Alarm OFF:/alarm_off, Cancel:/cancel'

- id: '4002'
  alias: 'telegram activate alarm'
  hide_entity: true
  trigger:
    - platform: event
      event_type: telegram_callback
      event_data:
        data: '/alarm_on'
  action:
    - service: homeassistant.turn_on
      entity_id: input_boolean.burglar_alarm_door
    - delay: '00:00:01'
    - service: telegram_bot.answer_callback_query
      data_template:
        callback_query_id: '{{ trigger.event.data.id }}'
        message: 'Alarm control'
    - service: telegram_bot.edit_message
      data_template:
        message_id: 'last'
        chat_id: '{{ trigger.event.data.user_id }}'
        message: >
            {% if is_state("input_boolean.burglar_alarm_door", "off") %}Alarm is OFF. {% else %}Alarm is ON. {% endif %}
            {% if is_state("input_boolean.away_scene", "off") %}Presence simulation is OFF. {% else %}Presence simulation is ON. {% endif %}
        inline_keyboard:
          - 'Away ON:/away_on, Away OFF:/away_off'
          - 'Alarm ON:/alarm_on, Alarm OFF:/alarm_off, Cancel:/cancel'

- id: '4003'
  alias: 'telegram deactivate alarm'
  hide_entity: true
  trigger:
    - platform: event
      event_type: telegram_callback
      event_data:
        data: '/alarm_off'
  action:
    - service: homeassistant.turn_off
      entity_id: input_boolean.burglar_alarm_door
    - delay: '00:00:01'
    - service: telegram_bot.answer_callback_query
      data_template:
        callback_query_id: '{{ trigger.event.data.id }}'
        message: 'Alarm control'
    - service: telegram_bot.edit_message
      data_template:
        message_id: 'last'
        chat_id: '{{ trigger.event.data.user_id }}'
        message: >
            {% if is_state("input_boolean.burglar_alarm_door", "off") %}Alarm is OFF. {% else %}Alarm is ON. {% endif %}
            {% if is_state("input_boolean.away_scene", "off") %}Presence simulation is OFF. {% else %}Presence simulation is ON. {% endif %}
        inline_keyboard:
          - 'Away ON:/away_on, Away OFF:/away_off'
          - 'Alarm ON:/alarm_on, Alarm OFF:/alarm_off, Cancel:/cancel'

- id: '4004'
  alias: 'telegram ping pong'
  hide_entity: true
  trigger:
    - platform: event
      event_type: telegram_callback
      event_data:
        data: '/ping'
  action:
    - service: telegram_bot.answer_callback_query
      data_template:
        callback_query_id: '{{ trigger.event.data.id }}'
        message: >-
          Callback received from {{ trigger.event.data.from_first }}.
          Message id: {{ trigger.event.data.message.message_id }}.
          Data: {{ trigger.event.data.data }}
          {{now().strftime("%H:%M:%S %Y-%m-%d")}} Pong, Message from {{ trigger.event.data["user_id"] }}.
        show_alert: true

- id: '4005'
  alias: 'telegram control'
  hide_entity: true
  trigger:
    - platform: event
      event_type: telegram_command
      event_data:
        command: '/start'
  action:
    - service: notify.telegram
      data:
        message: 'Control panel'
        data:
          inline_keyboard:
            - 'Lights:/lights, Status:/status, Security:/security'
            - 'System:/system, Help:/help'
6 Likes