Telegram paragraphs

Hello everybody
Does anyone know what the function node has to look like if I want individual paragraphs in the message?
So for example:
Status: on
Music: off
So far I've only managed to send status: on, for example.

Many Thanks

This is what I use in a function node to format a multi-line message for my weather station.

var chatId = flow.get("chatId");

var ws_pcb_info = "Weather station report for "+msg.payload[0].node_ref+"\r\n";
ws_pcb_info += "Location is... "+msg.payload[0].location+"\r\n";
ws_pcb_info += "Here are the latest readings... \r\nat: "+msg.payload[0].time+" hrs GMT\r\n";
ws_pcb_info +="on: "+msg.payload[0].date+"\r\n\r\n"
ws_pcb_info += "Temperature: "+msg.payload[0].temperature+" deg(C)\r\n";
ws_pcb_info += "Humidity: "+msg.payload[0].humidity+"%\r\n";
ws_pcb_info += "Pressure: "+msg.payload[0].pressure+" hPa\r\n\r\n";
ws_pcb_info += "Wemos rail: "+msg.payload[0].wemos_rail+"V\r\n";
ws_pcb_info += "Li-ion battery: "+msg.payload[0].lion_battery+"V\r\n";
ws_pcb_info += "Solar panel: "+msg.payload[0].solar_panel+"V\r\n\r\n";
ws_pcb_info += "Solar voltage: "+msg.payload[0].voltage+"V\r\n";
ws_pcb_info += "Solar current: "+msg.payload[0].current+"mA\r\n";
ws_pcb_info += "Solar wattage: "+msg.payload[0].wattage+"mW\r\n";
msg.payload.content = ws_pcb_info;
msg.payload.type = "message";
msg.payload.chatId = chatId;

return msg;

And this is what it looks like in Telegram.
Screen Shot 06-19-21 at 03.36 PM

Hope you find it useful.

first Many Thanks!

I tried exactly the same on myself, but it didn't work.

Well can you post what you now have in the function node ??

EDIT: You don't want the comma at the end of line 3 in your original listing.

Ich bitte um entschuldigung.. Ich kenne NodeRed ĂĽberhaupt nicht...Bin mich gerade ein wenig am einarbeiten

OK - you have some typos.

Line 1 Should end with ; (semicolon) not a , (comma) and it's messed up.

Line 3 Should start with var or let
So it should read.... var ws_pcb_info = "Status" .......... etc....

Lines 3 and 4 look exactly the same to me??

Line 7 Should read... msg.payload.chatId = chatID; // As you have already declared it on Line1
Note: You have chatID and it should be chatId - I've been caught by this so many times !!!

Try that and see if it works.

it did not work

Try this short piece of code and see if it works.

let message = "Status\r\n";
message += "This is the next line";

msg.payload.content = message;
msg.payload.type = "message";
msg.payload.chatId = 16647075;

return msg;

Have you tried it yet ??


it didnt work..

So I was able to send status messages already .. I just want to send several in one text ..

Ummm... the code looks fine.

Is that actually your chatId as I could copy the code at my end and see if it sends to you??

If you post code instead of pictures, we can much more easily copy, edit & fix up.

You create ws_pcb_info then try to set ws.pcb_info but nowhere do you join the 2 strings.

Also, as ws does not exist, trying to access .pcb_info will cause an undefined error when the function runs.

var chatId = flow.get("16647075");

var ws_pcb_info = "Status Taster Eingang" +flow.get("statustastereingang");
ws.pcb_info += "Status Taster 1" +flow.get("statustaster1");
msg.payload.content = ws_pcb_info;
msg.payload.type = "message";
msg.payload.chatId = 16647075;

return msg;

Well spotted Steve - I didn't see that .

There's an underscore there as well that's not right.... ws_pcb_info

1 Like

Try this.

var s1 = "Status Taster Eingang" +flow.get("statustastereingang");
var s2 = "Status Taster 1" +flow.get("statustaster1");
msg.payload = {};
msg.payload.content = s1 + "\n" + s2;
msg.payload.type = "message";
msg.payload.chatId = 16647075;

return msg;

it worked! Many Thanks!!


And thanks for letting us know.

Using Steve's way of creating individual lines of text, you should be able to create multi-line messages now.

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