# 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:** 2

<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:32 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/21 "2020-06-10T21:32:34Z")

</div>

> This is the output with the object items.

Could you please follow the request ? Copy the value from the payload and paste it here.  
We cannot see the output of your debug node from this screenshot. And read the documentation for that node (i linked to the same node as you are using).

---

<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:34 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/22 "2020-06-10T21:34:30Z")

</div>

Uh ok...

payload.options.reply\_markup

{"keyboard":[["Apagar luz de prueba"],["Encender luz de prueba"]],"resize\_keyboard":true,"one\_time\_keyboard":true}

---

<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:35 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/23 "2020-06-10T21:35:26Z")

</div>

The full payload. I would highly recommend to also read the [node-red documentation](http://nodered.org/docs/user-guide/) and how to work with messages.

---

<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 21:42 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/24 "2020-06-10T21:42:38Z")

</div>

Ok after looking at the howto on the node info.

you will need to put the stringify() back in the function node code. then repost the debug output from the telegram response node. In my first post i thought the debug output was from the response, i now think that is the confirmation message.

You need to clear the telegram response nodes polling error before continuing.

---

<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:46 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/25 "2020-06-10T21:46:01Z")

</div>

Ok...the pulling error i don't know because it happens...but all works ok...i know there is an error but i can't figured out how to solve it.

This is the output error:

> "ETELEGRAM: 409 Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"

---

<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 21:58 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/26 "2020-06-10T21:58:01Z")

</div>

What are the contents of the function nodes? As it looks like they may be reversed.

---

<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:** [11 June 2020 03:43 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/27 "2020-06-11T03:43:22Z")

</div>

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

it ends with a return msg...

---

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

</div>

There are 2 functions in the howto, the communication function and the response function. I believe that is the communication message function.

 ![Screenshot_20200611-071539](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/1/c1eb0dd8e96ea861ca64035487281a8c837c21c2.png)

your function Iluminacion should be.

 ![Screenshot_20200611-071650](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/8/e8efec0c059b36339ab7877fbbf048f24dfb35ed.png)

It is difficult to tell as we can not see you full flow.

---

<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:** [11 June 2020 14:47 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/29 "2020-06-11T14:47:13Z")

</div>

Uhm ok...

Maybe the misunderstood comes when i want to split those two differents arrays elements within the function. The elements makes them to appear on my telegram keyboard, so whatever the option i select i want to have the selected output to follow the flow on the right path.

Maybe i cannot work that function like that and i have to work it around with a different approach.

Confused...

---

<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:** [11 June 2020 15:02 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/30 "2020-06-11T15:02:56Z")

</div>

Your confused, think how we feel, we have a fraction of information available to you.

We need a clear understanding of your flow  
so post  
your flow layout  
the contents of your functions.

Its like trying to do a jigsaw through a key hole.

As i said before i think you have your function reversed, but it hard to tell from the keyhole.

---

<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:** [11 June 2020 15:06 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/31 "2020-06-11T15:06:12Z")

</div>

Ok...this is my current flows with the inside function details.

`[{"id":"8fd07497.19d0d8","type":"function","z":"31d2354e.c7d47a","name":"Bajar Peliculas","func":"msg.payload = {}\nmsg.payload.chatId = 587232739;\nmsg.payload.type = 'message';\nmsg.payload.content = 'OK...procesando...';\n\nvar opts = {\n reply_to_message_id: msg.payload.messageId,\n reply_markup: JSON.stringify({\n keyboard: [\n ['/peliculas']],\n 'resize_keyboard' : true, \n 'one_time_keyboard' : true\n })\n};\n\nmsg.payload.options = opts;\n\nreturn msg;","outputs":1,"noerr":0,"x":740,"y":300,"wires":[["82fcc8bc.934b28"]]},{"id":"e07e373d.d12bf8","type":"function","z":"31d2354e.c7d47a","name":"Iluminacion","func":"msg.payload = {}\nmsg.payload.chatId = 587232739;\nmsg.payload.type = 'message';\nmsg.payload.content = 'OK...procesando...';\n\nvar opts = {\n reply_to_message_id: msg.payload.messageId,\n reply_markup: ({\n keyboard: [\n ['Apagar luz de prueba'],\n ['Encender luz de prueba']],\n 'resize_keyboard' : true, \n 'one_time_keyboard' : true\n })\n};\n\nmsg.payload.options = opts;\n\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":340,"wires":[["3b38334a.687b2c","1da52795.dbf518"]]},{"id":"1da52795.dbf518","type":"delay","z":"31d2354e.c7d47a","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":720,"y":380,"wires":[["6e1d0238.10561c"]]},{"id":"1ec21f4a.b9bc11","type":"debug","z":"31d2354e.c7d47a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":670,"y":540,"wires":[]},{"id":"6e1d0238.10561c","type":"telegram sender","z":"31d2354e.c7d47a","name":"send response","bot":"4a013224.b5a66c","x":740,"y":420,"wires":[["1ec21f4a.b9bc11"]]},{"id":"4a013224.b5a66c","type":"telegram bot","z":"","botname":"fisgon","usernames":"","chatids":"587232739","baseapiurl":"","updatemode":"polling","pollinterval":"400","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":true}]`

