# Telegrambot receiver node - ChatIds property

**URL:** <https://discourse.nodered.org/t/telegrambot-receiver-node-chatids-property/42351>\
**Category:** General\
**Created:** [9 March 2021 15:34 UTC](https://discourse.nodered.org/t/telegrambot-receiver-node-chatids-property/42351 "2021-03-09T15:34:52Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Djibril](https://avatars.discourse-cdn.com/v4/letter/d/ea666f/32.png) [@Djibril](https://discourse.nodered.org/u/Djibril)\
**Post date:** [9 March 2021 15:34 UTC](https://discourse.nodered.org/t/telegrambot-receiver-node-chatids-property/42351/1 "2021-03-09T15:34:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![henrycosta05](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henrycosta05/32/36350_2.png) [@henrycosta05](https://discourse.nodered.org/u/henrycosta05)\
**Post date:** [9 March 2021 18:26 UTC](https://discourse.nodered.org/t/telegrambot-receiver-node-chatids-property/42351/2 "2021-03-09T18:26:03Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/2/a25e033cc63ce365c54daab7c7316cea0d2ebaac.png)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [9 March 2021 21:00 UTC](https://discourse.nodered.org/t/telegrambot-receiver-node-chatids-property/42351/3 "2021-03-09T21:00:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Djibril](https://avatars.discourse-cdn.com/v4/letter/d/ea666f/32.png) [@Djibril](https://discourse.nodered.org/u/Djibril)\
**Post date:** [10 March 2021 08:35 UTC](https://discourse.nodered.org/t/telegrambot-receiver-node-chatids-property/42351/4 "2021-03-10T08:35:22Z")

</div>

Thank you both for answers.

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

---

<div class="post-metadata">

**Author:** ![Folgore](https://avatars.discourse-cdn.com/v4/letter/f/edb3f5/32.png) [@Folgore](https://discourse.nodered.org/u/Folgore)\
**Post date:** [10 March 2021 20:02 UTC](https://discourse.nodered.org/t/telegrambot-receiver-node-chatids-property/42351/5 "2021-03-10T20:02:49Z")

</div>

> [@TotallyInformation](#):
>
> Penso che significhi dove è possibile specificare un elenco di chatId che sono considerati validi, qualsiasi altro ID sorgente verrà contrassegnato come non autorizzato e verrà indirizzato alla seconda porta di output.

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

---

<div class="post-metadata">

**Author:** ![Folgore](https://avatars.discourse-cdn.com/v4/letter/f/edb3f5/32.png) [@Folgore](https://discourse.nodered.org/u/Folgore)\
**Post date:** [10 March 2021 20:03 UTC](https://discourse.nodered.org/t/telegrambot-receiver-node-chatids-property/42351/6 "2021-03-10T20:03:53Z")

</div>

Sorry, I have pinned a wrong message

---

<div class="post-metadata">

**Author:** ![Djibril](https://avatars.discourse-cdn.com/v4/letter/d/ea666f/32.png) [@Djibril](https://discourse.nodered.org/u/Djibril)\
**Post date:** [11 March 2021 08:01 UTC](https://discourse.nodered.org/t/telegrambot-receiver-node-chatids-property/42351/7 "2021-03-11T08:01:45Z")

</div>

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

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [11 March 2021 10:12 UTC](https://discourse.nodered.org/t/telegrambot-receiver-node-chatids-property/42351/8 "2021-03-11T10:12:34Z")

</div>

> [@Folgore](#):
>
> Hi, I have used a function node after the telegram rec node for authorized chat

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

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [11 March 2021 10:37 UTC](https://discourse.nodered.org/t/telegrambot-receiver-node-chatids-property/42351/9 "2021-03-11T10:37:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [11 March 2021 12:53 UTC](https://discourse.nodered.org/t/telegrambot-receiver-node-chatids-property/42351/10 "2021-03-11T12:53:27Z")

</div>

Yes, either way would work

---

<div class="post-metadata">

**Author:** ![Djibril](https://avatars.discourse-cdn.com/v4/letter/d/ea666f/32.png) [@Djibril](https://discourse.nodered.org/u/Djibril)\
**Post date:** [11 March 2021 16:27 UTC](https://discourse.nodered.org/t/telegrambot-receiver-node-chatids-property/42351/11 "2021-03-11T16:27:51Z")

</div>

> [@krambriw](#):
>
> s you can use context.global variables for this purpose

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

\*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

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![Folgore](https://avatars.discourse-cdn.com/v4/letter/f/edb3f5/32.png) [@Folgore](https://discourse.nodered.org/u/Folgore)\
**Post date:** [12 March 2021 17:39 UTC](https://discourse.nodered.org/t/telegrambot-receiver-node-chatids-property/42351/12 "2021-03-12T17:39:52Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/c/2c0e75c206a31128ab0bcb6253bb4b16e940e607.jpeg)

---

<div class="post-metadata">

**Author:** ![Djibril](https://avatars.discourse-cdn.com/v4/letter/d/ea666f/32.png) [@Djibril](https://discourse.nodered.org/u/Djibril)\
**Post date:** [16 March 2021 10:31 UTC](https://discourse.nodered.org/t/telegrambot-receiver-node-chatids-property/42351/13 "2021-03-16T10:31:07Z")

</div>

Working, thank you!! 😉

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [30 March 2021 10:31 UTC](https://discourse.nodered.org/t/telegrambot-receiver-node-chatids-property/42351/14 "2021-03-30T10:31:26Z")

</div>

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