Home Assistant Community

Telegram - sending commands to trigger flows and questions

#1

Hi all - firstly, I know this isn’t a telegram forum, but I know a lot of folks use it within their flows. I have never used telegram in this manner, so I"m a complete rookie - so please be gentle :slight_smile:

I ran across this awesome setup: [HowTo] Setting up a Telegram Bot for all your Home Automation messages

After further research, I learned that this isn’t really new, but I just learned about it. It makes alerting very easy without having to open up anything externally or remaining connected via VPN to your home network. Works for what I had in mind and it was fairly simple to setup, but I have a few questions.

  1. Privacy: How do we keep our bots private? I was able to test and it’s reachable by anyone and will accept /start from anyone that chats it. How do we prevent this and make it private and only reachable by me?

I was also able to chat the bot and send messages to my Node Red flow, eventhough I had a chatid specified.

Either I’m doing it very wrong or it is what it is.

  1. Placing the same bot (node) in another tab(flow) I receive an error about single instance - any ideas? Do I have to create a bot for each tab where I want to use the bot? or am I doing something wrong.

  2. I want to trigger some actions using the receiver node, but I don’t know how to extract a payload from the message when received?

Again, I know this isn’t a Telegram forum, but I know that a lot of folks are using Telegram in one way or another.

#2

1 - Did you add your user ID to your bot chatbot-Telegram-node configuration?
Secondly, check your bot settings by using the BotFather -bot.

2 - Answered it all ready on [HowTo] Setting up a Telegram Bot for all your Home Automation messages

3 - It is stored in msg.payload.content. You can use a change-node to move it or a function node with coding.

For debugging please use a debug-node with ‘complete message’ enabled. You can see the complete content of the received message and check debug window on the right site. That’s how I learned the basics of NR. (with a lot of trial and error :wink:)

1 Like
#3

Hey thanks! Appreciate the help

Yes, I’ve added the chat ID and tested, no one outside that chat can see what’s sent to it.

I was wondering what else was there to security - does this mean anyone can chat my boy or even send it commands? What can someone do with my not. I guess that’s what I’m asking. Sorry I’m super new to telegram.

Commands on botfather are limited it seems. What do I check?

I can see where the payload is stored as I use debug nodes all the time, so do I set the change node to look for message.payload.content?

Thanks again!

#4

Check if your bot has the privacy setting enabled. This can be done by talking to @BotFather with the command /mybots.

Check this page with further info about Telegram bots:


Depends what are you trying to do. If you want to execute commands when sending a specific command is set, just try the command-node and, for example, the buttons mode:
afbeelding
In above example when the user sends /m it will send back a button menu, which you can configure yourself (all command has to start with / ).

1 Like
#5

K - so doing a lot more tinkering and slowly making progress.

Now I understand that outputs on the nodes - authorized us unauthorized and whether the expected commands are sent.

Still don’t understand the limited privacy options of the bot, but it is what it is I guess.

I accomplished what I wanted at the moment. I think I just need to keep at it and eventually I’ll get what I’m after.

Thank you again for all your help!

#6

You are more then welcome! :vulcan_salute::smile:
.

Those blue nodes are not from the Node-Red package node-red-contrib-chatbot, as far as I know. :face_with_raised_eyebrow:
That could explain the strange behaviours you are reporting! :thinking:

#7

Correct, it’s another telegram package. It actually is the only one I can make work for commands inbound. Outbound I can use the yellow nodes - the one you’re using.

Odd indeed, but whatever works.

#8

You should be aware that using an other package could be causing strange errors because the variables used (object infrastructure) could be different…

IMHO, you just should use only one package and stick with it. Just my two cents… :slightly_smiling_face:

#9

I agree, but I can’t get away from the multiple instance error.

I’ll keep trying.

#10

What happens in your debug-window when doing this?
afbeelding

#11

BTW, do you have, by any change, multiple bots with the same configuration in your configuration nodes?

afbeelding
You can find these in the most right pulldown button.

#12

I see the auth and unath content… So that’s working fine.

#13

Okay, so you can receive the message send to you (msg.payload.content).

Can you configure a button-node (in example Main Menu) and connect a Telegram Sender to it:

For further development, enable the Pass Through option in the Telegram Sender (for connecting debug nodes for example or activation buttons when pressed)

Example for the Main Menu node Message content:
❓ Please enter your choice {{firstName}}:

#14

So you sort of beat me to it.

This seems to work

image

Seems if I don’t use the “Authorized” node, any message sent to the bot will be received. Eventhough I’ve entered my user in the “Users” field.

Very odd.

#15

Not really. The user in the configuration node is used for sending messages to the specific users, not for receiving.

Next step, you can add a button to send the /as command in the Menu Node:

afbeelding

To execute the command you can add the specific command to execute it by Telegram.

Just one moment, I will create an example…

#16

So you’re actually already doing what I’m wanting to do - but it seems you have it setup way easier and more convenient… Do you mean that there will be buttons within the bot and I can just choose to arm and disarm by clicking them?

If so, that would be awesome.

If you could somehow (remote private info) share the raw flow, that would be greatly appreciated. I can hack through that.

The way I’m trying to do this is much more difficult than it needs to be.

#17

You can add the three options as buttons to your Main Menu and connect a command-node to received-node, like this:

The output of the command-node are the node which will essentially execute your command for arming and disarming your house.

I rather try to help you step by step, so other forum users can also learn from this, if you don’t mind.

#18

Just an example of a tiny piece of my setup:
afbeelding

That’s a reason why I don’t share my setup, it would be bit overwhelming I think…:wink:

Just let me know if you’re ready for the next step.

#19

Sure - I don’t mind working through it. I was tying to not waste your time… Appreciate your will to assist and stick with me.

So I set up the main menu node to look like yours, but how do I get the buttons configured to come up?

1 Like
#20

The Node which has ‘Main Menu’ on it, add a button, like I did on the post