Async/await works with polling, but not with webHooks
See original GitHub issueContext
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:
myStage.enter(async ctx => {
const someData = await makeRequest();
ctx.reply('Hello');
});
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.
- Telegraf.js Version: 3.25.0
- Node.js Version: 9.7.0
- Operating System: Ubuntu 16.04
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
- Create a stage;
- Use promise in enter callback.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Moving Beyond Polling to Async APIs
This article will show you how to keep your API up-to-date by replacing polling with more modern and effective methods.
Read more >Polling with async/await
This article is based on my real experience with refactoring a small piece of code with polling function so I won't be starting...
Read more >Asynchronous Request-Reply pattern - Azure
One solution to this problem is to use HTTP polling. Polling is useful to client-side code, as it can be hard to provide...
Read more >Expose public API for async system - rest
Short polling. In this pattern, you have a "start" HTTP API which returns an HTTP 202 and a unique identifier of the async...
Read more >Recommendations on how to implement a sync / async use ...
My API client is not able to do polling, but my API backend ... You can make use a library with built-in async/await...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@dmbaranov, Hello!
Not sure how your
await
works, but I think that here your promise chain is broken Try to check your problem code with enabled Webhook and disabled Webhook replyAnd so another moment, that
reply
method is async too. I think that it needs set await prefixref: #320 #497
@tva10 thanks for reply. Setting
webhookReply: false
fixes the problem indeed. Thanks for the explanation, though it’s still not clear enough for me why this is happening… And thanks for the notice aboutasyncWrapper
function as well 😃I’ll mark ticket as closed.