Extract info from chatbot

Hi everyone,

Need some help for extracting information that I'm receiving using Telegram with the chatbot.
I need to send some words that will trigger what I need, in this case a a gate node.
When I copy the path from the message content I receive the path os "payload.content", if I use that for a switch node, nothing is === to /toggle.
What I'm doing wrong?


,

Thanks

Tete

how have you set the switch node rule? did you select msg from the dropdown list, or did you leave it as A/Z?

Hi,

I'm using msg.

Tete

Please post your flow , so we can see what is happening.

Sorry for the delay.
This is the flow.
flows.json (3.3 KB)

All the best,

Tete

I see nothing wrong, are you sure the incoming message from the receiver node is outputting msg.payload.content? Could you capture the message in a debug using complete message setting, and use the copy value button to copy the complete message, and paste here in text format.

P.S. use the </> button to post the result.

{"originalMessage":{"message_id":91,"from":{"id":785831859,"is_bot":false,"first_name":"TT","username":"tete","language_code":"en"},"chat":{"id":785831859,"first_name":"TT","username":"tete","type":"private"},"date":1650210291,"text":"/toggle","entities":[{"offset":0,"length":7,"type":"bot_command"}],"chatId":785831859,"userId":785831859,"messageId":91,"transport":"telegram","language":"en","ts":"2022-04-17T15:44:51.000Z"},"payload":{"type":"message","chatId":785831859,"userId":785831859,"ts":"2022-04-17T15:44:51.000Z","transport":"telegram","inbound":true,"content":"/toggle","arguments":[]},"_msgid":"2239b513712bafe1"}

The problem is that everything seems right, and I'm stuck in this, without any success in detecting the error.

Tete

Everything is fine there to.
Have you you tried deleting the flow and adding new nodes. Are all the nodes wired correctly? try moving nodes and check for bypass wires.
I use node-red-contrib-telegrambot so unable to run your flow.
Does the switch output to otherwise, as it should if the switch does not recognised "/toggle".

can you clear the debug and give the debug node a name, then show us a screenshot of the debug message including the time and name, just incase your crop removed some thing.

Hi again,

This is with the node-red-contrib-telegrambot:

{"payload":{"chatId":785831859,"messageId":94,"type":"message","content":""},"originalMessage":{"message_id":94,"from":{"id":785831859,"is_bot":false,"first_name":"TT","username":"tete","language_code":"en"},"chat":{"id":785831859,"first_name":"TT","username":"tete","type":"private"},"date":1650212239,"text":"/toggle","entities":[{"offset":0,"length":7,"type":"bot_command"}]},"_msgid":"bccdc722e77afe84"}

the path for the switc is originalMessage.text, and this is the flow:

