Closed snurfer0 closed 1 year ago
The issue is happening due to waitForReply()
method, is there a better way to get the user input?
/**
* @dev Waits for user's reply and returns the reply message
* @param {MyContext} ctx Context
* @param {Message} message Message
* @param tries How many tries
* @returns {Promise<Message | undefined>} The message
*/
public async waitForReply(
ctx: MyContext,
message: Message,
tries = 30 // 15 seconds
): Promise<Message | undefined> {
while (tries > 0) {
// Wait for 500 ms
await sleep(500);
// Get latest updates
const [update] = await ctx.api.getUpdates({
allowed_updates: ['message'],
offset: -1,
limit: 1,
});
// Continue if there are no updates
if (!update) {
continue;
}
// Return reply message if found
if (update.message?.reply_to_message?.message_id === message.message_id) {
return update.message;
}
// Decrement tries
tries -= 1;
}
}
Maybe you are looking for this? https://grammy.dev/plugins/stateless-question
Is it a good idea to use this plugin inside the do() function?
it seems like this stateless question is not awaitable and I wont be able to update the menu in the do() function
Await would only work as long as the server is still running. Restarting the server would break this feature so you shouldn’t rely on something like that for a production bot.
Describe the bug After the
do()
function is executed on a button click, all menu buttons stop working. No errors are shown. Am I handling the button execution logic in a wrong way? the menu text is updating with the new context session data, but it breaks after the update.Versions
Version of grammy: "^1.19.0"
Version of grammy-inline-menu: "^8.0.1"
Version of NodeJS: v19.8.1
Version of TypeScript: "^5.0.4"
To Reproduce Steps to reproduce the behavior:
Add a couple of buttons having some logic in the do() function
Expected behavior Buttons should work.