The call service allows you to pass in data. This allows you to format the data field all in the function node.
[{"id":"051dfda870d2e0c1","type":"inject","z":"265e4c64d108bbce","name":"2 persons","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"blueiris/front","payload":"ALERT_DB;person:80%,person:78%;ALERT_PATH","payloadType":"str","x":108,"y":576,"wires":[["30ea80513a028e07"]]},{"id":"30ea80513a028e07","type":"function","z":"265e4c64d108bbce","name":"format data","func":"const [db, memo, path] = msg.payload.split(\";\");\nconst location = msg.topic.split(\"/\")[1];\n\nconst things = joinThings(memo.split(\",\").reduce((acc, thing) => {\n return [...acc, thing.split(\":\")[0]];\n}, []));\n\nconst message = `A ${things} was detected at the ${location}`;\nmsg.payload = {\n data: {\n message,\n data: {\n image: `http://192.168.1.246:81/alerts/${path}`,\n actions: [\n {\n action: \"URI\",\n title: \"Live\",\n uri: `http://192.168.1.246:81/ui3.htm?maximize=1&cam=${location}`,\n },\n {\n action: \"URI\",\n title: \"Clip\",\n uri: `http://192.168.1.246:81/ui3.htm?maximize=1&tab=alerts&cam=${location.toLocaleLowerCase()}&rec=${db}`\n }\n ]\n }\n }\n}\n\nreturn msg;\n\nfunction joinThings(arr) {\n const unique = [...new Set(arr)];\n const last = unique.pop();\n return unique.length > 0\n ? `${unique.join(', ')} and ${last}`\n : last ?? '';\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":282,"y":576,"wires":[["9fdb7c26eef97154"]]},{"id":"0ad97b3555ec8ea1","type":"inject","z":"265e4c64d108bbce","name":"2 persons and a dog","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"blueiris/front","payload":"ALERT_DB;person:80%,person:78%,dog:66%;ALERT_PATH","payloadType":"str","x":138,"y":624,"wires":[["30ea80513a028e07"]]},{"id":"9fdb7c26eef97154","type":"api-call-service","z":"265e4c64d108bbce","name":"","server":"","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_person","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":514,"y":576,"wires":[[]]}]
const [db, memo, path] = msg.payload.split(";");
const location = msg.topic.split("/")[1];
const things = joinThings(memo.split(",").reduce((acc, thing) => {
return [...acc, thing.split(":")[0]];
}, []));
const message = `A ${things} was detected at the ${location}`;
msg.payload = {
data: {
message,
data: {
image: `http://192.168.1.246:81/alerts/${path}`,
actions: [
{
action: "URI",
title: "Live",
uri: `http://192.168.1.246:81/ui3.htm?maximize=1&cam=${location}`,
},
{
action: "URI",
title: "Clip",
uri: `http://192.168.1.246:81/ui3.htm?maximize=1&tab=alerts&cam=${location.toLocaleLowerCase()}&rec=${db}`
}
]
}
}
}
return msg;
function joinThings(arr) {
const unique = [...new Set(arr)];
const last = unique.pop();
return unique.length > 0
? `${unique.join(', ')} and ${last}`
: last ?? '';
}