EdJoPaTo / grammy-inline-menu

Inline Menus for Telegram made simple. Successor of telegraf-inline-menu.
MIT License
354 stars 46 forks source link

How do I completely close the menu after interacting with a user? #70

Closed elithe1 closed 4 years ago

elithe1 commented 4 years ago

Describe your goal I'm trying to close the menu after the user pressed on a few buttons and I dispatched a request handling it's data choices somewhere else.

Expected I assumed there will be some menu.close() functionality that I could invoke from within setFunc() callback.

I feel it is super trivial and I'm just missing something.

EdJoPaTo commented 4 years ago

I assume this should work:

menu.simpleButton('Delete Menu Message', 'close', {
  doFunc: async ctx => ctx.deleteMessage()
}

Using a simple button for a simple thing to do without updating the menu afterwards. On the doFunc just use the ctx like you would with telegraf and delete the message. I have not tested it but it should work.

Keep in mind users like to have some kind of history. To see what they have done. Maybe keeping a message with the end result without buttons left to do anything is a nicer approach. (Implement hide on all the buttons or just use doFunc with ctx.editMessage which will also remove the keyboard while doing so.

Hope it helps :)

elithe1 commented 4 years ago

I actually manage to close a button. But in my case I show three questions(buttons) to the user and I wanted to close all questions after the user choses one and this was wierd. I use hide with a toggle boolean (attached to the session) like you had in the example but it doesn't seem to make all buttons disappear. Only the pressed button disappears.

Thanks for the UX input, it is actually very important and I'm communicating to the user the results of what happened after he presses on stuff.

EdJoPaTo commented 4 years ago

I'm not sure I understood the problem. Currently I understand something like this:

const menu = new TelegrafInlineMenu(…)
menu.question('question1', …, {hide: ctx => ctx.session.hideAll, …})
menu.question('question2', …, {hide: ctx => ctx.session.hideAll, …})
menu.question('question3', …, {hide: ctx => ctx.session.hideAll, …})

The menu has 3 question buttons. Once you set ctx.session.hideAll to true it will hide all the buttons on updating the message?

EdJoPaTo commented 4 years ago

I close this due to inactivity. When you still have a question related to this feel free to answer or create a new issue. :)