# Get element switch node

**URL:** <https://discourse.nodered.org/t/get-element-switch-node/27974>\
**Category:** General\
**Created:** [8 June 2020 06:00 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974 "2020-06-08T06:00:33Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [8 June 2020 06:00 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/1 "2020-06-08T06:00:33Z")

</div>

Hi All node-reder's!

I been messing around with the switch node and i'm stuck getting the element described with the screenshot below.

I want to get the lined elements and make a switch conditions with them, but for one reason it is failing.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/1/d14e3b9ccfe968ffa631fc08021a82d2154e7d0d.png)

Any clues?.  
Regards,

---

<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:** [8 June 2020 06:38 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/2 "2020-06-08T06:38:51Z")

</div>

The elements you are trying to get are part of a string as they are red and between "".  
You would need to JSON.parse() the msg.payload.options.reply\_markup element to turn it into an object

[https://www.w3schools.com/js/js\_json\_parse.asp](https://www.w3schools.com/js/js_json_parse.asp)

---

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [8 June 2020 06:50 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/3 "2020-06-08T06:50:31Z")

</div>

Thanks for the reply.

I have a parsed json before within a function.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/1/51ffac15760d1785908858ff3fb9207a9bcc8ff4.png)

---

<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:** [8 June 2020 06:55 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/4 "2020-06-08T06:55:23Z")

</div>

With that code you created the string. Don't stringify then the elements will be accessible.

---

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [9 June 2020 04:00 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/5 "2020-06-09T04:00:18Z")

</div>

Sorry i don't get it. So, i don stringfy the elements ?

The code will be like this?.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/5/4578641ef30208c498184f4327d8963a77d2e9ed.png)

If i put a debug there the output is:

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

Thanks!

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [9 June 2020 07:20 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/6 "2020-06-09T07:20:42Z")

</div>

Hi @Marty1982

it depends whether you are constructing this structure for a reason - for example, do you then pass this message to a particular node that expects this format?

When you stringify the property then the `payload.options.reply_markup` property is a single string. It doesn't have properties and you can't directly address the values inside it.

If you don't stringify the property then it is a JavaScript object and you can address all of its properties - such as `payload.options.reply_markup.keyboard` etc.

But if you are generating this message yourself in a Function node, then why do you need a Switch node to route it? Your Function node could have multiple outputs and you could add the logic in the Function node to choose which output it is sent on.

Without more information about what your wider flow looks like, its hard to be more specific.

---

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [9 June 2020 19:48 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/7 "2020-06-09T19:48:29Z")

</div>

Ok, let me if i get it. I have a function where i have two keyboard options to select from. Im ok with that. Whenever i select any of the options i want to clear that output so i can route the message to a GET node to my light, so i can turn them on or off.

So, with my actual examples, i understand that i dont need to Stringfy that keyboard options, is that correct?.

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [9 June 2020 20:13 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/8 "2020-06-09T20:13:26Z")

</div>

You have a function node that creates a message for telegram.  
You send this message to a telegram node.  
In telegram a keyboard will appear.  
You choose a response option.  
The telegram node will produce the response.

Connect the switch node to the telegram (response) node. (or depending on the type of telegram node, you might even have a telegram switch node that keeps track of the conversation).

something like:

 ![Screenshot 2020-06-09 at 22.12.32](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/b/9b7ee5f15e729e50c00256b690dd485182e1027e.jpeg)

---

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [9 June 2020 20:32 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/9 "2020-06-09T20:32:26Z")

</div>

Uhm, ok

I have this going on...

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/8/5873242b3c25e3cd3592e4fd068f77f7e40bce2e.png)

Function Iluminacion has this information and the output will be an array like this...

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

So how can i get that arrays within a switch node?.  
I tried to copy the path and i got this: payload.options.reply\_markup.keyboard[0]

thanks a lot!!

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [9 June 2020 20:45 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/10 "2020-06-09T20:45:21Z")

</div>

Was asked before: why do you need to get the data from the array that the function node sends ?  
Don't you want to capture the response instead ?

