telegram-node-bot
telegram-node-bot copied to clipboard
How to send some date to the runInlineMenu callback?
Have generate inlineMenu from some json-array. Code:
var sectionTitles=[];
var layoutList=[];
for(data in someArray){
sectionTitles.push({
text: data,
callback: (mes) => {
console.log(data)
}
})
layoutList.push('1');
}
tg.runInlineMenu(tgUser, 'sendMessage', 'Press some button:', {}, sectionTitles, layoutList)
Buttons name from JSON-array put correctly. But in console.log show me "undefined". How I can send data from JSON-array in runInlineMenu callback?
I have same question, you fix it?
Yes. But use other way:
I use callback_data field when build buttons array with some parameter (id, short_string and other) and then check callbacks with callbackQueries.
Something like this:
var kb=[]
for(var i=0;i<5;i++){
kb.push([{text:i, callback_data:i}]) //generate buttons array with callback_data field
}
$.sendMessage('Some message', {
reply_markup: JSON.stringify({
inline_keyboard: kb //input buttons
})
});
and then
tg.callbackQueries(($) => { //wait callbacks
console.log($.data) //then find what you need
})
It's work for me.
Nice, Thanks a lot. In my code instead of the "i" I'm using the controller's and command /yes that is in the tutorial. You have some idea how does this work? I want to go from the keyboard button to another command/controller with different code.
I think you can use callback_data with /command and args (if need it).
Something like this:
{text:'Button text', callback_data:'/command, args'};
And then parse it in callbackQueries method.
I'm not shure that is correct way. But I think it's can work.