Telegram - Send and Receive Actions

Hello,

I have complete my telegram's bot setup and I am trying to open a switch using command "true" and close it using "false" respectively (telegram app). I also want to receive a feedback of these actions in my telegram chatbot. The problem is that I only receive a message on the debug that states chatId, messageId, type, content and date. I have set the following settings for when I type true in my chatbot but nothing appears. Are there any ideas to make it work?

Thanks for your time, appreciate your help !

image
image

Current Flow

[{"id":"e965d4b7.df8638","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"a5542607.d53408","type":"ui_switch","z":"e965d4b7.df8638","name":"Switch","label":"","tooltip":"","group":"c8de5ff4.0911e","order":4,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"payload.content","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"x":330,"y":120,"wires":[["272d5eb8.4d9932"]]},{"id":"c96f3c47.a5a65","type":"telegram receiver","z":"e965d4b7.df8638","name":"","bot":"2f6c1f7b.9d7c1","saveDataDir":"","filterCommands":false,"x":130,"y":120,"wires":[["b7cb05c3.8c0f38","a5542607.d53408"],[]]},{"id":"272d5eb8.4d9932","type":"switch","z":"e965d4b7.df8638","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":120,"wires":[["35cf774b.1cf948"],["5b0e35b2.b8fe2c"]]},{"id":"b7cb05c3.8c0f38","type":"debug","z":"e965d4b7.df8638","name":"Telegram Debugger","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":310,"y":180,"wires":[]},{"id":"35cf774b.1cf948","type":"change","z":"e965d4b7.df8638","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"{\"type\":\"message\",\"content\":\"Sprinkler Activated\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":100,"wires":[["1f76f2e4.4f97dd"]]},{"id":"5b0e35b2.b8fe2c","type":"change","z":"e965d4b7.df8638","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"{\"type\":\"message\",\"content\":\"Sprinkler Deactivated\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":140,"wires":[["1f76f2e4.4f97dd"]]},{"id":"1f76f2e4.4f97dd","type":"telegram sender","z":"e965d4b7.df8638","name":"","bot":"2f6c1f7b.9d7c1","haserroroutput":false,"outputs":1,"x":910,"y":120,"wires":[[]]},{"id":"c8de5ff4.0911e","type":"ui_group","name":"NewWidget","tab":"93b99af0.cadfa8","order":2,"disp":true,"width":"6","collapse":false},{"id":"2f6c1f7b.9d7c1","type":"telegram bot","botname":"christs99_bot","usernames":"","chatids":"","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},{"id":"93b99af0.cadfa8","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Have you looked at the 'examples' for 'telegrambot' as this one might be useful.

[{"id":"f0f40237.40f438","type":"function","z":"117ca2b6.9952d5","name":"create question","func":"msg.payload.type = 'message';\nmsg.payload.content = 'Really?';\nmsg.payload.options = {reply_to_message_id : msg.payload.messageId}\n\nreturn [ msg ];\n","outputs":"1","noerr":0,"initialize":"","finalize":"","x":290,"y":3480,"wires":[["7705422f.822834"]]},{"id":"4c7274da.77331c","type":"telegram command","z":"117ca2b6.9952d5","name":"/foo","command":"/foo","bot":"d086776c.7de82","strict":false,"hasresponse":false,"x":110,"y":3480,"wires":[["f0f40237.40f438"]]},{"id":"7705422f.822834","type":"telegram sender","z":"117ca2b6.9952d5","name":"send question","bot":"d086776c.7de82","x":500,"y":3480,"wires":[["b84786d5.195848"]]},{"id":"b84786d5.195848","type":"telegram reply","z":"117ca2b6.9952d5","name":"get reply","bot":"d086776c.7de82","x":675,"y":3480,"wires":[["29d8ebcb.f400fc"]]},{"id":"29d8ebcb.f400fc","type":"function","z":"117ca2b6.9952d5","name":"switch answer","func":"if(msg.payload.content === 'Yes')\n{\n    return [msg, null];   \n}\nelse\n{\n    return [null, msg];   \n}\n","outputs":"2","noerr":0,"initialize":"","finalize":"","x":847,"y":3480,"wires":[["6a50edd.6235114"],["b599b2a2.4b0278"]]},{"id":"6a50edd.6235114","type":"debug","z":"117ca2b6.9952d5","name":"Yes","active":true,"console":"false","complete":"payload","x":1050,"y":3460,"wires":[]},{"id":"b599b2a2.4b0278","type":"debug","z":"117ca2b6.9952d5","name":"No","active":true,"console":"false","complete":"payload","x":1050,"y":3500,"wires":[]},{"id":"d086776c.7de82","type":"telegram bot","z":"","botname":"HeinzBot","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]

Hello,

I checked this flow but I am still facing the problem. I inserted "id" on change nodes but still nothing appears...

[{"id":"f89b2d29.a83e9","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"5b12d628.937dd8","type":"ui_switch","z":"f89b2d29.a83e9","name":"Sprinkler","label":"switch","tooltip":"","group":"2d70c600.e2d54a","order":4,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"payload.content","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"x":440,"y":220,"wires":[["e67db6b4.a1c958"]]},{"id":"c54b6c5c.89663","type":"telegram receiver","z":"f89b2d29.a83e9","name":"","bot":"2f6c1f7b.9d7c1","saveDataDir":"","filterCommands":false,"x":110,"y":220,"wires":[["75ec4a88.1a8f84","5b12d628.937dd8"],[]]},{"id":"e67db6b4.a1c958","type":"switch","z":"f89b2d29.a83e9","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":570,"y":220,"wires":[["2fc21b79.779b14"],["59411407.8590ac"]]},{"id":"75ec4a88.1a8f84","type":"debug","z":"f89b2d29.a83e9","name":"Telegram Debugger","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":350,"y":260,"wires":[]},{"id":"2fc21b79.779b14","type":"change","z":"f89b2d29.a83e9","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"{\"chatId\":1709611765,\"type\":\"message\",\"content\":\"Sprinkler Activated\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":200,"wires":[["29d05abf.7d0cc6"]]},{"id":"59411407.8590ac","type":"change","z":"f89b2d29.a83e9","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"{\"chatId\":1709611765,\"type\":\"message\",\"content\":\"Sprinkler Deactivated\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":240,"wires":[["29d05abf.7d0cc6"]]},{"id":"29d05abf.7d0cc6","type":"telegram sender","z":"f89b2d29.a83e9","name":"","bot":"2f6c1f7b.9d7c1","haserroroutput":false,"outputs":1,"x":950,"y":220,"wires":[[]]},{"id":"2d70c600.e2d54a","type":"ui_group","name":"Example","tab":"c0a2130d.da022","order":1,"disp":true,"width":"6","collapse":false},{"id":"2f6c1f7b.9d7c1","type":"telegram bot","botname":"christs99_bot","usernames":"","chatids":"","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},{"id":"c0a2130d.da022","type":"ui_tab","name":"Alarm","icon":"dashboard","disabled":false,"hidden":false}]

Thanks for your time, appreciate your help.

try...

[{"id":"5b12d628.937dd8","type":"ui_switch","z":"f89b2d29.a83e9","name":"Sprinkler","label":"switch","tooltip":"","group":"2d70c600.e2d54a","order":4,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"payload.content","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"x":280,"y":220,"wires":[["e67db6b4.a1c958"]]},{"id":"e67db6b4.a1c958","type":"switch","z":"f89b2d29.a83e9","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":220,"wires":[["2fc21b79.779b14"],["59411407.8590ac"]]},{"id":"2fc21b79.779b14","type":"change","z":"f89b2d29.a83e9","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"chatId\":1709611765,\"type\":\"message\",\"content\":\"Sprinkler Activated\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":200,"wires":[["29d05abf.7d0cc6"]]},{"id":"59411407.8590ac","type":"change","z":"f89b2d29.a83e9","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"chatId\":1709611765,\"type\":\"message\",\"content\":\"Sprinkler Deactivated\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":240,"wires":[["29d05abf.7d0cc6"]]},{"id":"29d05abf.7d0cc6","type":"telegram sender","z":"f89b2d29.a83e9","name":"","bot":"2f6c1f7b.9d7c1","haserroroutput":false,"outputs":1,"x":950,"y":220,"wires":[[]]},{"id":"2d70c600.e2d54a","type":"ui_group","name":"Example","tab":"c0a2130d.da022","order":1,"disp":true,"width":"6","collapse":false},{"id":"2f6c1f7b.9d7c1","type":"telegram bot","botname":"christs99_bot","usernames":"","chatids":"","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},{"id":"c0a2130d.da022","type":"ui_tab","name":"Alarm","icon":"dashboard","disabled":false,"hidden":false}]

Hello,

I have tried it but what what I want to achieve is the following: send message "true" on telegram in order to turn on the switch and message "false" to turn off the switch.

Thanks for your help!

then use a command node that accepts commands like /sprinkler on and /sprinkler off .

e.g...

image

flow...

[{"id":"a3872cbcde741a07","type":"telegram command","z":"5d3f964c.fef898","name":"/sprinkler","command":"/sprinkler","bot":"2f6c1f7b.9d7c1","strict":false,"hasresponse":false,"useregex":false,"removeregexcommand":false,"outputs":1,"x":1300,"y":760,"wires":[["bec79bae1fceb246","6abe36ea2949f2dc"]]},{"id":"bec79bae1fceb246","type":"debug","z":"5d3f964c.fef898","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1310,"y":820,"wires":[]},{"id":"911dc47892c82122","type":"switch","z":"5d3f964c.fef898","name":"on / off / unknown","property":"originalMessage.text","propertyType":"msg","rules":[{"t":"eq","v":"/sprinkler on","vt":"str"},{"t":"eq","v":"/sprinkler off","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":1530,"y":820,"wires":[["90ac3e61b8abcbb8"],["007c07e7ea4ed46a"],["477f69d0587f8e43"]]},{"id":"e67db6b4.a1c958","type":"switch","z":"5d3f964c.fef898","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":1490,"y":980,"wires":[["2fc21b79.779b14"],["59411407.8590ac"]]},{"id":"2fc21b79.779b14","type":"change","z":"5d3f964c.fef898","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"type\":\"message\",\"content\":\"Sprinkler Activated\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":1700,"y":960,"wires":[["ba8bed07b604869c"]]},{"id":"59411407.8590ac","type":"change","z":"5d3f964c.fef898","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"type\":\"message\",\"content\":\"Sprinkler Deactivated\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":1700,"y":1000,"wires":[["ba8bed07b604869c"]]},{"id":"29d05abf.7d0cc6","type":"telegram sender","z":"5d3f964c.fef898","name":"","bot":"2f6c1f7b.9d7c1","haserroroutput":false,"outputs":1,"x":1990,"y":1000,"wires":[[]]},{"id":"c13ba8d8f1052e78","type":"ui_switch","z":"5d3f964c.fef898","name":"Sprinkler","label":"switch","tooltip":"","group":"2d70c600.e2d54a","order":4,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"payload.content","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"x":1980,"y":800,"wires":[["e67db6b4.a1c958"]]},{"id":"90ac3e61b8abcbb8","type":"change","z":"5d3f964c.fef898","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1740,"y":780,"wires":[["c13ba8d8f1052e78"]]},{"id":"007c07e7ea4ed46a","type":"change","z":"5d3f964c.fef898","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1740,"y":820,"wires":[["c13ba8d8f1052e78"]]},{"id":"477f69d0587f8e43","type":"function","z":"5d3f964c.fef898","name":"Dont understand message","func":"var message = \n`\n## I dont understand 🤔\n\nMust be one of the following... \n* /sprinkler on\n* /sprinkler off\n`;\n\nmsg.payload.type = 'message';\nmsg.payload.content = message.trim();\n\n// activate markdown\nmsg.payload.options = {\n  disable_web_page_preview : true, \n  parse_mode : \"Markdown\"\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1780,"y":860,"wires":[["ba8bed07b604869c"]],"info":"## New message\n\nHello *markdown* formatted messages!'\n\nwith `inline` code\n\n> and quote\n>> nested\n\n\\`\\`\\`\nvar code = \"cool\";\n\\`\\`\\`\n\n| table | data |\n|---|---|\n| 1 | fred |\n| 2 | bob |\n\n_Italic_ **bold** "},{"id":"6abe36ea2949f2dc","type":"change","z":"5d3f964c.fef898","name":"save chatId","rules":[{"t":"set","p":"chatId","pt":"flow","to":"payload.chatId","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1490,"y":760,"wires":[["911dc47892c82122"]]},{"id":"ba8bed07b604869c","type":"change","z":"5d3f964c.fef898","name":"","rules":[{"t":"set","p":"payload.chatId","pt":"msg","to":"chatId","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1970,"y":960,"wires":[["29d05abf.7d0cc6","3ef4c1aa27fbde11"]]},{"id":"3ef4c1aa27fbde11","type":"debug","z":"5d3f964c.fef898","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2090,"y":900,"wires":[]},{"id":"2f6c1f7b.9d7c1","type":"telegram bot","botname":"christs99_bot","usernames":"","chatids":"","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},{"id":"2d70c600.e2d54a","type":"ui_group","name":"Example","tab":"c0a2130d.da022","order":1,"disp":true,"width":"6","collapse":false},{"id":"c0a2130d.da022","type":"ui_tab","name":"Alarm","icon":"dashboard","disabled":false,"hidden":false}]
1 Like

Hello again sir,
Appreciate your help, I have some theoretical questions about "property".
The following node has property of "msg.originalMessage.text", is it possible to explain what it achieves with this?
image
Is this node uses "flow.chatId" in order to be linked with all the nodes in the flow?
image
Thanks for your time sir !

First off - does it work for you?


msg.originalMessage.text comes from the text you send to the bot. It contains the full text you send. So the switch node checks to see you have entered exactly /sprinkler on or /sprinkler off

the best way to see this is look at the debug msg that comes out of the 1st node (the blue command node)

There reason I use flow.chatId is because you might not know the chatId (so I extract it from the incoming message & store it in flow context for later retrieval - thats how when operating the switch node it also sends a telegram. You can remove the flow context item if you know the chatId will never change. And yes, flow context is available to all nodes on 1 tab (global context is available on all tabs)

1 Like

It works, thanks for you explanation I am trying to see if I understand everything correctly ! I really appreciate your help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.