telegram-node-bot icon indicating copy to clipboard operation
telegram-node-bot copied to clipboard

How to send some date to the runInlineMenu callback?

Open dangear opened this issue 7 years ago • 4 comments

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?

dangear avatar Jan 08 '18 22:01 dangear

I have same question, you fix it?

RobotCharly avatar Feb 14 '18 17:02 RobotCharly

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.

dangear avatar Feb 15 '18 01:02 dangear

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.

RobotCharly avatar Feb 19 '18 13:02 RobotCharly

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.

dangear avatar Feb 19 '18 14:02 dangear