# Joining messages

**URL:** <https://discourse.nodered.org/t/joining-messages/43343>\
**Category:** General\
**Created:** [29 March 2021 08:10 UTC](https://discourse.nodered.org/t/joining-messages/43343 "2021-03-29T08:10:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [29 March 2021 08:10 UTC](https://discourse.nodered.org/t/joining-messages/43343/1 "2021-03-29T08:10:30Z")

</div>

Hi,  
I have 3 or 4 nodes which generates different msg.payload at different times. I need to join all the payloads into one single payload, only when the last node has completed its job. Got confused....

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [29 March 2021 08:22 UTC](https://discourse.nodered.org/t/joining-messages/43343/2 "2021-03-29T08:22:01Z")

</div>

Is the "last" one always the same one ? If so use a join node and let that node also set msg.complete to trigger the group to be complete. If not - how do you know what is last ? - once you know that you can do same.

---

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [29 March 2021 10:07 UTC](https://discourse.nodered.org/t/joining-messages/43343/3 "2021-03-29T10:07:41Z")

</div>

That's my problem. I cannot know exactly which is the last. They are 3 or 4 queries to servers and they always respond with different times...

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [29 March 2021 10:15 UTC](https://discourse.nodered.org/t/joining-messages/43343/4 "2021-03-29T10:15:33Z")

</div>

Can you knock up a demo flow (using injects to simulate the data) and explain how you expect them to be joined, i'll have a look.

something like...

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/0/4012161086c19c5436c2221f48d931dc8890ded4.png)

Use the "copy value" button (that appears under your mouse cursor when you hover over the debug message) to capture the server data and paste it into the payload of the injects so that it simulates your situation.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 March 2021 10:25 UTC](https://discourse.nodered.org/t/joining-messages/43343/5 "2021-03-29T10:25:14Z")

</div>

If there is no logical way to solve your problem then there is no way in s/w either.

---

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [29 March 2021 10:35 UTC](https://discourse.nodered.org/t/joining-messages/43343/6 "2021-03-29T10:35:49Z")

</div>

That's easier than that. They are text messages that I need to join and send to an Alexa speech node.  
Messages can be:

1:  
Alarm state: Activated  
Zone 1: OFF  
Zone2: ON  
Zone 3: OFF

2:  
Sprinkler system ENABLED (or DIABLED)

3:  
Air Condition ON

4:  
Kitchen Window: Open  
Living Window: Closed  
..  
...

But I need to have a singles (long) speech message with the full status

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [29 March 2021 10:37 UTC](https://discourse.nodered.org/t/joining-messages/43343/7 "2021-03-29T10:37:28Z")

</div>

Then provide the demo flow (complete with demo sample messages as i described) and what you expect the output to be & I will attempt to provide an answer (if it is possible)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [29 March 2021 12:29 UTC](https://discourse.nodered.org/t/joining-messages/43343/8 "2021-03-29T12:29:55Z")

</div>

You can specify the msg.parts for each message

```auto
{"id":"mes1","count":4,"type":"object","key":"alarm"}

```

The id and count will give you a object length and group the messages, you can then reconstruct automatic or using the reduced sequence in the join node. ( reduced sequence - the only issue i see with this is repeat messages with same id and key are counted).

```auto
[{"id":"2fedd031.63e358","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"parts","v":"{\"id\":\"mes1\",\"count\":4,\"type\":\"object\",\"key\":\"alarm\"}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"alarm","payloadType":"str","x":160,"y":2800,"wires":[["e6419572.6fa578"]]},{"id":"e6419572.6fa578","type":"join","z":"5a245aa1.510164","name":"join","mode":"auto","build":"array","property":"payload","propertyType":"msg","key":"parts.key","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"(\t$merge([parts, {\"count\": $I + parts.count}]);\t$merge([$A,{parts.key: payload}]) \t)","reduceInit":"{}","reduceInitType":"json","reduceFixup":"","x":400,"y":2900,"wires":[["6bb469c0.836dc"]]},{"id":"a00f481.1c890b8","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"parts","v":"{\"id\":\"mes1\",\"count\":4,\"type\":\"object\",\"key\":\"sprinkler\"}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"enabled","payloadType":"str","x":160,"y":2840,"wires":[["e6419572.6fa578"]]},{"id":"6733626c.c7463c","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"parts","v":"{ \"id\": \"mes1\", \"count\": 4, \"type\": \"object\", \"key\": \"air\" }","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":150,"y":2880,"wires":[["e6419572.6fa578"]]},{"id":"17a963d0.05ee4c","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"parts","v":"{ \"id\": \"mes1\", \"count\": 4, \"type\": \"object\", \"key\": \"windows\" }","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"kitchen open","payloadType":"str","x":180,"y":2920,"wires":[["e6419572.6fa578"]]},{"id":"6bb469c0.836dc","type":"debug","z":"5a245aa1.510164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":700,"y":2940,"wires":[]},{"id":"5fb9a37.ab249dc","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"parts","v":"{\"id\":\"mes3\",\"count\":3,\"type\":\"object\",\"key\":\"sprinkler\"}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"disabled","payloadType":"str","x":430,"y":3040,"wires":[["e6419572.6fa578"]]},{"id":"e085142b.4296","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"parts","v":"{ \"id\": \"mes3\", \"count\": 3, \"type\": \"object\", \"key\": \"air\" }","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":420,"y":3080,"wires":[["e6419572.6fa578"]]},{"id":"b68a8ade.60ddb8","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"parts","v":"{\"id\":\"mes3\",\"count\":3,\"type\":\"object\",\"key\":\"alarm\"}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"alarm bedroom","payloadType":"str","x":470,"y":3000,"wires":[["e6419572.6fa578"]]},{"id":"cca2980c.8f3a28","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"parts","v":"{\"id\":\"mes2\", \"index\":0, \"count\":3,\"type\":\"object\",\"key\":\"alarm\"}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"alarm kitchen","payloadType":"str","x":200,"y":3120,"wires":[["e6419572.6fa578"]]},{"id":"2c7d4940.fafa3e","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"parts","v":"{\"id\":\"mes2\",\"index\":1,\"count\":3,\"type\":\"object\",\"key\":\"sprinkler\"}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"enabled","payloadType":"str","x":170,"y":3160,"wires":[["e6419572.6fa578"]]},{"id":"69458bef.1053e4","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"parts","v":"{ \"id\": \"mes2\", \"index\": 2, \"count\": 3, \"type\": \"object\", \"key\": \"air\" }","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":160,"y":3200,"wires":[["e6419572.6fa578"]]}]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [12 April 2021 12:30 UTC](https://discourse.nodered.org/t/joining-messages/43343/9 "2021-04-12T12:30:47Z")

</div>

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