Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Token ID #124

Open
lexrosenot opened this issue Aug 31, 2020 · 35 comments
Open

Change Token ID #124

lexrosenot opened this issue Aug 31, 2020 · 35 comments

Comments

@lexrosenot
Copy link

Hello, is there any way to modify the token value in the node configuration at runtime from the node-red dashboard? The idea is that people without access to the node's configuration can do it from the dashboard. I really appreciate your work.

image

@windkh
Copy link
Owner

windkh commented Aug 31, 2020

If you would alter the token you would need to restart the bot... is that what you want?

@lexrosenot
Copy link
Author

Hello. no, what I want is that a person who generates his own bot from telegram can configure the token of his own bot from the nodered dashboard. it's possible ?.

Thanks for your reply

@windkh
Copy link
Owner

windkh commented Sep 1, 2020

No that is not possible, it would be only through a restart of node red. Maybe I will add this in future but it is not of the highest priority right now.

@jenskastensson
Copy link

Hi, I am also looking for a way to set the token in run-time. My use case is similar to @lexrosenot (I think) : the user doesn't have access to the Node-RED Telegram configuration node and will enter his/her token in another simplified user interface.
I understand that you 're not planning to do this in the near future, do you mind hinting where I would add it temporarily (while waiting for your proper implementation) ?

@windkh
Copy link
Owner

windkh commented Sep 4, 2020

No not really as the bot is started when deployed. Even if you could alter the value you would need to deploy the changes

@jenskastensson
Copy link

Thank you @windkh , this is my case : it's an embedded system and I have full control over all files and I can restart the Node-Red run-time. I could 1) modify/replace NR source files or 2) write the token to a config file and finally restart NR
Which approach would be the easiest and which file(s) should I aim for.
Thank you for a great and stable node implementation, we'll make donation ProKNX when it works

@windkh
Copy link
Owner

windkh commented Sep 5, 2020

@jenskastensson
I have several ideas how to lazy initialize the bot when the token is not set in the config node.
But implementing it would definately take some time.
Or do you rather need a quick hack to get some prototype up and running?

@jenskastensson
Copy link

It depends on when it would be available: If you think it could be available within a month - I can wait
If it is longer, then I can live with a hack (or hack my self with your guidance)

@windkh
Copy link
Owner

windkh commented Sep 5, 2020

Let‘s start finding a nice solution by gathering some ideas... I would appreciate if anybody else would also provide his thoughts:

Idea 1: instead of entering the token directly I could read it from an external config file. You would enter the full path to the file instead of the token in the config node

Idea 2: I could read the token from an environment variable like reading from a file#
✔️ implemented in version 8.6.0

