Hello node-red experts,
Greetings!!
I have been working on creating a telegram bot associated with node-red, which will ask user a series of questions and user need to respond them.
Now if you see I am expecting when a user replies to question: "Are you a new joinee?" then I have attached Telegram Reply
node which should send reply back to next switch and accordingly next actions should happen. But Telegram Reply
is NOT working. Even I have enabled traces(debug mode) to it but not getting any error in console from it.
I am a newbie in node-red and JS but tried my best to fix it here, any help will be highly appreciated.
Following is my current tried code:
[{"id":"f1ad7bfd5882cc1a","type":"tab","label":"test123456","disabled":false,"info":"","env":[]},{"id":"585d4255e238512f","type":"telegram receiver","z":"f1ad7bfd5882cc1a","name":"","bot":"6b031eeb3ef163ce","saveDataDir":"","filterCommands":false,"x":110,"y":40,"wires":[["8e4658e2b26d5bea"],[]]},{"id":"8e4658e2b26d5bea","type":"switch","z":"f1ad7bfd5882cc1a","name":"","property":"payload.content","propertyType":"msg","rules":[{"t":"regex","v":"^ *(hi|hello|hey|howdy) *$","vt":"str","case":true}],"checkall":"true","repair":false,"outputs":1,"x":110,"y":160,"wires":[["9a7653c6bb6d150d"]]},{"id":"9a7653c6bb6d150d","type":"function","z":"f1ad7bfd5882cc1a","name":"Welcome","func":"var helpMsg = \"/help - shows help\\n\\n\"\ncontext.set(\"chatId\", msg.payload.chatId)\nhelpMsg += \"/foo - opens a dialog\\n\\n\\n\"\nif (msg.payload.chatId === 7) {\n helpMsg = \"R. Singh, Welcome sir!!!! \"\n}\nelse if (msg.payload.chatId === 12) {\n helpMsg = \"Ki karda hai ghussuu :) :) :) \"\n}\nelse {\n helpMsg += \"You are welcome in Singh's bot, \" + msg.originalMessage.from.username;\n}\nhelpMsg += \"Your chat id is: \" + msg.payload.chatId;\nmsg.payload.content = helpMsg;\nmsg.payload.sentMessageId = msg.payload.chatId;\nmsg.payload.flag = msg.payload.chatId;\nconsole.log(msg + \"+++++++++++\");\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":160,"wires":[["386a0fe52619624b","133175beaeded35c","59b33f21f66de252"]]},{"id":"386a0fe52619624b","type":"debug","z":"f1ad7bfd5882cc1a","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":280,"y":120,"wires":[]},{"id":"bda0fc24c4a035fb","type":"function","z":"f1ad7bfd5882cc1a","name":"new joinee??","func":"/*function sleep(milliseconds) {\n const date = Date.now();\n let currentDate = null;\n do {\n currentDate = Date.now();\n } while (currentDate - date < milliseconds);\n}\nsleep(1500);*/\nmsg.payload.type = 'message';\nmsg.payload.options = { reply_to_message_id: msg.payload.messageId };\nmsg.payload.content = \"Are you a new joinee?\";\nreturn [msg];","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":60,"wires":[["6b03f5af1ec023a8","59b33f21f66de252"]]},{"id":"6b03f5af1ec023a8","type":"debug","z":"f1ad7bfd5882cc1a","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":20,"wires":[]},{"id":"133175beaeded35c","type":"delay","z":"f1ad7bfd5882cc1a","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":460,"y":60,"wires":[["bda0fc24c4a035fb"]]},{"id":"25f6f3f143492fac","type":"function","z":"f1ad7bfd5882cc1a","name":"confimed new joinee","func":"msg.payload.content = \"Good to know, welcome to company\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":380,"wires":[["fd4f421c85a6966e","c9265e97ac2d800d"]]},{"id":"fd4f421c85a6966e","type":"debug","z":"f1ad7bfd5882cc1a","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":440,"y":340,"wires":[]},{"id":"bf0f82dd730d671d","type":"function","z":"f1ad7bfd5882cc1a","name":"not a new joinee","func":"msg.payload.content = \"NOTE: at this point only yes OR no answer is accepted.\\n SO please either enter yes OR no, Thank you!!\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":460,"wires":[["2c73336f9070571d","c9265e97ac2d800d"]]},{"id":"2c73336f9070571d","type":"debug","z":"f1ad7bfd5882cc1a","name":"debug 9","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":440,"y":420,"wires":[]},{"id":"dbeb4a3eb521554a","type":"telegram reply","z":"f1ad7bfd5882cc1a","name":"","bot":"6b031eeb3ef163ce","x":400,"y":240,"wires":[["aa1e77582d99edcf","a4e4986658244af0"]]},{"id":"b36440cbecbdc934","type":"switch","z":"f1ad7bfd5882cc1a","name":"","property":"payload.content","propertyType":"msg","rules":[{"t":"regex","v":"^ *yes *$","vt":"str","case":true},{"t":"regex","v":"^ *no *$","vt":"str","case":true}],"checkall":"true","repair":false,"outputs":2,"x":270,"y":420,"wires":[["25f6f3f143492fac","bf0f82dd730d671d"],[]]},{"id":"c9265e97ac2d800d","type":"telegram sender","z":"f1ad7bfd5882cc1a","name":"","bot":"6b031eeb3ef163ce","haserroroutput":false,"outputs":1,"x":730,"y":400,"wires":[["ac4b7e52eb3c80cb"]]},{"id":"ac4b7e52eb3c80cb","type":"debug","z":"f1ad7bfd5882cc1a","name":"debug 12","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":700,"y":360,"wires":[]},{"id":"45c8e6fa42f6707b","type":"function","z":"f1ad7bfd5882cc1a","name":"function 3","func":"if (msg.payload.content === 'yes') {\n console.log(\"I am in yes answer of user new joinee\");\n return [ msg, null ];\n}\nelse {\n return [ null, msg ];\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":120,"y":300,"wires":[["b36440cbecbdc934","5ebb90f9c18a7efd"]]},{"id":"5ebb90f9c18a7efd","type":"debug","z":"f1ad7bfd5882cc1a","name":"debug 13","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":120,"y":340,"wires":[]},{"id":"aa1e77582d99edcf","type":"debug","z":"f1ad7bfd5882cc1a","name":"debug 14","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":390,"y":280,"wires":[]},{"id":"59b33f21f66de252","type":"telegram sender","z":"f1ad7bfd5882cc1a","name":"","bot":"6b031eeb3ef163ce","haserroroutput":false,"outputs":1,"x":510,"y":140,"wires":[["50a1b5729a79d6f9"]]},{"id":"50a1b5729a79d6f9","type":"function","z":"f1ad7bfd5882cc1a","name":"function 4","func":"console.log(\"---------------------->>>>>>>\");\n\nlet content = msg.payload.content;\nlet chatId = msg.payload.chatId;\nlet sentMessageId = msg.payload.sentMessageId;\nlet type = msg.payload.type;\nlet messageId = msg.reply_to_message_id;\nlet replyTo = msg.payload.messageId;\n\nmsg.payload = {};\nmsg.payload.content = content;\nmsg.payload.chatId = chatId;\nmsg.payload.sentMessageId = sentMessageId;\nmsg.payload.type = type;\n\nconsole.log(\"payload =\" + msg.payload.content);\n\nreturn [ msg ] ; \n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":700,"y":200,"wires":[["dbeb4a3eb521554a","0bef13cf95e04ed1"]]},{"id":"0bef13cf95e04ed1","type":"debug","z":"f1ad7bfd5882cc1a","name":"debug 16","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":700,"y":160,"wires":[]},{"id":"a4e4986658244af0","type":"function","z":"f1ad7bfd5882cc1a","name":"function 5","func":"console.log(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":700,"y":300,"wires":[["ed75e9e6b836ca3a"]]},{"id":"ed75e9e6b836ca3a","type":"debug","z":"f1ad7bfd5882cc1a","name":"debug 19","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":700,"y":260,"wires":[]},{"id":"6b031eeb3ef163ce","type":"telegram bot","botname":"sin17","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksprotocol":"socks5","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]
Thanks,
Ravinder Singh