I am using node red to create an iOS notification. I would really like to define a line break in the notification for formatting issues. I stumbled across a website similar to this one. I found some code to create a new line but the problem is I can’t figure out how to insert my flow variable into it.
https://sebhastian.com/new-line-javascript/
I have two function nodes, one of them creating the message body, another one creating the message, which is then passed to the call service node.
To best of my knowledge it is javascript console.
Here is the code I have:
var a = '{"iOS_Notification" : "this is line 1\\nthis is line 2\\nthis is line 3\\nthis is line 4\\nthis is line 5 "}';
var b = JSON.parse(a);
msg.payload= b
return msg;
function node 2
var iOS_Notification = msg.payload.iOS_Notification
msg.payload =
{
"data": {
"message": iOS_Notification
}
}
return msg;
The whole flow:
[{"id":"154c352b23a3a7f0","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"eed7f3ed0810fab7","type":"inject","z":"154c352b23a3a7f0","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":275,"y":460,"wires":[["e8923ef9a59046d9"]],"l":false},{"id":"e8923ef9a59046d9","type":"function","z":"154c352b23a3a7f0","name":"","func":"var a = '{\"iOS_Notification\" : \"this is line 1\\\\nthis is line 2\\\\nthis is line 3\\\\nthis is line 4\\\\nthis is line 5 \"}';\nvar b = JSON.parse(a);\nmsg.payload= b\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":315,"y":420,"wires":[["efc023215ddb677e"]],"l":false},{"id":"efc023215ddb677e","type":"function","z":"154c352b23a3a7f0","name":"","func":"var iOS_Notification = msg.payload.iOS_Notification\nmsg.payload =\n{ \n \"data\": {\n \"message\": iOS_Notification\n}\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":355,"y":380,"wires":[["269d10f277d180ad"]],"l":false},{"id":"269d10f277d180ad","type":"api-call-service","z":"154c352b23a3a7f0","name":"","server":"7acb3af6.49e9d4","version":3,"debugenabled":false,"service_domain":"notify","service":"our_iphones","entityId":"","data":"{}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":395,"y":340,"wires":[[]],"l":false},{"id":"7acb3af6.49e9d4","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
I am sure this could be done better. I am not a programmer by day but just an enthusiast. I love learning about new things and would be grateful if someone could point out away to do this.
My objective is to create line breaks with dynamic iOS notifications. The code works well enough for static notifications.