Skip to content

{env.get()} token and chatids not resolved from flows.json - breaks automated deployments #432

@FlorianSauer

Description

@FlorianSauer

Problem

The token and chatids properties in the Telegram bot config node are not getting picked up at Node-RED server startup.
token gets cleared, chatids gets not filled correctly.
Node-RED seems to strip credential properties from flows.json and does not resolve {env.get()} expressions.

The only way to set the token and chatids is manually via the editor UI after every fresh deployment.
This breaks automated Docker deployments where flows.json is git-managed.

Steps to Reproduce

  1. Write flows.json and commit it to git
	...
	{
	"id": "ee000000000001",
	"type": "telegram bot",
	"botname": "MyBotName",
	"usernames": "",
	"chatids": "{env.get(\"TELEGRAM_CHAT_ID\")}",
	"baseapiurl": "",
	"token": "{env.get(\"TELEGRAM_BOT_TOKEN\")}",
	"updatemode": "polling",
	"pollinterval": "300",
	"usesocks": false,
	"sockshost": "",
	"socksport": "6667",
	"socksusername": "socks",
	"sockspassword": "",
	"bothost": "",
	"botpath": "",
	"localbotport": "8443",
	"publicbotport": "8443",
	"privatekey": "",
	"certificate": "",
	"useselfsignedcertificate": false,
	"sslterminated": false,
	"verboselogging": false
	},
	...

settings.js:

module.exports = {
    credentialSecret: process.env.NODE_RED_CREDENTIAL_SECRET,
    editorTheme: {
        tours: false
    },
    telemetry: {
        enabled: false,
        updateNotification: false
    }
}
  1. Clone git managed flows, settings etc.
$ rm -rf data/
$ git checkout .
Updated 4 paths from the index
$ ls -la data/
total 32
drwxr-xr-x 2 docker docker  4096 Mär 26 08:41 ./
drwxr-xr-x 6 docker docker  4096 Mär 26 08:41 ../
-rw-r--r-- 1 docker docker     0 Mär 26 08:41 .empty
-rw-r--r-- 1 docker docker 13107 Mär 26 08:41 flows.json
-rw-r--r-- 1 docker docker    55 Mär 26 08:41 .gitignore
-rw-r--r-- 1 docker docker   268 Mär 26 08:41 settings.js
  1. Start container with docker compose up -d

  2. Verify env vars are available in the container:

$ docker compose exec node-red env | grep TELEGRAM
TELEGRAM_BOT_TOKEN=123456:ABCDEF
TELEGRAM_CHAT_ID=123456
  1. Result:
    token is empty, "bot not initialized" warning under both Telegram sender and receiver nodes.
    When I then enter the token manually or enter {env.get("TELEGRAM_BOT_TOKEN")} manually again, the telegram sender shows as connected, but test messages get ignored.
    The chatids do not get picked up from environment.
    When I then enter the chatids manually test messages get picked up and processed.

  2. File permissions after manually entering the credentials

$ ls -lah data/
total 92K
drwxr-xr-x 4 docker docker 4,0K Mär 26 16:09 .
drwxr-xr-x 6 docker docker 4,0K Mär 26 16:03 ..
-rw-r--r-- 1 docker docker  28K Mär 26 16:06 .config.nodes.json
-rw-r--r-- 1 docker docker   40 Mär 26 16:06 .config.runtime.json
-rw-r--r-- 1 docker docker  513 Mär 26 16:06 .config.users.json
-rw-r--r-- 1 docker docker    0 Mär 26 16:03 .empty
-rw-r--r-- 1 docker docker  128 Mär 26 16:07 flows_cred.json
-rw-r--r-- 1 docker docker 9,1K Mär 26 16:09 flows.json
-rw-r--r-- 1 docker docker 9,1K Mär 26 16:09 .flows.json.backup
-rw-r--r-- 1 docker docker   55 Mär 26 16:03 .gitignore
drwxr-xr-x 3 docker docker 4,0K Mär 26 16:06 lib
drwxr-xr-x 2 docker docker 4,0K Mär 26 16:06 node_modules
-rw-r--r-- 1 docker docker  120 Mär 26 16:06 package.json
-rw-r--r-- 1 docker docker  268 Mär 26 16:03 settings.js

Expected Behavior

{env.get()} should resolve for the token and allowed chatids in flows.json.

Workaround

Manually enter the token and chatids in the editor token field after every fresh deployment.
This defeats the usage for automated setups.

Environment

  • Node-RED: 4.1.7 (Docker)
  • node-red-contrib-telegrambot:
$ docker compose exec node-red npm ls node-red-contrib-telegrambot
node-red-docker@4.1.7 /usr/src/node-red
`-- node-red-contrib-telegrambot@17.1.2
  • Deployment: Docker Compose with env_file, git-managed flows.json

Happy to provide additional logs or test with a dev build if that helps narrow this down.
Is there a recommended approach for automated deployments that I might be missing?

I saw the "Reading token from external location" section in the readme.
If im not mistaken my approach is similar to it.
Im just not setting the token in settings.js but passing the values via the docker environment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions