# Execute only once on telegram bot

**URL:** <https://discourse.nodered.org/t/execute-only-once-on-telegram-bot/56735>\
**Category:** General\
**Tags:** telegram, mqtt\
**Created:** [16 January 2022 09:49 UTC](https://discourse.nodered.org/t/execute-only-once-on-telegram-bot/56735 "2022-01-16T09:49:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HantuRaya](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hanturaya/32/54332_2.png) [@HantuRaya](https://discourse.nodered.org/u/HantuRaya)\
**Post date:** [16 January 2022 09:49 UTC](https://discourse.nodered.org/t/execute-only-once-on-telegram-bot/56735/1 "2022-01-16T09:49:20Z")

</div>

Hello everyone, I'm totally new to Node-RED (5 days)  
How can i only execute 1 command when everytime I call my telegram bot?  
by the way this is my flow, suggestions welcome 😃

and i want to ask one more thing, what can I do to remove the "undefined" thing when I called the telegram

 ![3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/f/7f5f7a3d5191c7a722d082b69bb5f3dbcd4886c2.png)  
 ![4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/2/32a5e75c2f86414083a5d7e57266dae9e656f0c2.png)

---

<div class="post-metadata">

**Author:** ![HantuRaya](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hanturaya/32/54332_2.png) [@HantuRaya](https://discourse.nodered.org/u/HantuRaya)\
**Post date:** [16 January 2022 09:55 UTC](https://discourse.nodered.org/t/execute-only-once-on-telegram-bot/56735/3 "2022-01-16T09:55:30Z")

</div>

```auto
[{"id":"569cdb27f329ea92","type":"tab","label":"FINALE","disabled":false,"info":"","env":[]},{"id":"25baba9fb0f5a5ea","type":"mqtt in","z":"569cdb27f329ea92","name":"acVolt","topic":"bts/noc/ac/acVolt","qos":"2","datatype":"json","broker":"ab5d3aec78c4252c","nl":false,"rap":true,"rh":0,"inputs":0,"x":170,"y":180,"wires":[["fd7d36364496112b"]]},{"id":"fd7d36364496112b","type":"function","z":"569cdb27f329ea92","name":"","func":"msg.nocav = msg.payload\nmsg.payload = msg.nocav\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":180,"wires":[["95e0c68effc44ed9"]]},{"id":"797f30155666dbb3","type":"debug","z":"569cdb27f329ea92","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":200,"wires":[]},{"id":"e089098f482382e5","type":"mqtt in","z":"569cdb27f329ea92","name":"acCurrent","topic":"bts/noc/ac/acCurrent","qos":"2","datatype":"json","broker":"ab5d3aec78c4252c","nl":false,"rap":true,"rh":0,"inputs":0,"x":160,"y":260,"wires":[["04489801898c80b4"]]},{"id":"1ec9d39c7133849f","type":"mqtt in","z":"569cdb27f329ea92","name":"acEnergy","topic":"bts/noc/ac/acEnergy","qos":"2","datatype":"json","broker":"ab5d3aec78c4252c","nl":false,"rap":true,"rh":0,"inputs":0,"x":160,"y":420,"wires":[["531f8de7d2a1322d"]]},{"id":"9a81b7f7ea9b265d","type":"mqtt in","z":"569cdb27f329ea92","name":"acPower","topic":"bts/noc/ac/acPower","qos":"2","datatype":"json","broker":"ab5d3aec78c4252c","nl":false,"rap":true,"rh":0,"inputs":0,"x":160,"y":340,"wires":[["cdf02351be96c6f3"]]},{"id":"dd04cb76f9acceac","type":"mqtt in","z":"569cdb27f329ea92","name":"acFreq","topic":"bts/noc/ac/acFreq","qos":"2","datatype":"json","broker":"ab5d3aec78c4252c","nl":false,"rap":true,"rh":0,"inputs":0,"x":170,"y":500,"wires":[["765c7f7d9dc8a89e"]]},{"id":"837f9501c81c1eb2","type":"mqtt in","z":"569cdb27f329ea92","name":"acPf","topic":"bts/noc/ac/acPf","qos":"2","datatype":"json","broker":"ab5d3aec78c4252c","nl":false,"rap":true,"rh":0,"inputs":0,"x":170,"y":580,"wires":[["bd0a9512f937a30b"]]},{"id":"04489801898c80b4","type":"function","z":"569cdb27f329ea92","name":"","func":"msg.nocaccurrent = msg.payload\n\nmsg.payload = msg.nocaccurrent\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":260,"wires":[["95e0c68effc44ed9"]]},{"id":"cdf02351be96c6f3","type":"function","z":"569cdb27f329ea92","name":"","func":"msg.nocaccurrent = msg.payload\n\nmsg.payload = msg.nocaccurrent\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":340,"wires":[["95e0c68effc44ed9"]]},{"id":"531f8de7d2a1322d","type":"function","z":"569cdb27f329ea92","name":"","func":"msg.nocaccurrent = msg.payload\n\nmsg.payload = msg.nocaccurrent\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":420,"wires":[["95e0c68effc44ed9"]]},{"id":"765c7f7d9dc8a89e","type":"function","z":"569cdb27f329ea92","name":"","func":"msg.nocaccurrent = msg.payload\n\nmsg.payload = msg.nocaccurrent\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":500,"wires":[["95e0c68effc44ed9"]]},{"id":"bd0a9512f937a30b","type":"function","z":"569cdb27f329ea92","name":"","func":"msg.nocaccurrent = msg.payload\nmsg.payload = msg.nocaccurrent\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":580,"wires":[["95e0c68effc44ed9"]]},{"id":"95e0c68effc44ed9","type":"function","z":"569cdb27f329ea92","name":"","func":"let test1 = \"Power Details\\r\\n\"\ntest1 += \"Current Volt: \" + msg.nocav\ntest1 += \"\\r\\n\"\ntest1 += \"Current Volt: \" + msg.nocaccurrent\ntest1 += \"\\r\\n\"\ntest1 += \"Current Volt: \" + msg.nocacpower\ntest1 += \"\\r\\n\"\n \nmsg.payload = test1;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":380,"wires":[["797f30155666dbb3","8b43c6ebcbd3f2b5"]]},{"id":"101f44abc2cd3a33","type":"telegram command","z":"569cdb27f329ea92","name":"","command":"/test","description":"","registercommand":false,"language":"","scope":"default","bot":"fc62e3f73418bc8d","strict":false,"hasresponse":false,"useregex":false,"removeregexcommand":false,"outputs":1,"x":290,"y":100,"wires":[["95e0c68effc44ed9"]]},{"id":"8b43c6ebcbd3f2b5","type":"telegrambot-notify","z":"569cdb27f329ea92","name":"","bot":"e4207fff45b6f8d3","chatId":"","message":"","parseMode":"","x":850,"y":480,"wires":[]},{"id":"ab5d3aec78c4252c","type":"mqtt-broker","name":"BTS","broker":"","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"1","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"fc62e3f73418bc8d","type":"telegram bot","botname":"Bot","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"1500","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false},{"id":"e4207fff45b6f8d3","type":"telegrambot-config","botname":"Bot","usernames":"","chatIds":"","pollInterval":"300"}]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [16 January 2022 10:41 UTC](https://discourse.nodered.org/t/execute-only-once-on-telegram-bot/56735/4 "2022-01-16T10:41:32Z")

</div>

Your flow confuses me.

1. The `function` node connected to each `mqtt-in` node are doing the same thing. Why?
2. What do you except the msg coming from the `telegram-in` is going to cause the `function` node to do?

each msg going into a node will be processed with `only` the data it contains (with the exception of contect data).

you need to join the various inputs together and this might help you understand how to do that so see [this article in the cookbook](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object.

In addition, I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<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:** [17 March 2022 10:42 UTC](https://discourse.nodered.org/t/execute-only-once-on-telegram-bot/56735/5 "2022-03-17T10:42:25Z")

</div>

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