# 2 inputs function: mqtt & telegram?

**URL:** <https://discourse.nodered.org/t/2-inputs-function-mqtt-telegram/10143>\
**Category:** General\
**Created:** [14 April 2019 21:09 UTC](https://discourse.nodered.org/t/2-inputs-function-mqtt-telegram/10143 "2019-04-14T21:09:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![waquete](https://avatars.discourse-cdn.com/v4/letter/w/a698b9/32.png) [@waquete](https://discourse.nodered.org/u/waquete)\
**Post date:** [14 April 2019 21:09 UTC](https://discourse.nodered.org/t/2-inputs-function-mqtt-telegram/10143/1 "2019-04-14T21:09:26Z")

</div>

Hi there!  
I'm very new to nodered (what a huge world to discover!)  
I come to my 1st issue....  
I would like to do something simple,but I cannot figure out how to do (even based on [http://noderedguide.com/node-red-lecture-6-example-6-7-multiple-inputs-on-a-function-node/](http://noderedguide.com/node-red-lecture-6-example-6-7-multiple-inputs-on-a-function-node/))

let's me explain the situation:  
I would like to get the state of a tasmota sonoff switch as an answer to a telegram message.

Let's image I sent on my phone "light?" by telegram...I wish to received "on" or "off".  
good point is that I have on mqtt a retained "stat" topic from the tasmota, so I can know anytime what is it's state.

So my idea was to draw:

- an MQTT input node (with the relevant "stat" topic)
- a telegram receive node.  
and join both their outputs on same "function" node...  
and here I'm stuck...the documentation talk about "topics"....ok for mqtt input...but telegram does not have topic?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [14 April 2019 21:16 UTC](https://discourse.nodered.org/t/2-inputs-function-mqtt-telegram/10143/2 "2019-04-14T21:16:40Z")

</div>

Hi,  
One way would be to use a change node in the path of the tasmota and just set msg.topic to something.  
Another way (as you only have two inputs) is to use the lack of a topic to indicate the other branch. So "if (msg topic == " whatever... else (it must be the other one (tasmota))

---

<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:** [14 April 2019 21:27 UTC](https://discourse.nodered.org/t/2-inputs-function-mqtt-telegram/10143/3 "2019-04-14T21:27:20Z")

</div>

I'm not 100% sure I understand your requirements but from what I can gather...

1. Use a function node after MQTT to store status of light in a flow variable named "light".
2. When you receive a telegram use a switch node to determine if the message is "light?". Connect the output to a function node to retrieve the value from your flow variable and pass it on as a msg.payload to the telegram node as a reply.

Clues.  
Use `flow.set('light', msg.payload);` to store MQTT status in flow context and to retrieve it, `var lightStat = flow.get('light');`