---

<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:** [11 June 2020 15:20 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/32 "2020-06-11T15:20:54Z")

</div>

Ok now fix your post and put the exported flow between  
```  
export  
```  
As the flow has error due to how you posted it  
all code should be posted surrounded by ```

---

<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:** [11 June 2020 15:31 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/33 "2020-06-11T15:31:30Z")

</div>

ok..done it!

---

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

</div>

How are you triggering this flow is ther a command sent from the telegram message?

---

<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:** [11 June 2020 16:12 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/35 "2020-06-11T16:12:58Z")

</div>

Yes im triggering the command with a /menu telegram command using the telegram node that does that, allowing me to capture it.

---

<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:** [11 June 2020 16:48 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/36 "2020-06-11T16:48:40Z")

</div>

ok i am getting a response on `msg.originalMessage.text`

input message command test

```auto
[{"id":"da76c360.33d9e","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"581dc1ad.facb88","type":"function","z":"da76c360.33d9e","name":"Iluminacion","func":"msg.payload.chatId = msg.payload.chatId;\nmsg.payload.type = 'message';\nmsg.payload.content = 'OK...procesando...';\n\nvar opts = {\n reply_to_message_id: msg.payload.messageId,\n reply_markup: JSON.stringify({\n keyboard: [\n ['Apagar luz de prueba'],\n ['Encender luz de prueba']],\n 'resize_keyboard' : true, \n 'one_time_keyboard' : true\n })\n};\n\nmsg.payload.options = opts;\n\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":280,"wires":[["5b82c470.593b64"]]},{"id":"9f91613.55fb42","type":"debug","z":"da76c360.33d9e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"originalMessage.text","targetType":"msg","x":560,"y":420,"wires":[]},{"id":"5b82c470.593b64","type":"telegram sender","z":"da76c360.33d9e","name":"","bot":"8497aed3.3ec0f8","x":640,"y":280,"wires":[[]]},{"id":"c5db8d7.6ccf9f","type":"switch","z":"da76c360.33d9e","name":"","property":"originalMessage.text","propertyType":"msg","rules":[{"t":"eq","v":"Apagar luz de prueba","vt":"str"},{"t":"eq","v":"Encender luz de prueba","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":400,"y":340,"wires":[["9f91613.55fb42"],["9f91613.55fb42"]]},{"id":"3c5c1742.be4278","type":"telegram command","z":"da76c360.33d9e","name":"","command":"test","bot":"8497aed3.3ec0f8","strict":false,"hasresponse":true,"x":140,"y":200,"wires":[["581dc1ad.facb88"],["c5db8d7.6ccf9f"]]},{"id":"8497aed3.3ec0f8","type":"telegram bot","z":"","botname":"e1cidbot","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]

```

 ![Screenshot_20200611-175849](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/396e81dfcc0c667ad7a32de54b835bd3526d30ed.png)

---

<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:** [11 June 2020 17:43 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/37 "2020-06-11T17:43:52Z")

</div>

uhm ok, but you are not passing the input /test over the iluminacion function, i mean, that function node shows up the keyboard on Telegram. I see that you are passing directly the message over the Switch node...

Where should i make that decision?

---

<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:** [11 June 2020 17:59 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/38 "2020-06-11T17:59:38Z")

</div>

Sorry your question is not clear to me. What decision

---

<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:** [11 June 2020 18:00 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/39 "2020-06-11T18:00:33Z")

</div>

The decision of what option to choose.  
Apagar luz de prueba  
Encender luz de prueba

---

<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:** [11 June 2020 18:14 UTC](https://discourse.nodered.org/t/get-element-switch-node/27974/40 "2020-06-11T18:14:15Z")

</div>

The switch node makes the decision of what the pressed keyboard value is. Depending on the return value the switch will use the first or second output.

edit/  
The returned value is also available at -  
msg.payload.content

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

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