Beginnersquestion FunctionNode

Hey guys,
I know this is a absolute beginners question but I studied working with messages and watched a few function node videos but it didn't helped me out.

The task is simple. I have a node, watching my dishwasher, which sends some informations on the end of the wash process. I have a Function node subsequently which should convert those properties in a readable text:

Die Spülmaschine ist fertig.  
Dauer: {{ payload.time }} Minuten.  
Energieverbrauch: {{ payload.energy }} kw/h.  
Kosten: {{ payload.cost }} €

This Text should be passed in a function node which should add a title, and edit the payload to go to a telegram sender node. And here I don't know how exactly I can do that.

The is what I got so far:

var payload=msg.payload;
var newMsg = { 
      title : 'Spülmaschine',
      msg.payload : payload ,
      type : 'message',
      chatId : 'xxxxxxx',
    };
return newMsg;

Can you help me and tell me how to get this right?

Thank you

Do you mean a template node? A function node doesn't do mustache.

What does right look like? What exactly is the issue? Is the text you send not right? Is it that you received nothing in telegram? Are you just after advice regarding sending msgs between nodes?

1 Like

Sorry first there is a template-node with mustache and then should the function node format the msg.payload correctly to get used in the telegram sender node.

Here is an example of template and function node, hope it helps

[{"id":"187967a.a95e618","type":"inject","z":"4484ee28.caa3c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"time\":\"65\",\"cost\":12.52,\"energy\":110}","payloadType":"json","x":130,"y":500,"wires":[["dc2b7cc9.db3fd8","1fc3423.ff7063e"]]},{"id":"1fc3423.ff7063e","type":"template","z":"4484ee28.caa3c","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Die Spülmaschine ist fertig.  \nDauer: {{ payload.time }} Minuten.  \nEnergieverbrauch: {{ payload.energy }} kw/h.  \nKosten: {{ payload.cost }} €\n","output":"str","x":290,"y":500,"wires":[["42220b9.712b574"]]},{"id":"42220b9.712b574","type":"function","z":"4484ee28.caa3c","name":"","func":"var payload=msg.payload;\nmsg.payload = { \n      title : 'Spülmaschine',\n      content: payload ,\n      type : 'message',\n      chatId : 'xxxxxxx'\n    };\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":470,"y":500,"wires":[["269a25ff.79887a"]]}]```

Ok, but you still don't say what the actual issue is. Can you answer the questions? ...

1 Like

Sorry @E1cid, but this one does not work:

`title: "testing"`  does not show up anywhere
`type: "text"`   has to be `type: "message"` 

At least with my telegram node node-red-contrib-telegrambot latest version 8.6.4

I think the most import part is the msg.payload.content part with the telegram text, which @terminus didn't use.

At least with my telegram node node-red-contrib-telegrambot latest version 8.6.4
I think the most import part is the msg.payload.content part with the telegram text, which @terminus didn't use.

Thank you @stefan24 for your Answer, I changed that to message by myself, also there was a comma where i thought it supposed to be a dot. But I got it working.

Hi, it was an example of formating an object in a function, and i was working from memory and @terminus managed to work out the kinks.

I have edited the post and corrected the syntax error and text to message.

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