# Beginnersquestion FunctionNode

**URL:** <https://discourse.nodered.org/t/beginnersquestion-functionnode/33719>\
**Category:** General\
**Created:** [4 October 2020 07:09 UTC](https://discourse.nodered.org/t/beginnersquestion-functionnode/33719 "2020-10-04T07:09:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![terminus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/terminus/32/38378_2.png) [@terminus](https://discourse.nodered.org/u/terminus)\
**Post date:** [4 October 2020 07:09 UTC](https://discourse.nodered.org/t/beginnersquestion-functionnode/33719/1 "2020-10-04T07:09:08Z")

</div>

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:

```auto
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:

```auto
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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 October 2020 07:19 UTC](https://discourse.nodered.org/t/beginnersquestion-functionnode/33719/2 "2020-10-04T07:19:13Z")

</div>

> [@terminus](#):
>
> I have a Function node subsequently which should convert those properties in a readable text:
> 
> ```auto
> Die Spülmaschine ist fertig.  
> Dauer: {{ payload.time }} Minuten.  
> Energieverbrauch: {{ payload.energy }} kw/h.  
> Kosten: {{ payload.cost }} €
> 
> ```

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

> [@terminus](#):
>
> Can you help me and tell me how to get this right

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?

---

<div class="post-metadata">

**Author:** ![terminus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/terminus/32/38378_2.png) [@terminus](https://discourse.nodered.org/u/terminus)\
**Post date:** [4 October 2020 07:21 UTC](https://discourse.nodered.org/t/beginnersquestion-functionnode/33719/3 "2020-10-04T07:21:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [4 October 2020 07:29 UTC](https://discourse.nodered.org/t/beginnersquestion-functionnode/33719/4 "2020-10-04T07:29:24Z")

</div>

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

````auto
[{"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"]]}]```
````

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 October 2020 07:29 UTC](https://discourse.nodered.org/t/beginnersquestion-functionnode/33719/5 "2020-10-04T07:29:31Z")

</div>

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

> [@Steve-Mcl](#):
>
> 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?

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [4 October 2020 09:17 UTC](https://discourse.nodered.org/t/beginnersquestion-functionnode/33719/6 "2020-10-04T09:17:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![terminus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/terminus/32/38378_2.png) [@terminus](https://discourse.nodered.org/u/terminus)\
**Post date:** [4 October 2020 11:27 UTC](https://discourse.nodered.org/t/beginnersquestion-functionnode/33719/7 "2020-10-04T11:27:47Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [4 October 2020 12:50 UTC](https://discourse.nodered.org/t/beginnersquestion-functionnode/33719/8 "2020-10-04T12:50:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [18 October 2020 12:50 UTC](https://discourse.nodered.org/t/beginnersquestion-functionnode/33719/9 "2020-10-18T12:50:15Z")

</div>

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