Pass message property with another node in-between

Hello forum,
I have this flow:
A -> B -> C

Node A has an output property msg.foo, which I want to pass to node C. However node B does not support that property, and it makes an API call, so there is a delay.

How do I pass this msg.foo from node A to node C, with node B in between which does not have this property?

Be gentle as I am less than 24 hour old to NodeRED :slight_smile:

In general, that would be a bug with Node B that ought to be raised against it. Nodes should preserve message properties.

What node is it?

It's a chatgpt node (GitHub - HaroldPetersInskipp/node-red-contrib-chatgpt: A Node-RED node that interacts with OpenAI machine learning models to generate text and image outputs like 'ChatGPT' and 'DALL·E 2'.)

I wasn't aware that nodes pass full 'msg' object along the flow. Is there any alternative I can use?

Here is a work-around. I am not sure how robust it is, particularly if messages arrive faster than the faulty node can process them.

[{"id":"396ed32beb653e14","type":"inject","z":"f14e4f2a567f3bb1","name":"","props":[{"p":"payload"},{"p":"foo","v":"bar","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":120,"wires":[["270467aa371fa522","e476f0df3fc96329","191d58b73a7ce26c"]]},{"id":"270467aa371fa522","type":"function","z":"f14e4f2a567f3bb1","name":"Your bad node here","func":"msg = {\"payload\": msg.payload}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":310,"y":140,"wires":[["553d7f893ecab85c"]]},{"id":"e476f0df3fc96329","type":"change","z":"f14e4f2a567f3bb1","name":"msg.topic=foo","rules":[{"t":"set","p":"topic","pt":"msg","to":"foo","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"foo","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":100,"wires":[["a8b43f8cabacd091"]]},{"id":"553d7f893ecab85c","type":"change","z":"f14e4f2a567f3bb1","name":"msg.topic=payload","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":140,"wires":[["a8b43f8cabacd091"]]},{"id":"a8b43f8cabacd091","type":"join","z":"f14e4f2a567f3bb1","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":710,"y":100,"wires":[["96e4bf652ba97c04"]]},{"id":"96e4bf652ba97c04","type":"debug","z":"f14e4f2a567f3bb1","name":"Output data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":180,"wires":[]},{"id":"191d58b73a7ce26c","type":"debug","z":"f14e4f2a567f3bb1","name":"Input data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":280,"y":180,"wires":[]}]

Note that it does not reconstruct the message exactly as it was - the input has msg.payload and msg.foo, the output has msg.payload.payload and msg.payload.foo.
You could use another change node to fix this.

Thank you @jbudd
Using a combination of Change nodes, I was able to make it work when I realized that nodes were passing the property (thanks @knolleary for pointing out). Node B had been overriding the property msg.topic, which I was interested in, so I created another property, msg.subject, with a Change node. This enabled me to do what I wanted to do."

Thank you!

1 Like

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