node-red-contrib-telegrambot icon indicating copy to clipboard operation
node-red-contrib-telegrambot copied to clipboard

Change Token ID

Open lexrosenot opened this issue 5 years ago • 35 comments

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

lexrosenot avatar Aug 31 '20 02:08 lexrosenot

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

windkh avatar Aug 31 '20 21:08 windkh

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

lexrosenot avatar Sep 01 '20 15:09 lexrosenot

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.

windkh avatar Sep 01 '20 18:09 windkh

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) ?

jenskastensson avatar Sep 04 '20 14:09 jenskastensson

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

windkh avatar Sep 04 '20 17:09 windkh

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

jenskastensson avatar Sep 05 '20 06:09 jenskastensson

@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?

windkh avatar Sep 05 '20 06:09 windkh

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)

jenskastensson avatar Sep 05 '20 06:09 jenskastensson

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?

windkh avatar Sep 05 '20 09:09 windkh

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.

jenskastensson avatar Sep 05 '20 11:09 jenskastensson

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

windkh avatar Sep 05 '20 11:09 windkh

@lexrosenot What do you think?

jenskastensson avatar Sep 05 '20 11:09 jenskastensson

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.

jenskastensson avatar Sep 05 '20 12:09 jenskastensson

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

windkh avatar Sep 05 '20 12:09 windkh

We're using Snips, now SONOS

On Sat, Sep 5, 2020 at 2:40 PM Karl-Heinz Wind [email protected] 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 .

jenskastensson avatar Sep 05 '20 13:09 jenskastensson

@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 avatar Sep 05 '20 13:09 lexrosenot

IMG_20200905_105007

lexrosenot avatar Sep 05 '20 13:09 lexrosenot

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 avatar Sep 06 '20 11:09 windkh

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 avatar Sep 06 '20 12:09 windkh

:heavy_check_mark: Idea 2 is implemented in version 8.6.0

windkh avatar Sep 06 '20 12:09 windkh

Excellent, I'll have go tomorrow

On Sun, Sep 6, 2020 at 2:20 PM Karl-Heinz Wind [email protected] 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 avatar Sep 06 '20 12:09 jenskastensson

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

jenskastensson avatar Sep 06 '20 16:09 jenskastensson

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

windkh avatar Sep 06 '20 17:09 windkh

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 avatar Sep 06 '20 18:09 windkh

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?

windkh avatar Sep 06 '20 18:09 windkh

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 [email protected] 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 avatar Sep 07 '20 06:09 jenskastensson

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 [email protected] 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 [email protected] 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 avatar Sep 10 '20 16:09 jenskastensson

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

windkh avatar Nov 30 '20 21:11 windkh

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 [email protected] 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 .

jenskastensson avatar Dec 01 '20 13:12 jenskastensson

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

windkh avatar Dec 01 '20 13:12 windkh