Idea 3: this could also work somehow (https://flows.nodered.org/flow/6fe183c197b3464a1fe4d89744e068ff) but the bot would need to be triggered to reinitialize somehow.

Idea 4: token in config is empty. The token is injected into the node via the msg object. Some predecessor in the flow would have to set this value at least in one initial message

Idea 5: create a new config node which can be placed in the flow and controlled from e.g. an inject node. This one would be just a proxy to the real config node in the sidebar. Restarts could be done too, when the bot has a problems with the network.

Idea 6: hack: enter a placeholder in the token field. Search an replace this placeholder in the config file of nodred before restarting the nodered instance.
❌ this is not better than Idea 2

....
what solution would you like most?

@jenskastensson
Copy link

jenskastensson commented Sep 5, 2020

Any solution is fine for me, but is has to be possible to set it even if it's not empty.
Idea 7: could be to use the Dynamic auth that you have implemented for usernames {global.get("telegramtoken")}
(edit: windkh: ❌ this won't work as the flow is initialized after the bot is started)

Personally, I think passing it on with the msg variable is the most commonly used method. But then I don't have the full picture.

@windkh
Copy link
Owner

windkh commented Sep 5, 2020

Idea 7 could be done in addition to others.
❌ does not work

@jenskastensson
Copy link

@lexrosenot What do you think?

@jenskastensson
Copy link

BTW I will use it for a chatbot for Home Automation: PRATGLAD for Trådfri, https://pratglad.com
Here's a video https://www.youtube.com/watch?v=IuBVU6duVDM
The chatbot backend input is feed to an offline Voice recognition NLU by Snips/SONOS, pretty cool, isn't it?
We're struggling to explain that is in fact a superior solution than Alexa and Google Home, it respects users privacy.

@windkh
Copy link
Owner

windkh commented Sep 5, 2020

Nice I did something similar... what speech to text engine did you use? ... ah just saw it. We used rasa ... also very nice

@jenskastensson
Copy link

jenskastensson commented Sep 5, 2020 via email

@lexrosenot
Copy link
Author

@lexrosenot What do you think?

Hello guys,
My case is similar to that of @jenskastensson , it is an embedded system, but in a raspberry pi where node-red runs and works as an orchestrator of independent modules (esp8266/esp32) through the mqtt protocol, being able to control this from the dashboard or telegram. I think that idea 4 is the one that best adapts and simplest at the node configuration level.

@lexrosenot
Copy link
Author

IMG_20200905_105007

@windkh
Copy link
Owner

windkh commented Sep 6, 2020

Idea 7 does not work with global context variables as the bot is started upon deployment and thus is initialized before the flow is started. This won't work
image

@windkh
Copy link
Owner

windkh commented Sep 6, 2020

Idea 2: Instead of reading the value from a context variable in the flow it is read from the environment as follows
image

The only drawback would be that you would have to enter the variable into the settings.js of node-red before you start node-red.

image

@windkh
Copy link
Owner

windkh commented Sep 6, 2020

✔️ Idea 2 is implemented in version 8.6.0

@jenskastensson
Copy link

jenskastensson commented Sep 6, 2020 via email

@jenskastensson
Copy link

jenskastensson commented Sep 6, 2020

Couldn't wait so tried it today.. It seems I have a problem: Node-RED v0.20.7 (the user base is on this version)
I've updated node-red-contrib-telegrambot to 8.6.0 (shown in Palette)
Entered a token manually in the UI to confirm it works, then replaced the token with {env.get("BOT_TOKEN")}
Edited the settings.js file and added
process.env.BOT_TOKEN = "61648djsjd....";
on the first line.
Restarted Node-RED (tried to reboot the system too) but I only see "polling error" in the status field.
I verified that the env var is ok by adding a Inject node which reads $BOT_TOKEN and send to debug output
The browser runs at very high CPU when the polling error happens, tis will potentially be a problem for my usres too. Most of them will not use the Telegram node, and so they will have the {env.get("BOT_TOKEN")} and and empty env variable.
Do you have any ideas what goes wrong here and how I can troubleshoot it?
Thanks for your efforts

@windkh
Copy link
Owner

windkh commented Sep 6, 2020

Hm... I will check what happens when the variable is not set or not present

@windkh
Copy link
Owner

windkh commented Sep 6, 2020

if the environment variable is not found (does not exist) you get the following:
image

If the environment variable is found and contains a valid key you get the following:
image

If the token is not valid you will get a polling error which is reset after a while.... right now it returns to green state "polling" which is wrong. I will improve this so that it will look like this
image

If the environment variable is empty then you get the following:
image

@windkh
Copy link
Owner

windkh commented Sep 6, 2020

Couldn't wait so tried it today.. It seems I have a problem: Node-RED v0.20.7 (the user base is on this version)
I've updated node-red-contrib-telegrambot to 8.6.0 (shown in Palette)
Entered a token manually in the UI to confirm it works, then replaced the token with {env.get("BOT_TOKEN")}
Edited the settings.js file and added
process.env.BOT_TOKEN = "61648djsjd....";
on the first line.
Restarted Node-RED (tried to reboot the system too) but I only see "polling error" in the status field.
I verified that the env var is ok by adding a Inject node which reads $BOT_TOKEN and send to debug output
The browser runs at very high CPU when the polling error happens, tis will potentially be a problem for my usres too. Most of them will not use the Telegram node, and so they will have the {env.get("BOT_TOKEN")} and and empty env variable.
Do you have any ideas what goes wrong here and how I can troubleshoot it?
Thanks for your efforts

I can't reproduce your problem. I am using the following environment:
npm 6.4.1
node-red 1.1.2
node 10.15.0

Can you try 8.6.1 of the nodes and recheck?

@jenskastensson
Copy link

jenskastensson commented Sep 7, 2020 via email

@jenskastensson
Copy link

jenskastensson commented Sep 10, 2020 via email

@windkh
Copy link
Owner

windkh commented Nov 30, 2020

@jenskastensson should I close this issue or are you still interested in a better solution?

@jenskastensson
Copy link

jenskastensson commented Dec 1, 2020 via email

@windkh
Copy link
Owner

windkh commented Dec 1, 2020

@jenskastensson I will create a better solution... just wanted to check the priorities

@jenskastensson
Copy link

jenskastensson commented Dec 1, 2020 via email

@lexrosenot
Copy link
Author

i can implement idea 2 very succesfully. thanks a lot !

@windkh windkh reopened this Aug 23, 2021
@windkh
Copy link
Owner

windkh commented Aug 23, 2021

I opened again … as I will try to improve this in future

@Leandro-G-Ribeiro
Copy link

Senhores!
eu utilizei a ideia das variáveis de ambiente para setar o token pelo usuário e funcionou muito bem apesar de ter que reiniciar o node-red. coloquei o arquivo Settings.js a linha process.env.BOT_TOKEN = "61648djsjd...." ;
e na configuração do nó Token do nó {env.get("BOT_TOKEN")}.
Ta muito bom essa implementação, era isso que eu precisava. valew!!!!

@windkh
Copy link
Owner

windkh commented Jan 19, 2022

muy bien

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants