HowTo send a message with variables

I have a working node which sends a static text (This is a test) as a message. It works very well.
I would now like to replace the static text with a variable which, for example, was passed to me from the previous node. I think it works with a template block. But how does the code look like? Does anyone have an understandable example here?

[{"id":"b1c50bd382b75e76","type":"inject","z":"8ed57a821485ba05","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":120,"y":2300,"wires":[["176d336035dfc137"]]},{"id":"176d336035dfc137","type":"change","z":"8ed57a821485ba05","name":"SynoChat","rules":[{"t":"set","p":"headers","pt":"msg","to":"{\"content-type\":\"application/x-www-form-urlencoded\"}","tot":"json"},{"t":"set","p":"payload","pt":"msg","to":"payload={\"text\":\"This is a test\"}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":2300,"wires":[["2c27a0a20f49d272"]]},{"id":"2c27a0a20f49d272","type":"http request","z":"8ed57a821485ba05","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://192.168.xxx.x:5000/webapi/entry.cgi?api=SYNO.Chat.External&method=incoming&version=2&token=<secret_token>","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"credentials":{"user":"","password":""},"x":490,"y":2300,"wires":[[]]}]

Here are two methods, it could also be done with a function node

One uses JSONata expression in a change node
The other uses mustache template in a template node

[{"id":"b1c50bd382b75e76","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":210,"y":1060,"wires":[["176d336035dfc137","ff4f5412.95355"]]},{"id":"176d336035dfc137","type":"change","z":"b779de97.b1b46","name":"SynoChat","rules":[{"t":"set","p":"headers","pt":"msg","to":"{\"content-type\":\"application/x-www-form-urlencoded\"}","tot":"json"},{"t":"set","p":"payload","pt":"msg","to":"'payload={\"text\":\"' & $$.payload & '\"}'","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":1060,"wires":[["32bb0d03.017b1a"]]},{"id":"ff4f5412.95355","type":"template","z":"b779de97.b1b46","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"payload={\"text\":\"{{{payload}}}\"}","output":"str","x":440,"y":1120,"wires":[["32bb0d03.017b1a"]]},{"id":"32bb0d03.017b1a","type":"debug","z":"b779de97.b1b46","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":660,"y":1080,"wires":[]}]

Hope it helps

1 Like

Yes, of course. It helps. Very nice. Full function. Thank you.