Trigger a flow via telegram and respond with data from MQTT?


May be this is a stupid question or I have just knots in my brain, but as I am completely new to Node Red, please forgive me my stupidness:

I have data from my 3d-Printer via MQTT in Node Red and I have a chatbot from Telegram. Both work individually. But now I'd like to output the status of my printer to telegram only, when "/status" is received via telegram.

How do I buffer the data that comes via MQTT until the "/status" - command comes in? This is what I currently have:

Thanks for your help!!

Regards, Andreas


Given the phrasing of your question, would the node-red-contrib-simple-message-queue help you out?

I am also very new at node-red....


You can use context data to store whatever you need, then retrieve it when the /status arrives.

I was about to say this.

Just connect the mqtt node to a change node, store the payload into a context variable.
When requesting the /status, get the context variable and display it.

Or, if you want to avoid the use of context data (which can make it more difficult to follow the flow) then use a Join node in key/value mode to join the mqtt value with the telegram data and then every time a new message comes in you will be able to take appropriate action.

thanks to you all!

@Steve-Mcl and bakman2 : perfect, that is what I was searching for... (not only for this task)

@Colin : you are right, context makes things more difficult to understand, but I don't get how your proposal with the join node will work:
When new MQTT data arrives and /status is not triggered, then the following function evaluates to do nothing.
Then /status arrives, the function starts to output the last MQTT data, because it is still in the message object.
Then new MQTT data arrives. What is the state of the /status - isn't it still active? and therefore the function node creates an output?

You can check the topic of the output message from the join node (which will be the topic of the message it has just received) and ignore the message unless the topic is that for the telegram message.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.