# Send mqtt message to telegram

**URL:** <https://discourse.nodered.org/t/send-mqtt-message-to-telegram/45067>\
**Category:** General\
**Created:** [2 May 2021 16:22 UTC](https://discourse.nodered.org/t/send-mqtt-message-to-telegram/45067 "2021-05-02T16:22:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steinspiel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steinspiel/32/30095_2.png) [@Steinspiel](https://discourse.nodered.org/u/Steinspiel)\
**Post date:** [2 May 2021 16:22 UTC](https://discourse.nodered.org/t/send-mqtt-message-to-telegram/45067/1 "2021-05-02T16:22:17Z")

</div>

Hello,

An "mqtt In Node" receives different messages from an MQTT topic.

example:  
{"topic":"test/topic\_1","payload":"test message 1","qos":0,"retain":false,"\_msgid":"90dd8faa.79f8e"}  
{"topic":"test/topic\_1","payload":"test message 2","qos":0,"retain":false,"\_msgid":"7d6b3fe3.e7e8d"}  
...

I want to send this message to the "Telegram sender Node". What do I have to write in my "function node" for this to work?

let payload = {"chatId":\*\*\*\*\*\*\*\*\*,  
type:"message",  
content:"---the message should be here---"};  
return{payload};

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/0/2044e545e53ae02dac1d114672f7f37537c45206.png)

Thank you for your help,

---

<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:** [2 May 2021 16:44 UTC](https://discourse.nodered.org/t/send-mqtt-message-to-telegram/45067/2 "2021-05-02T16:44:53Z")

</div>

A function node is not needed a template node would do the job  
e.g.

```auto
[{"id":"4b9c66a1.6cc778","type":"inject","z":"9b3f9f31.c45298","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"test message","payloadType":"str","x":190,"y":2140,"wires":[["ea63aa67.c972f"]]},{"id":"ea63aa67.c972f","type":"template","z":"9b3f9f31.c45298","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"chatId\": 123456,\n\"type\":\"message\",\n\"content\":\"{{payload}}\"}","output":"json","x":380,"y":2140,"wires":[["9e00d0a7.d5ccf"]]},{"id":"9e00d0a7.d5ccf","type":"debug","z":"9b3f9f31.c45298","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":2140,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Steinspiel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steinspiel/32/30095_2.png) [@Steinspiel](https://discourse.nodered.org/u/Steinspiel)\
**Post date:** [2 May 2021 17:37 UTC](https://discourse.nodered.org/t/send-mqtt-message-to-telegram/45067/3 "2021-05-02T17:37:53Z")

</div>

> [@E1cid](#):
>
> A function node is not needed a template node would do the job

good evening,

Thanks for your help, it works very well!

Do you know how I can also send the topic name to telgram? Unfortunately, my example doesn't work.

```auto
{"chatId": 123456,
"type":"message",
"content":"{{payload}}"
"content":"{{topic}}"
}

```

---

<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:** [2 May 2021 17:58 UTC](https://discourse.nodered.org/t/send-mqtt-message-to-telegram/45067/4 "2021-05-02T17:58:06Z")

</div>

```auto
{"chatId": 123456,
"type":"message",
"content":"{{payload}}\n{{topic}}"}

```

---

<div class="post-metadata">

**Author:** ![Steinspiel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steinspiel/32/30095_2.png) [@Steinspiel](https://discourse.nodered.org/u/Steinspiel)\
**Post date:** [2 May 2021 20:11 UTC](https://discourse.nodered.org/t/send-mqtt-message-to-telegram/45067/5 "2021-05-02T20:11:59Z")

</div>

> [@E1cid](#):
>
> `"content":"{{payload}}\n{{topic}}"}`

"\ n" shares the payload?  
Thanks, that helped.

Slash in the topic name (mqtt\*\*/\*\*topic) is represented as Unicode in Telegram, but it doesn't matter. 😉

thanks

---

<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:** [1 July 2021 20:12 UTC](https://discourse.nodered.org/t/send-mqtt-message-to-telegram/45067/6 "2021-07-01T20:12:55Z")

</div>

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