Command : REQUIRED command to listen for. Must start with ā/ā. Example: /start
Bot: Bot username. It is used when there is more than one bot in a group chat. Example: my_bot_username_bot
Sequence: What should happen when receiving this command.
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_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.
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.
Example: Hi {{ telegram_sender_first_name }}! You said {{ telegram_args_as_text }} after the command.
Copy-paste the content from this link to a new file inside your configurationās blueprints/automation folder.
Changelog
2022-09-03: Telegram API was updated and variables telegram_sender_first_name, telegram_sender_last_name, telegram_sender_full_name and telegram_sender_user_id are now available always.
2022-05-18: BREAKING CHANGE Variables telegram_sender_first_name, telegram_sender_last_name, telegram_sender_full_name and telegram_sender_user_id are now only available if you call a command (when you type /command in a telegram text message). If you click an inline keyboard button, these variables will not work. āReply in privateā function will only work with commands too.
2022-01-17: BREAKING CHANGE Replaced āCommand @ Bot Usernameā field with a more simple āBotā username field. Now it is not necessary to write down the command twice because it uses trigger_variables to concatenate command and bot username. Also added trigger ID.
2021-10-28: Add field āCommand @ Bot Usernameā to ensure compatibility in group chats and Chat ID variable. Improved description.
2021-10-11: Parse telegram arguments and other event data received by Home Assistant and allow to use them as variables in templates. Also updated blueprintās description.
Hi, I installed your blueprint and created the below automation. When I run it the words āTTS Testā are broadcast on the speaker. When I however type ā/say somethingā into telegram, nothing happens. My telegram integration works as I have Node-red flow that reacts to commands from telegram. I am however wanting to move away from Node-red and do everything via these automatons.
Once I get this working I would like to know how do to change things so that whatever is typed after my command, becomes the message.
Nice feature request! I just updated the blueprint definition to get event data from Telegram and set them as variables so that they are useable in templates. I also updated description for better explaining.
Furthermore, I realized that arguments from telegram commands are received as a list of single words, so I added a variable called telegram_args_as_text that transforms the list back to a string of plain text.
Now, for example, if you type /say How are you?, arguments are stored in these two variables:
Thanks for this, unfortunately, I must have a config issue. I can send notifications to Telegram but Hass does not appear to see any /commands. When I type in "/talk Hi " nothing happens.
If I install Node-Red and use the Telegram nodes there then it all works so I think I have the correct API keys and IDs but canāt get it read Telegram commands when not using Node-Red (used the same config details that I used when connecting via Node-Red.
Also tried
But the display still does not change to cast mode i.e. I do not appear to be reading the commands that are being typed in.
Use {{ telegram_args_as_text }} in message field. Without {{ }} will not be replaced with the variable. I think that TTS service doesnāt allow templates in user interface mode, so it will automatically change to YAML mode, but no problem.
To debug your configuration, you can follow these steps:
Set the message filed as You said: {{ telegram_args_as_text }}
With this configuration, Telegram Bot should respond to your message with the arguments.
Then, try to send a message to your bot like /talk How are you?. You should receive back a message saying: You said: How are you?.
Both blueprints use the same internal configuration, so if this one works, the other one should work. If it doesnāt, maybe you have some configuration issue with the action. You could try to debug it using developer tools tab in your Home Assistant instance.
āCommand @ Bot Usernameā field has been replaced with a more simple āBotā username field. Now, it is not necessary to write down the command twice because it uses trigger_variables to concatenate command and bot username.
Bot username is used when there is more than one bot in a group chat.
It is a new field, so it is necessary to set it up if you update the blueprint.
It seems that telegram bot API has changed, and some information is now not working. I just updated the blueprint to avoid using data that is causing the error.
This means that variables telegram_sender_first_name, telegram_sender_last_name, telegram_sender_full_name and telegram_sender_user_id are now only available if you call a command (when you type /command in a telegram text message). If you click an inline keyboard button, these variables will not work. āReply in privateā function will only work with commands too.
Cool blueprint. I really like to try it out, but when I click on the blue āimport blueprintā button, Iām correctly redirected to my homeassistant UI, but after clicking on the āpreview blueprintā button, it tells me the following: No valid blueprint found in the topic. Blueprint syntax blocks need to be marked as YAML or no syntax.
Iām running homeassistant version 2022.5.5, so this should be recent enough, if Iām not wrong.
Iām pretty new to homeassistant so any help is very welcome. Thanks a lot.
The telegram bot API has updated and variables telegram_sender_first_name, telegram_sender_last_name, telegram_sender_full_name and telegram_sender_user_id are back available always, with no errors!
To benefit from these updates, redownload the blueprint code!
Hi this is still working well with Google TTS but when I try using Picotts TTS, it does not work. I can get it to work with fixed text but not using the parameters i.e. {{ telegram_args_as_text }}
I am happy to use Google for now but thought I would just let you know.
You mentioned on the top of the post that there is a minimum required version of HA to use this.
You may want to consider adding this to prevent issues with people not reading thatā¦
Nice job on the Documentation, BTW. I might clone some of that. Mine tend to be , chaotic ā¦ at times.
The {{ telegram_args_as_text }} is simply taking every single word after the command into a string. For example, /say How are you? returns How are you?. It doesnāt recognize new line breaks, so if you type \n it returns the same \n, not a new line.
You say that it works with Google TTS but not with Pico TTS. I do not have Pico TTS to try it, but as long as this TTS can read text strings, it should work as well. You can check whether there is some issue with quotation marks or typing in your code. Sometimes there are slight differences between platforms that make them break if we copy-paste the same code.
I have successfully set up the above blueprint. I use it so that I can fill my shopping list via my Telegrambot. This also works, but I would like to remove the following characters from the entry.
Here is the config of the blueprint:
FĆ¼ge ich nun mit meinem Telegrambot ein Item zur Liste hinzu, macht er das zwar. Aber nur mit diesen Klammern [āā] Diese mƶchte ich aber entfernen. Wie mache ich das?
The {{ telegram_args }} is a list of all the words sent after the command. A list means that every word is considered a separate element. Thatās why they are wrapped in ['']. If you want all them as a single text string, you could try to use the {{ telegram_args_as_text }} parameter instead.