How to trigger function on menu item click, awat for function to complete, then return button with external url
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?
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!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.