# How to pass information from a sensor to my telegram bot

**URL:** <https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839>\
**Category:** General\
**Created:** [5 June 2020 16:19 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839 "2020-06-05T16:19:25Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [5 June 2020 19:46 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/21 "2020-06-05T19:46:08Z")

</div>

Import this example flow if it helps to understand what I tried to say. 🙂

```auto
[{"id":"6c6d0d34.e473e4","type":"inject","z":"9bcda218.23d61","name":"Mock /Temperature","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":60,"wires":[["4d3d08a7.a3a778"]]},{"id":"4d3d08a7.a3a778","type":"change","z":"9bcda218.23d61","name":"Mock s7 node","rules":[{"t":"set","p":"payload","pt":"msg","to":"24","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":200,"y":120,"wires":[["f5017d3a.61af"]]},{"id":"f5017d3a.61af","type":"change","z":"9bcda218.23d61","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.content","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":250,"y":180,"wires":[["8d0ba250.c420a"]]},{"id":"8d0ba250.c420a","type":"debug","z":"9bcda218.23d61","name":"Mock Telegram Sender","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":380,"y":240,"wires":[]}]

```

---

<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:** [5 June 2020 19:46 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/22 "2020-06-05T19:46:09Z")

</div>

> [@ristomatti](#):
>
> No I didn't?

I quoted @osancleca 😉

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [5 June 2020 19:47 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/23 "2020-06-05T19:47:10Z")

</div>

Sorry! Shouldn't be posting after a few Friday drinks. 😜

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [5 June 2020 20:31 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/24 "2020-06-05T20:31:51Z")

</div>

I have tested the flow as you can see in the image when I write from telegram / Temperature reaches the red node it makes the change to 24 but it does not get to return 24 to telegram

 ![RR8](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/6/a618c62215a851e7daff781bc2c1f3a4fb75bb8d.png)

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [5 June 2020 20:32 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/25 "2020-06-05T20:32:37Z")

</div>

Telegram App

 ![RR9](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/3/f34de89e153e5a939d90ec8feb783563cd6f5336.png)

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [5 June 2020 20:33 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/26 "2020-06-05T20:33:45Z")

</div>

I have also changed it to test but that change has not worked for me

---

<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:** [5 June 2020 20:42 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/27 "2020-06-05T20:42:54Z")

</div>

@osancleca Just change the text "mesage.content" to "payload.content" in the change node in your post #14 and it WILL send the message "24" to Telegram. You can just send another screenshot after your change!

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [5 June 2020 20:53 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/28 "2020-06-05T20:53:34Z")

</div>

Have you been able to get any message sent by your bot? Which Telegram node are you using? It might be that you have some configuration missing from the Telegram Sender node. Or it might require certain fields to be in the msg sent to it. I don't have the node installed so I can't check what it's documentation on the sidebar says...

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [5 June 2020 21:02 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/29 "2020-06-05T21:02:17Z")

</div>

[https://flows.nodered.org/node/node-red-contrib-chatbot](https://flows.nodered.org/node/node-red-contrib-chatbot)?

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [7 June 2020 10:52 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/30 "2020-06-07T10:52:13Z")

</div>

Sorry for not answering before but I am new to the forum and I was temporarily blocked because I had a limit of messages in one day

It has worked like this, the problem was that in the change node when the change is made to 24 it has to put you in the form of a string, if you change it to number it did not work there was the problem

 ![RR10](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/752884c51235e2807c45e6d17e11c072ea3cde1d.png)

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [7 June 2020 11:03 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/31 "2020-06-07T11:03:00Z")

</div>

Tomorrow I will have the plc and I will be able to connect node s7 to read the real temperature

Now what I am trying is when I send from telegram / Temperature that it returns 24 but simulating that I have node s7 connected, but I am not able to make the code to detect the entry of 2 variables in the final node of function and make a if that if Temperature enters me it returns the value of the second variable, in this case 24

 ![RR10](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/1/21bda2c128ec0567457afa6c07852666979b69ec.png)

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [7 June 2020 11:03 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/32 "2020-06-07T11:03:20Z")

</div>

![RR11](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/2/a2c680539070e84f2ce34fb80f7b6fc74916ade5.png)

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [7 June 2020 11:03 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/33 "2020-06-07T11:03:41Z")

</div>

![RR12](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/0/b02a77734710127f9702ec302eb398b72656260e.png)

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [7 June 2020 11:10 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/34 "2020-06-07T11:10:23Z")

</div>

I was thinking of using a join node like in this example to capture the 2 variables and in the function node to do an if (msg == Temperature)  
return the value of the second variable, the problem I have is that in this example the variables do arrive with a name and are not a container, I am a bit blocked, any suggestion please

 ![R13](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/5/159a1d66034c1f673b807fc5c0d6996c063034b4.png)

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [7 June 2020 11:12 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/35 "2020-06-07T11:12:59Z")

</div>

[FlowJoin.json](https://discourse.nodered.org/uploads/short-url/tzPDGt5m5HVLYHoRq5KSy5NxYIo.json) (1.5 KB)

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [7 June 2020 11:35 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/36 "2020-06-07T11:35:37Z")

</div>

Based on your screenshots and explanation I think you are over complicating this. How I would imagine this to work is a flow like:

`/Temperature from Telegram -> s7 node -> change node to move temperature from msg.payload to msg.payload.content -> Telegram Sender`

So a direct flow with no branches and no function nodes.

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [7 June 2020 12:00 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/37 "2020-06-07T12:00:02Z")

</div>

I understand that from what you tell me this would be the flow

 ![RR14](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/d/2da84579dd4b90aef76cdc60bea997a1fadc8a42.png)

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [7 June 2020 12:07 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/38 "2020-06-07T12:07:35Z")

</div>

Anyway, I would like to know how to make a function node with several input variables and to be able to make a code in which, depending on the input that I want to generate an output, it is more than anything because I see Red Node as super interesting. And I think that at some point whether or not I am in this project, I will have to face this.

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [7 June 2020 12:37 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/39 "2020-06-07T12:37:02Z")

</div>

> [@osancleca](#):
>
> Anyway, I would like to know how to make a function node with several input variables and to be able to make a code in which, depending on the input that I want to generate an output

Could you give a practical example what you would like to achieve (on a higher level)? Based on that it's simpler to give hints.

Note that while you can do pretty much anything in function nodes, the idea with Node-RED's system is to use the various building blocks to create a flow. In many cases you can achieve an easier to follow flow if you utilise the other core nodes instead of using function nodes. Of course they have their place when other nodes would be unpractical.

Let's say you would have a simple Telegram input node. You would receive whatever you typed to your bot in `msg.payload.content`. You could then use a switch node to route the `msg` to multiple outouts based on what's in `msg.payload.content`. Then you could redirect the outputs to either do something like turn on a light or read data from a sensor like you're trying to do now.

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [7 June 2020 15:22 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/40 "2020-06-07T15:22:05Z")

</div>

ok, i get it, to be able to do if everything can be done through the nodes is interesting since it simplifies life a lot, tomorrow i will have the plc i will try it and tell you, greetings and thanks

[Previous page](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839.md?page=1)

[Next page](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839.md?page=3)