---

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [10 June 2020 12:47 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/11 "2020-06-10T12:47:40Z")

</div>

Yes that is why im confused. How to get the data from the response?.

Thanks a lot !

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [10 June 2020 15:49 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/12 "2020-06-10T15:49:58Z")

</div>

The 'send response' node should output the response.

---

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [10 June 2020 17:39 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/13 "2020-06-10T17:39:20Z")

</div>

Ok...the send response debug output is this.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/6/068ded66a1a9a5db3b58ea13906a4918b6ce8d61.png)

So i get it now...i can't see the option that i input in my telegram option. So, is not receveing anyhing from telegram keyboard...weird...

I need to work in how to get the selection from telgram keyboard then...

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [10 June 2020 18:18 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/14 "2020-06-10T18:18:06Z")

</div>

Which telegram contrib node are you using?  
What does the rest of the debug message say?

---

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [10 June 2020 19:08 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/15 "2020-06-10T19:08:31Z")

</div>

Im using this one:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/c/3cbc564513cf81345b1acd2783f123685e1a378c.png)

I dont use RedBot because it shows me an error when working with functions and some stuff.

This is my debug output.

object  
payload: object  
chatId: 587232739  
type: "message"  
content: object  
message\_id: 13487  
from: object  
chat: object  
date: 1591816007  
text: "OK...procesando..."

options: object  
reply\_markup: "{"keyboard":[["Apagar luz de prueba"],["Encender luz de prueba"]],"resize\_keyboard":true,"one\_time\_keyboard":true}"  
chat\_id: 587232739  
text: "OK...procesando..."  
sentMessageId: 13487  
originalMessage: object  
message\_id: 13484  
from: object  
chat: object  
date: 1591816001  
text: "Iluminacion"

\_msgid: "a1014c3d.76722"

---

<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:** [10 June 2020 19:34 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/16 "2020-06-10T19:34:14Z")

</div>

> [@Marty1982](#):
>
> So how can i get that arrays within a switch node?.  
> I tried to copy the path and i got this: payload.options.reply\_markup.keyboard[0]

`payload.options.reply_markup.keyboard` - will give you the 2 element array  
`payload.options.reply_markup.keyboard[0] `- will give you the first object in the array  
`payload.options.reply_markup.keyboard[1]`- will give you the second object in the array  
`payload.options.reply_markup.keyboard[0][0]` will give you the value of the object in the first array element.  
`payload.options.reply_markup.keyboard[1][0]` will give you the value of the object in the second array element.

But after reading all replys i still unsure to what you are doing.

---

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [10 June 2020 20:37 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/17 "2020-06-10T20:37:52Z")

</div>

Thanks for reply,  
I want to get the payload or whatever from the telegram screen selection keyboard. When i touch a selection i want to capture that and make something with it.

So, the output is not giving me the right output...

---

<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:** [10 June 2020 20:48 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/18 "2020-06-10T20:48:04Z")

</div>

your telegram response node shows a polling error, But i see no error outputed in your debug window.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [10 June 2020 21:18 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/19 "2020-06-10T21:18:39Z")

</div>

I still dont know which contrib node that is, as there are multiple telegram nodes, but by the shear number of nodes I would expect some decent documentation. Are you using [this one](https://github.com/windkh/node-red-contrib-telegrambot) ? It includes a switch node, which is specifically for the purpose you are looking for. Also a lot of information and examples on that link, including keyboards+response handling.

And your debug output does not show the full debug output. (see the "object"s, which contains more information).  
Use this icon to copy the complete payload:

![Screenshot 2020-06-10 at 23.16.15](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/c/5c054f20e5a9b60d4cfc9439c33e9f17368505eb.jpeg)

---

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [10 June 2020 21:31 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/20 "2020-06-10T21:31:13Z")

</div>

I have this one using it right now:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b32e235a187d992554454155bd232b09af08eb0c.png)

This is the output with the object items.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/6/068ded66a1a9a5db3b58ea13906a4918b6ce8d61.png)

[Next page](https://discourse.nodered.org/t/get-element-switch-node/27974.md?page=2)
