EdJoPaTo / grammy-inline-menu

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

Redirect to submenu after question #134

Closed QreKer closed 4 years ago

QreKer commented 4 years ago

Hello. I want to redirect my user after answering the question to submenu but got an error I don't understand. I'm using such stack: telegraf telegraf-inline-menu telegraf-stateless-question telegram-mysql-session

My current code in attachments as well as error stacktrace. telegrafStatelessQuestion.zip

I will be fine with 2 solutions:

  1. User answers the question and menu element "test"(line 34) will be hidden if ctx.session.test value exists(after answer menu not updated if I use return '/' in 'do" and only hidden if I press button "test" again)
  2. User will be redirected to submenu "Authorized"(line 61) after question.

Thank you in advance for your help

EdJoPaTo commented 4 years ago

I assume you want to achieve something quite similar to #135. Please also check my response there.

Your authorized menu is probably a menu independent from the main menu (not reachable as a submenu) so you probably need another MenuMiddleware. If you specify the root path of that MenuMiddleware as auth/ then you can supply auth/ as third argument of replyMenuToContext (line 24 in your code).

Currently you set the additionalState to auth which is always the same (thats why I suggested to pass it directly in line 24) and does not end with a /. Thats why the error came up as a path of a menu was expected which end with /. (A menu always ends with /, buttons never do)

Also as you want to reply the question (line 40) you probably don't want to update the menu afterwards so i suggest return false instead.

Hope it helps :) If you have feedback on how to improve the documentation on multiple MenuMiddlewares I'm all ears :)

QreKer commented 4 years ago

Hello. Thank you for answer. I tried as you say, also checked #135 but there same issue as like when I'm using "hide". You can check current code with results screenshots: tg.zip

As you can see after the question user not redirected to "auth/" and only will be redirected if manually clicks "test" button again. Also in console screenshot you can see output of 2 console.log on lines 26 and 27. Both says that user answered the question and path that must be user is "auth/". On line 46 I tried both:

  1. return false;
  2. return 'auth/'; Both works in the same way as I mentioned above in this message.

Can it happen if I'm using polling and not webhooks? UPD: tested with webhook, same result.

UPD2:

Ok, now I understand the issue. I used await replyMenuToContext(menuTemplate, ctx, additionalState); Which can return only menuTemplate(in my case). I just misunderstood documentation because there no explanation for each argument for replyMenuToContext, you should add this. Or I can post it to this issue on this or next weekdays(have no time now). Keep it open if I can post there an class documentation that should be added to main documentation.

Thank you for your help.

EdJoPaTo commented 4 years ago

There is some documentation for the arguments in the JSDoc. Editors like VSCode should show it?

Maybe it should be improved then? Do you have suggestions?