Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to send some date to the runInlineMenu callback? #195

Open
dangear opened this issue Jan 8, 2018 · 4 comments
Open

How to send some date to the runInlineMenu callback? #195

dangear opened this issue Jan 8, 2018 · 4 comments

Comments

@dangear
Copy link

dangear commented Jan 8, 2018

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?

@RobotCharly
Copy link

I have same question, you fix it?

@dangear
Copy link
Author

dangear commented Feb 15, 2018

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.

@RobotCharly
Copy link

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.

@dangear
Copy link
Author

dangear commented Feb 19, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants