GleDel
(Gle Del)
March 15, 2018, 1:16pm
1
Hello. I’ve been working on my hass setup for a couple of days now and it has been a real struggle so far. Slowly I’m getting there though.
I’m trying to set up a telegram bot that replies in the correct conversation:
- alias: 'Telegram bot start command'
hide_entity: true
trigger:
platform: event
event_type: telegram_command
event_data:
command: '/start'
action:
- service: telegram_bot.send_message
data_template:
target: '{{ trigger.event.data.chat_id }}'
title: '*Command control*'
message: 'What would you like me to do?'
inline_keyboard:
- 'Ping:/ping, Chat Info:/chatinfo'
- 'Exit:/exit'
This is working fine. It’s responding to the command in the correct chat.
Then I tried to answer the ‘Ping’ with 'Pong
- alias: 'Telegram bot that reply pong to ping'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
command: '/ping'
action:
- service: telegram_bot.send_message
data_template:
message: 'Pong'
This is working. Except that it’s always replying with pong to the default chat-id.
So I tried adding target:'{{ trigger.event.data.chat_id }}'
This is my code now:
- alias: 'Telegram bot that reply pong to ping'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
command: '/ping'
action:
- service: telegram_bot.send_message
data_template:
target:'{{ trigger.event.data.chat_id }}'
message: 'Pong'
But now I’m getting this error and I can’t figure out why that is:
Configuration invalid
Testing configuration at /config
ERROR:homeassistant.util.yaml:mapping values are not allowed here
in “/config/automation/telegram_bot.yaml”, line 29, column 16
Failed config
General Errors:
- mapping values are not allowed here
in “/config/automation/telegram_bot.yaml”, line 29, column 16
Successful config (partial)
Any help?
Thanks!
taikapanu
(Juha Panu)
March 15, 2018, 7:14pm
2
Telegram cant handle uneven number of _ marks.
opened 03:16PM - 08 Feb 16 UTC
closed 06:20PM - 18 May 16 UTC
Hi there!
Thanks for your cool API, really easy to use.
I found a problem when trying to send messages that contains underscores.
I...
vladosam
(Vladimir)
March 15, 2018, 7:38pm
3
This telegram ping - pong works for me:
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
1 Like
GleDel
(Gle Del)
March 16, 2018, 8:26am
4
Your code works. But what i want is for telegram to send a normal message. As if it’s just relying.
vladosam
(Vladimir)
March 16, 2018, 8:35am
5
This should work.
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Message'
1 Like
GleDel
(Gle Del)
March 16, 2018, 9:24am
6
This Works.
However. Doesn’t matter wich button im pressing. I’s seems to execute the ping command even if I’m pressing another command
vladosam
(Vladimir)
March 16, 2018, 9:31am
7
Lets see your telegram yaml. It’s hard to help without it.
GleDel
(Gle Del)
March 16, 2018, 9:54am
8
configuration.yaml
telegram_bot:
- platform: polling
api_key: !secret telegram_api
allowed_chat_ids:
- !secret telegram_chat_id_glenn
- !secret telegram_chat_id_group
- !secret telegram_chat_id_ellen
Automation
- alias: 'Telegram bot start command'
hide_entity: true
trigger:
platform: event
event_type: telegram_command
event_data:
command: '/start'
action:
- service: telegram_bot.send_message
data_template:
target: '{{ trigger.event.data.chat_id }}'
title: '*Command control*'
message: 'What would you like me to do?'
inline_keyboard:
- 'Ping:/ping, Chat Info:/chatinfo'
- 'Exit:/exit'
- alias: 'Telegram bot that reply pong to ping'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
command: '/ping'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Pong'
As you can see I have three buttons. every button responds to the /ping command.
I tried adding automation for the other buttons but that resluts in evry automation being executed no matter what button is being pressed.
Here’s the code for those other automations:
- alias: 'Exit'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
command: '/exit'
action:
- service: telegram_bot.delete_message
data_template:
message_id: '{{ trigger.event.data.message.message_id }}'
chat_id: '{{ trigger.event.data.chat_id }}'
- alias: 'Chat info test'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
command: '/chatinfo'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Test Chatinfo'
vladosam
(Vladimir)
March 16, 2018, 10:15am
9
That is strange. It has to be something with your ‘Telegram bot start command’.
This is my telegram /start command.
- 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'
I would also change that chat info command to something like Chatinfo.
GleDel
(Gle Del)
March 16, 2018, 10:36am
10
vladosam:
notify.telegram
I need the telegram_bot.send_message
command because in need the bot to reply in the correct chat.
I keep getting the same problem… Every button executes all commands
vladosam
(Vladimir)
March 16, 2018, 10:55am
11
So if you press ping it also execute /chatinfo and /exit?
Try to replace
trigger:
platform: event
event_type: telegram_callback
event_data:
command: '/ping'
with
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/ping'
GleDel
(Gle Del)
March 16, 2018, 12:24pm
12
Unfortunately still the same
vladosam
(Vladimir)
March 16, 2018, 1:51pm
13
I tried to recreate your setup with only two buttons. And this work. But i test it with only one user. Try it and see what happens.
- alias: 'Telegram bot start command'
hide_entity: true
trigger:
platform: event
event_type: telegram_command
event_data:
command: '/start'
action:
- service: telegram_bot.send_message
data_template:
target: '{{ trigger.event.data.chat_id }}'
title: '*Command control*'
message: 'What would you like me to do?'
inline_keyboard:
- 'Ping:/ping, Chat Info:/chatinfo'
# - 'Exit:/exit'
- alias: 'Telegram bot that reply pong to ping'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/ping'
action:
- service: telegram_bot.send_message
data_template:
target: '{{ trigger.event.data.chat_id }}'
message: 'Pong'
- alias: 'Chat info test'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/chatinfo'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Test Chatinfo'
show_alert: true
Yevgeniy
(Yevgeniy)
March 16, 2018, 2:17pm
14
I have same problem. Platform: polling.
vladosam
(Vladimir)
March 16, 2018, 2:27pm
15
I’m also using telegram with pooling all the time. But that never happened to me. Try this code i posted before.
Yevgeniy
(Yevgeniy)
March 16, 2018, 6:36pm
16
I found the mistake in my automations. It must be data: '/command'
on the event_data section if I use telegram_callback. Thank you!
1 Like
vladosam
(Vladimir)
March 16, 2018, 6:47pm
17
Great. I’m glad you fix it.
1 Like
GleDel
(Gle Del)
March 20, 2018, 12:35pm
18
I’ll give this a try later today.
GleDel
(Gle Del)
March 20, 2018, 5:26pm
19
This also did it for me. I had one instance where i was using command
instead of data
Thanks for the help @vladosam and @Yevgeniy
@vladosam i have a doubt… me and my wife using telegram.
so… if i want to make an automation only for her, and other for me…
what i would put on this line??
target: ‘{{ trigger.event.data.chat_id }}’
???