Telegram multiple msg.payload combined

Good day,

I am looking for a way to combine multiple msg.payload into one Telegram message.

The Telegram node get overwhelmed when it need to send to many replies, hence me wanting to combine the message in one reply..

See image attached.

Thank you for looking

1 Like

Use a join node to join all the messages. there is an example in the node-red cook book.
https://cookbook.nodered.org/basic/join-streams

msg.payload = {
    "chatId": "234454653222", 
    "topic": "06 AC_OUT_W", 
    "type":"message", 
    "content":"Power Usage = " + msg.payload + " W"};
return msg;

Thanks, i think my formatting is wrong, i get chatID empty?

msg.payload = {
    "chatId": "234454653222", 
    "topic": "06 AC_OUT_W", 
    "type":"message", 
    "content":"Power Usage = " + msg.payload["06 AC_OUT_W"] + " W"};
return msg;

The name of the topic becomes the payloads property.
Best to give the topic (instead of 206 AC_OUT_W" powerOut") a better name then you could use msg.payload.powerOut

my apologies, I am still battling here.

my 2 functions nodes are as follows:

msg.payload = {
    "chatId": "3333333333", 
    "topic": "battvolt", 
    "type":"message", 
    "content":"Battery Voltage = " + msg.payload + " V"};
return msg;
msg.payload = {
    "chatId": "44444433", 
    "topic": "powerin", 
    "type":"message", 
    "content":"Eskom AC in = " + msg.payload + " V"};
return msg;

My output from debug:

2

Result in no message to Telegram

I simplified my flow to only 2 nodes now just to try and make sense of it all. not good

1

i do mix the information like this

var satDisplayName  = msg.payload[0].satDisplayName;
var serverTime      = msg.payload[0].serverTime;

var freq            = msg.payload[0].freq;
var mode            = msg.payload[0].mode;

msg.payload = {chatId : 12345id , type : 'message', content : 
"Satellit: " +"*" +satDisplayName +"*" +"\n" +"\n"
+mode +"@" +freq
+"\n" +"\n" 

+serverTime
};

// activate markdown
//msg.payload.options = {disable_web_page_preview : true, parse_mode :"Markdown"};
msg.payload.options = {disable_web_page_preview : true, parse_mode :"Markdown"};
return msg;

Thank you for the reply, i dont understand

if you have a normal output like this

i just collect the Information i need with the var at the beginn.
and in the second part i put the var togehter to get a nice output in Telegram include to have important stuff in bold.

Join you values before the function then in a new function create the payload for telegram. You will only need one function node.
Reference you values like this in the function
msg.payload["06 AC_OUT_W"]
Post your flow and i will edit for an example if you wish.

Thank you

[{"id":"2649c9fd.20f3b6","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"d77650ce.8d502","type":"change","z":"2649c9fd.20f3b6","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"powerin","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":110,"y":280,"wires":[["6c71c520.8520bc"]]},{"id":"c1efedfc.ede68","type":"change","z":"2649c9fd.20f3b6","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"battvolt","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":110,"y":240,"wires":[["2266906a.dbe5b"]]},{"id":"2266906a.dbe5b","type":"function","z":"2649c9fd.20f3b6","name":"Battery Voltage","func":"msg.payload = {\n    \"chatId\": \"xxxxx\", \n    \"type\":\"message\", \n    \"content\":\"Battery Voltage = \" + msg.payload + \" V\"};\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":240,"wires":[["497bbc0f.902114"]]},{"id":"6c71c520.8520bc","type":"function","z":"2649c9fd.20f3b6","name":"AC in","func":"msg.payload = {\n    \"chatId\": \"xxxxx\", \n    \"type\":\"message\", \n    \"content\":\"Eskom AC in = \" + msg.payload + \" V\"};\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":350,"y":280,"wires":[["497bbc0f.902114"]]},{"id":"497bbc0f.902114","type":"join","z":"2649c9fd.20f3b6","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":590,"y":260,"wires":[["79c47aba.225df4"]]},{"id":"79c47aba.225df4","type":"telegram sender","z":"2649c9fd.20f3b6","name":"","bot":"","haserroroutput":false,"outputs":1,"x":850,"y":260,"wires":[[]]}]

Here is an example combined into one message. Not sure of telegrams formatting the newline may work.

[{"id":"8d31813f.e1cea","type":"inject","z":"2649c9fd.20f3b6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"36","payloadType":"num","x":100,"y":160,"wires":[["c1efedfc.ede68"]]},{"id":"c1efedfc.ede68","type":"change","z":"2649c9fd.20f3b6","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"battvolt","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":110,"y":240,"wires":[["497bbc0f.902114"]]},{"id":"497bbc0f.902114","type":"join","z":"2649c9fd.20f3b6","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":330,"y":260,"wires":[["5be85aec.4b4884"]]},{"id":"d77650ce.8d502","type":"change","z":"2649c9fd.20f3b6","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"powerin","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":110,"y":280,"wires":[["497bbc0f.902114"]]},{"id":"5be85aec.4b4884","type":"function","z":"2649c9fd.20f3b6","name":"Battery Voltage","func":"msg.payload = {\n    \"chatId\": \"xxxxx\", \n    \"type\":\"message\", \n    \"content\":\"Battery Voltage = \" + msg.payload.battvolt + \" V\\n Eskom AC in = \" + msg.payload.powerin + \" W\"};\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":540,"y":260,"wires":[["a2328cf5.d40268"]]},{"id":"756c8b3a.0b490c","type":"inject","z":"2649c9fd.20f3b6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1000","payloadType":"num","x":100,"y":360,"wires":[["d77650ce.8d502"]]},{"id":"a2328cf5.d40268","type":"debug","z":"2649c9fd.20f3b6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":760,"y":260,"wires":[]}]
2 Likes

Much appreciated. Worked like a charm. Thank you

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