I’m pretty new to coding but I really want to learn how to build IoT projects with Node-RED. Right now I’m trying to set up a Telegram bot so I can send commands to my devices and get updates back.
I’ve managed to create a Telegram bot and get the API token. I also found my chat ID which took forever to figure out. I installed the chatbot module for Node-RED and created a simple flow.
The problem is that when I send messages from Telegram, Node-RED receives them but shows this error in the debug panel: “Unable to find context().global in Node-RED”
The flow seems to detect incoming messages but can’t process them properly. I think I’m missing some basic configuration but I can’t figure out what. Has anyone run into this context error before? What am I doing wrong with the setup?
This error typically occurs when the Node-RED context storage isn’t properly initialized or the flow is trying to access global context before it’s ready. I had similar issues when I first started with Telegram bots in Node-RED. The chatbot module sometimes tries to store conversation state in global context immediately upon receiving messages. Try restarting Node-RED completely after installing the chatbot module, as context storage needs to be properly initialized on startup. Also check if you have any function nodes in your flow that reference context().global - make sure they include proper error handling. Another thing to verify is that your settings.js file has contextStorage properly configured. Sometimes the default memory storage isn’t set up correctly which causes these context errors.
yeah, it seems like global context isn’t set up yet. maybe throw in a delay node b4 the telegram stuff or double-check that context().global is used in the right spot. also, ensure your chatbot node has the right token, could be messing things up too.
I encountered this exact same issue when setting up my first Telegram integration. The context().global error usually happens because the chatbot nodes are trying to access global variables that haven’t been initialized yet. What worked for me was adding an inject node at the beginning of my flow that fires once on startup to initialize the global context variables. You can set it to inject an empty object or whatever initial values you need into global context. Also worth checking if you’re running Node-RED in a Docker container or similar environment where the context storage might not persist properly. Sometimes clearing the context completely and letting it rebuild from scratch fixes these initialization issues. Make sure your flow isn’t trying to read from global context before anything has been written to it first.