[{"id":"bfd968a9974ea2e3","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"c73331c92dd9e628","type":"telegram command","z":"bfd968a9974ea2e3","name":"/toggle","command":"/toggle","description":"","registercommand":false,"language":"","bot":"","strict":false,"hasresponse":false,"useregex":false,"removeregexcommand":false,"outputs":1,"x":170,"y":440,"wires":[["1536e074d67162f6","27f2863923cc7d38"]]},{"id":"1536e074d67162f6","type":"switch","z":"bfd968a9974ea2e3","name":"toggle, open, close","property":"originalMessage.text","propertyType":"msg","rules":[{"t":"eq","v":"/toggle","vt":"str"},{"t":"eq","v":"open","vt":"str"},{"t":"eq","v":"close","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":470,"y":440,"wires":[["4b91581b8d13357d"],["3d6e6e189586eb93"],["16e9f4a703e5eff0"],["d79b0546e6d370ce"]]},{"id":"3d6e6e189586eb93","type":"debug","z":"bfd968a9974ea2e3","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":400,"wires":[]},{"id":"16e9f4a703e5eff0","type":"debug","z":"bfd968a9974ea2e3","name":"3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":440,"wires":[]},{"id":"d79b0546e6d370ce","type":"debug","z":"bfd968a9974ea2e3","name":"4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":480,"wires":[]},{"id":"27f2863923cc7d38","type":"debug","z":"bfd968a9974ea2e3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":290,"y":500,"wires":[]},{"id":"4b91581b8d13357d","type":"debug","z":"bfd968a9974ea2e3","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":360,"wires":[]}]

/toggle is just the exemple, but I already tried "open", "close" and "toggle".

Tete

That is working fine my end with telegrambot.
as you can see in image

I wanted to see the image from your chatbot telegram flow. Please could you try again with that telegram chatbot. As i suspect there is missing info not in original image.

Did it output to otherwise? the image does not show two messages.
if it did not then the issue is in the switch node. I would try deleting the flow and tab and start again.

Hi,

Yes, it did output for the otherwise.
I just installed a new raspberry with the node red (just in case), made everything from scratch and I still have the same problem.
Can you please send your flow, just as last resort?

Tete

Can you also try. “contains” toggle ?

Sure
here is the command one

[{"id":"c73331c92dd9e628","type":"telegram command","z":"bf9e1e33.030598","name":"/toggle","command":"/toggle","description":"","registercommand":false,"language":"","bot":"125415a2.b4e0e2","strict":false,"hasresponse":false,"useregex":false,"removeregexcommand":false,"outputs":1,"x":120,"y":1260,"wires":[["1536e074d67162f6","27f2863923cc7d38"]]},{"id":"1536e074d67162f6","type":"switch","z":"bf9e1e33.030598","name":"toggle, open, close","property":"originalMessage.text","propertyType":"msg","rules":[{"t":"eq","v":"/toggle","vt":"str"},{"t":"eq","v":"open","vt":"str"},{"t":"eq","v":"close","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":420,"y":1260,"wires":[["4b91581b8d13357d"],["3d6e6e189586eb93"],["16e9f4a703e5eff0"],["d79b0546e6d370ce"]]},{"id":"27f2863923cc7d38","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":240,"y":1320,"wires":[]},{"id":"4b91581b8d13357d","type":"debug","z":"bf9e1e33.030598","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":700,"y":1180,"wires":[]},{"id":"3d6e6e189586eb93","type":"debug","z":"bf9e1e33.030598","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":700,"y":1220,"wires":[]},{"id":"16e9f4a703e5eff0","type":"debug","z":"bf9e1e33.030598","name":"3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":700,"y":1260,"wires":[]},{"id":"d79b0546e6d370ce","type":"debug","z":"bf9e1e33.030598","name":"4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":700,"y":1300,"wires":[]},{"id":"125415a2.b4e0e2","type":"telegram bot","botname":"mybot","usernames":"","chatids":"-1001361034082","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]

and here is one with receiver node

[{"id":"924e655b.62c95","type":"telegram receiver","z":"bf9e1e33.030598","name":"","bot":"125415a2.b4e0e2","saveDataDir":"","filterCommands":false,"x":120,"y":1260,"wires":[["1536e074d67162f6","27f2863923cc7d38"],[]]},{"id":"1536e074d67162f6","type":"switch","z":"bf9e1e33.030598","name":"toggle, open, close","property":"originalMessage.text","propertyType":"msg","rules":[{"t":"eq","v":"/toggle","vt":"str"},{"t":"eq","v":"open","vt":"str"},{"t":"eq","v":"close","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":420,"y":1260,"wires":[["4b91581b8d13357d"],["3d6e6e189586eb93"],["16e9f4a703e5eff0"],["d79b0546e6d370ce"]]},{"id":"27f2863923cc7d38","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":240,"y":1320,"wires":[]},{"id":"4b91581b8d13357d","type":"debug","z":"bf9e1e33.030598","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":700,"y":1180,"wires":[]},{"id":"3d6e6e189586eb93","type":"debug","z":"bf9e1e33.030598","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":700,"y":1220,"wires":[]},{"id":"16e9f4a703e5eff0","type":"debug","z":"bf9e1e33.030598","name":"3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":700,"y":1260,"wires":[]},{"id":"d79b0546e6d370ce","type":"debug","z":"bf9e1e33.030598","name":"4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":700,"y":1300,"wires":[]},{"id":"125415a2.b4e0e2","type":"telegram bot","botname":"mybot","usernames":"","chatids":"-1001361034082","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]

Both work and output two messages.

Hi,

Using your flow and changing to the "contains" suggested by dceejay, the message with the "close" goes out in the second output, like you sent does not go out. So at least now I have an output to the right "gate", the problem now is that the output isn't "clean", so I can't activate the simple gate, with the commands, open, close and toggle.
The message is like the one in the image.

Tete

Hi,

I just solved in a archaic form, but it's solved.



Many thanks for all the help!

All the best,

Tete

1 Like

Hi,

Now I have a problem with the switch node, it's getting bigger:


Is there any alternative for this system? I know that in NR there is more than a option for the same problem, but this is the only one, that I know.

All the best,

Tete

It depends what you are doing with the result.

For example, if those last 6 HTTP requests perform something like http://fixed-ip/variable_path and variable_path is the value coming from telegram, then you can make the URL by adding variable_path to http://fixed-ip/

Also, you could restructure the commands to make the whole thing more dynamic. e.g. /command door open and /command door close then you can direct all door items to a single output that understands open and close and any future commands like, for example status.

Hi,

I have everything that I need in the Telegram, so there is a mix of items.
For instance, this one is to close a gate in NR to stop receiving alerts of movement in a determinate sensor:


Then I have for the info about the WAN IP.
5x HTTP request for CCTV
and 1 to turn off a light.

Tete