I am trying to send buttons to my telegram bot using the telegram bot api. For now, for creating the buttons, I have to hard code the values in the fields but lets say I want to create the inline keyboard buttons dynamically through an array and passing the array index and the array values as parameters. How should i go about it ?
This is what I tried so far.
var menu =["Nightclub","Parks","Restaurants","Telecom","Internet"];
var options = {
reply_markup: JSON.stringify({
inline_keyboard: [
[{ text: 'Some button text 1', callback_data: '1' }],
[{ text: 'Some button text 2', callback_data: '2' }],
[{ text: 'Some button text 3', callback_data: '3' }]
]
})
};
Lets say I want to pass the data in the menu array dynamically inside my options. How do i go about it ?
2
Answers
If I understood you well.
We gonna use here the Array.map function to create one array using menu array.
Gonna result to :
You can try too using a simple for loop: