windkh / node-red-contrib-telegrambot

Telegram bot nodes for node-red.
Other
267 stars 119 forks source link

Change Token ID #124

Open lexrosenot opened 4 years ago

lexrosenot commented 4 years ago

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 commented 4 years ago

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

lexrosenot commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

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 commented 4 years ago

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# :heavy_check_mark: 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. :x: this is not better than Idea 2

.... what solution would you like most?

jenskastensson commented 4 years ago

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: :x: 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 commented 4 years ago

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

jenskastensson commented 4 years ago

@lexrosenot What do you think?

jenskastensson commented 4 years ago

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 commented 4 years ago

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

jenskastensson commented 4 years ago

We're using Snips, now SONOS

On Sat, Sep 5, 2020 at 2:40 PM Karl-Heinz Wind notifications@github.com wrote:

Nice I did something similar... what speech to text engine did you use

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/windkh/node-red-contrib-telegrambot/issues/124#issuecomment-687605542, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSPHQMNMUXRT4ZPZH6KHCLSEIWTXANCNFSM4QP76Y6A .

lexrosenot commented 4 years ago

@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 commented 4 years ago

IMG_20200905_105007

windkh commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

:heavy_check_mark: Idea 2 is implemented in version 8.6.0

jenskastensson commented 4 years ago

Excellent, I'll have go tomorrow

On Sun, Sep 6, 2020 at 2:20 PM Karl-Heinz Wind notifications@github.com wrote:

Idea 8 is implemented in version 8.6.0

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/windkh/node-red-contrib-telegrambot/issues/124#issuecomment-687774886, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSPHQNBRAUVO5PGPA34LBLSEN47LANCNFSM4QP76Y6A .

jenskastensson commented 4 years ago

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 commented 4 years ago

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

windkh commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

Great, after upgrade to the latest version 8.6.1 it works as expected. Ill try on a few more devices.

On Sun, Sep 6, 2020 at 8:10 PM Karl-Heinz Wind notifications@github.com wrote:

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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/windkh/node-red-contrib-telegrambot/issues/124#issuecomment-687858894, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSPHQKEADTX2UZ43FR5AQTSEPGAFANCNFSM4QP76Y6A .

jenskastensson commented 4 years ago

Just a quick note to let you know that I got it up and working, it's a bit ugly but should work. I 'll get back when we've tested a bit more. Thx

On Mon, Sep 7, 2020 at 8:21 AM Jens Kastensson jens@kastensson.se wrote:

Great, after upgrade to the latest version 8.6.1 it works as expected. Ill try on a few more devices.

On Sun, Sep 6, 2020 at 8:10 PM Karl-Heinz Wind notifications@github.com wrote:

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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/windkh/node-red-contrib-telegrambot/issues/124#issuecomment-687858894, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSPHQKEADTX2UZ43FR5AQTSEPGAFANCNFSM4QP76Y6A .

windkh commented 3 years ago

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

jenskastensson commented 3 years ago

Thanks, Karl, you can close it. It's not an ideal solution but you did it very fast and it does the job! Highly appreciated, sorry for the delay I 've sent a small contribution /Jens

On Mon, Nov 30, 2020 at 10:23 PM Karl-Heinz Wind notifications@github.com wrote:

@jenskastensson https://github.com/jenskastensson should I close this issue or are you still interested in a better solution?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/windkh/node-red-contrib-telegrambot/issues/124#issuecomment-736065168, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSPHQPL5JWEHGOPPWU5RHDSSQEOZANCNFSM4QP76Y6A .

windkh commented 3 years ago

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

jenskastensson commented 3 years ago

Not urgent for me, I have the current solution implemented and tested! Don't fix it if it ain't broke ;)

On Tue, Dec 1, 2020 at 2:43 PM Karl-Heinz Wind notifications@github.com wrote:

@jenskastensson https://github.com/jenskastensson I will create a better solution... just wanted to check the priorities

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/windkh/node-red-contrib-telegrambot/issues/124#issuecomment-736559693, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSPHQPQXATBDMCABSGZTD3SSTXJBANCNFSM4QP76Y6A .

lexrosenot commented 3 years ago

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

windkh commented 3 years ago

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

Leandro-G-Ribeiro commented 2 years ago

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 commented 2 years ago

muy bien