-
Notifications
You must be signed in to change notification settings - Fork 907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async/await works with polling, but not with webHooks #567
Comments
After further investigation, I found out one more interesting piece. I have a helper function:
and I use it this way: Changing it to
fixes the problem. Nevertheless, I consider it as a bug because this code works fine with long polling. |
@dmbaranov, Hello! Not sure how your const config = {
telegram: { webhookReply: true } // default true, but need to set false
};
const app = new Telegraf( /*token*/, config); And so another moment, that myStage.enter(async ctx => {
const someData = await makeRequest();
await ctx.reply('Hello');
}); |
@tva10 hi. Pretty much, And actually, the issue is not that my promise chain is broken, it's about that it works with long polling approach but doesn't work with webhook. I didn't make any changes to my code, just changing from Btw, I have 2 different stages:
Whereas they both works fine with long polling approach, stageOne won't work with webhooks. Presumably because it has async callback. But again, what I'm trying to say is, the same code works differently depending on an update approach. |
@dmbaranov yep, I tried to hint that code (with broken promises) works differently too (in #320) I definitly think that in your promise chain something went wrong By default webhook, on update, keep opened https socket as long as promise has pending state or timeout happens. This soket will be used for your first answer/reply. And checked your first Async Wrapper function, I think it needs more returns const asyncWrapper = fn => {
return function(ctx, next) {
return fn(ctx).catch(error => {
console.log('error');
return next();
});
};
}; |
@tva10 thanks for reply. Setting I'll mark ticket as closed. |
For anyone who likes one line code: |
Context
I have a bot and I'm running it with the different update approaches - long polling and webHooks. For some reasons, the same code works with the first option but doesn't work with the second one. After some investigation, I found out that this piece of code breaks webHooks:
What's strange about that, if I'll have 2 ctx.reply(), then it will work and bot will send both messages. But if there is only one ctx.reply(), it won't send anything.
Expected Behavior
The same code should work both with long polling and webHooks.
Current Behavior
Apparently, it doesn't.
Failure Information (for bugs)
There are no any errors.
Steps to Reproduce
The text was updated successfully, but these errors were encountered: