Telegrambot receiver node - ChatIds property

Hi,

I'm trying to create a Telegram bot, and I noticed I can specify ChatIds (or Users) in Telegram Receiver node in order to authorize or not messages.

Is there a way to update the ChatIds property from a configuration file or a function node? I tried but I couldn't get it.

hi @Djibril,
Are you setting chatId (case sensitive) inside msg.payload?

I think he means where you can specify a list of chatId's that are considered valid, any other source id's will be marked as unauthorised and be directed to the 2nd output port.

I don't believe that you can make those dynamic I'm afraid. If this is something you would like to see, I recommend opening an "issue" on the GitHub repository for the node.

Thank you both for answers.

@TotallyInformation I'll follow your recommendation, thank you!!

Hi, I have used a function node after the telegram rec node for authorized chat.

Sorry, I have pinned a wrong message

Tried to open an issue on GitHub, and got an answer from windkh

[{"id":"ee5ccada.43f59","type":"telegram sender","z":"117ca2b6.9952d5","name":"","bot":"","x":570,"y":380,"wires":[[]]},{"id":"aa3d783b.53061","type":"telegram receiver","z":"117ca2b6.9952d5","name":"","bot":"","saveDataDir":"c:\\temp\\foo","filterCommands":false,"x":290,"y":420,"wires":[["3fe23b0b.35503c","ee5ccada.43f59"],[]]},{"id":"3fe23b0b.35503c","type":"debug","z":"117ca2b6.9952d5","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":560,"y":440,"wires":[]},{"id":"7b3b2aee.330974","type":"inject","z":"117ca2b6.9952d5","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":680,"wires":[["c140074e.b4b44"]]},{"id":"c140074e.b4b44","type":"function","z":"117ca2b6.9952d5","name":"No Access","func":"// classic aproach for using context.\ncontext.global.usernames = [];\ncontext.global.chatids = [];\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":680,"wires":[[]]},{"id":"cd683e65.cff7b8","type":"inject","z":"117ca2b6.9952d5","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":720,"wires":[["72b7bffd.9a79"]]},{"id":"72b7bffd.9a79","type":"function","z":"117ca2b6.9952d5","name":"Grant access to User and chat 1","func":"// classic aproach for using context.\ncontext.global.usernames = [ \"User\" ];\ncontext.global.chatids = [ 1 ];\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":570,"y":720,"wires":[[]]},{"id":"d9d3a4c6.9ed7f","type":"change","z":"117ca2b6.9952d5","name":"Grant access to Sepp and Egon","rules":[{"t":"set","p":"usernames","pt":"global","to":"[\"Sepp\", \"Egon\"]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":620,"wires":[[]]},{"id":"6929b4a6.06892c","type":"inject","z":"117ca2b6.9952d5","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":620,"wires":[["d9d3a4c6.9ed7f"]]},{"id":"fa9290c0.e55dc","type":"change","z":"117ca2b6.9952d5","name":"No Access","rules":[{"t":"set","p":"usernames","pt":"global","to":"[\"Sepp\", \"Egon\"]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":580,"wires":[[]]},{"id":"6eebcb8a.ae350c","type":"inject","z":"117ca2b6.9952d5","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":580,"wires":[["fa9290c0.e55dc"]]},{"id":"5615bf9b.6e0f38","type":"comment","z":"117ca2b6.9952d5","name":"","info":"You can make use of the context in two ways:\n1. context.global.key = value\n2. global.set(key, value)\n\nOnly the latter one can be seen in the context browser window while the first is only stored as variable in memory.\n\nThe config node must be configured as follows:\n1. {context.global.hereyourkey} for approach one\n2. {gobal.get(\"hereyoukey\")} for approach two\n\nIf the config starts with { and ends with } the expression is evaluated as script.\n\nIn this example you can write\n{context.global.username}\n{context.global.chatids}\n\nor \n{global.get(\"usernames\")}\n{global.get(\"chatids\")}\n\nI would recommend the latter one.\n","x":260,"y":520,"wires":[]}]

This would also work as a solution. If you keep a list of valid ChatId's either in a context variable in the function node or as a flow/global context variable you can update it dynamically. In the function node you simply write code that filters messages, eventually to two different outputs, based on the current list

OK, so it seems you can use context.global variables for this purpose

Yes, either way would work

Tried today, but not working... I tried the simple cut/paste of the posted flow, adding my bot coordinates, but no way... :frowning:

*EDIT
Actually I edited a little the posted flow: usernames are set in both "No Access" and "Grant access ..." nodes, so I removed usernames from the first

[{"id":"ee5ccada.43f59","type":"telegram sender","z":"117ca2b6.9952d5","name":"","bot":"","x":570,"y":380,"wires":[[]]},{"id":"aa3d783b.53061","type":"telegram receiver","z":"117ca2b6.9952d5","name":"","bot":"","saveDataDir":"c:\\temp\\foo","filterCommands":false,"x":290,"y":420,"wires":[["3fe23b0b.35503c","ee5ccada.43f59"],[]]},{"id":"3fe23b0b.35503c","type":"debug","z":"117ca2b6.9952d5","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":560,"y":440,"wires":[]},{"id":"7b3b2aee.330974","type":"inject","z":"117ca2b6.9952d5","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":680,"wires":[["c140074e.b4b44"]]},{"id":"c140074e.b4b44","type":"function","z":"117ca2b6.9952d5","name":"No Access","func":"// classic aproach for using context.\ncontext.global.usernames = [];\ncontext.global.chatids = [];\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":680,"wires":[[]]},{"id":"cd683e65.cff7b8","type":"inject","z":"117ca2b6.9952d5","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":720,"wires":[["72b7bffd.9a79"]]},{"id":"72b7bffd.9a79","type":"function","z":"117ca2b6.9952d5","name":"Grant access to User and chat 1","func":"// classic aproach for using context.\ncontext.global.usernames = [ \"User\" ];\ncontext.global.chatids = [ 1 ];\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":570,"y":720,"wires":[[]]},{"id":"d9d3a4c6.9ed7f","type":"change","z":"117ca2b6.9952d5","name":"Grant access to Sepp and Egon","rules":[{"t":"set","p":"usernames","pt":"global","to":"[\"Sepp\", \"Egon\"]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":620,"wires":[[]]},{"id":"6929b4a6.06892c","type":"inject","z":"117ca2b6.9952d5","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":620,"wires":[["d9d3a4c6.9ed7f"]]},{"id":"fa9290c0.e55dc","type":"change","z":"117ca2b6.9952d5","name":"No Access","rules":[{"t":"set","p":"usernames","pt":"global","to":"[]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":580,"wires":[[]]},{"id":"6eebcb8a.ae350c","type":"inject","z":"117ca2b6.9952d5","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":580,"wires":[["fa9290c0.e55dc"]]},{"id":"5615bf9b.6e0f38","type":"comment","z":"117ca2b6.9952d5","name":"","info":"You can make use of the context in two ways:\n1. context.global.key = value\n2. global.set(key, value)\n\nOnly the latter one can be seen in the context browser window while the first is only stored as variable in memory.\n\nThe config node must be configured as follows:\n1. {context.global.hereyourkey} for approach one\n2. {gobal.get(\"hereyoukey\")} for approach two\n\nIf the config starts with { and ends with } the expression is evaluated as script.\n\nIn this example you can write\n{context.global.username}\n{context.global.chatids}\n\nor \n{global.get(\"usernames\")}\n{global.get(\"chatids\")}\n\nI would recommend the latter one.\n","x":260,"y":520,"wires":[]}]

Sorry, my memory is in fault. Try this.

I have created a global variable for user permissions.
The variable for user is an array.

conf1

Working, thank you!! :wink:

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