grammy-inline-menu icon indicating copy to clipboard operation
grammy-inline-menu copied to clipboard

How to trigger function on menu item click, awat for function to complete, then return button with external url

Open launchthatbrand opened this issue 3 years ago • 1 comments

Describe your goal I want the user to select "pay with Stripe", trigger a function to create the checkout and get the payment link, then push button link into a button.

I have a function that generates a stripe checkout link ("https://checkout.stripe.com/*******")

I have a menu that goes Plans (customer selects one of the 3 available plans) -> Payment Options (card, accesscode, crypto) -> then renders a 2nd level submenu with 1 interact button that says "Click To Pay".

At the moment the "Click To Pay" button is rendered before the url has been returned by the function. How can i code this so that the bot replies with an immediate text "generating payment link..." then finally the url button once its generated?

Would I have to use a combination of this inline menu and the regular grammy menu await ctx.reply?

launchthatbrand avatar Sep 27 '22 23:09 launchthatbrand

The .url() accepts constants, functions and async functions. I assume your function generating the checkout link is async so you could supply it as the url function:

menu.url('Click to Pay', async ctx => {
  const url = await generateCheckoutLink(ctx.session.selectedPlan);
  return url;
});

That way the menu will wait for your generateCheckoutLink function before continuing to create the menu. This will always result in a menu with a working url.

Hope it helps!

EdJoPaTo avatar Sep 28 '22 09:09 EdJoPaTo

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Oct 28 '22 20:10 stale[bot]