Get element switch node

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.

Any clues?.

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

Thanks for the reply.

I have a parsed json before within a function.


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

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

The code will be like this?.


If i put a debug there the output is:


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.

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!

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:

Uhm, ok

I have this going on...


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

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!!

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 ?

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

Thanks a lot !

The 'send response' node should output the response.

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

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...

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

Im using this one:

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

This is my debug output.

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"

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.

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...

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

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 ? 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

I have this one using it right now:

This is the output with the object items.