EdJoPaTo / grammy-inline-menu

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

Can't manually navigate to menu in the tree having button triggers hide: true #202

Closed iamcsharper closed 1 year ago

iamcsharper commented 1 year ago

Describe the bug When you add a submenu (path /typ) to root menu, and set hide: () => true, you cannot navigate to the path /typfrom anywhere else via otherMenu.navigate('Click', '/typ')

I need this case to implement scenario:

  1. User is in "checkout" menu
  2. User clicks on button "Pay"
  3. On click, a POST request is sent
  4. If the order is created, I navigate the user to menu "thank you page"
  5. If the order is corrupted, I navigate the user to menu "order error"

I have to process the click and navigate the user at the same time, that's why .submenu is not suitable for me. Besides, I will have other code parts that will navigate the user to the "thank you page" menu, that's why I can't make the POST request IN the "thank you page" menu "render" function

I also tried the resendMenuToContext function, but it looks like I can't use any buttons or selects in the menu sent, because it is not registered in the tree and not processed (leads to main menu on any click)

Versions

Expected behavior I expect it to be controllable via options or middlewares, should the router ignore a path if its hidden, OR to have a "async do" option in submenu

EdJoPaTo commented 1 year ago

You can change the hide function to something like ctx => !isOrderSuccessful(ctx) or ctx => !didOrderFail(ctx) or something like that. But I think multiple menus with their own MenuMiddleware each seems more fitting here.

You can have the main menu on / and add another MenuMiddleware for ordererror/ and orderdone/. I am currently not sure about the do function return path as its a different middleware then. But orderSuccessfulMiddleware.replyToContext(ctx) will work for sure.

Hope this helps?

iamcsharper commented 1 year ago

Thanks for the reply!