telegraf: How to handle errors
Hello,
I’m currently doing a little project using Telegraf and I have a problems handling errors. I have read a lot about it and I have seen some solutions but they are not working.
The code I am having problems with is basically this one:
const bot = new Telegraf(config.telegram.token);
bot.on('message', (ctx) =>
process_message(ctx.message, callback)
);
bot.startPolling();
And, for example, when I open another bot I have this problem, very reported:
Failed to process updates. { Error: 409: Conflict: terminated by other getUpdates request
I have seen that you can use bot.catch(err => console.log(err)); but it’s not working for me. As I know, Telegraf works with promises, so I also tried bot.startPolling().catch(err => console.log(err));
I’m sorry it this have been answered already, as you can see I did some research but nothing is working because I’m missing something.
Thanks a lot.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 23 (8 by maintainers)
And what do you want?
@msolefonte Yes, I re-checked the case. If you want to pass 409’s, you will face update duplicates leading to multiple processing for same messages:
node_modules/telegraf/core/network/client.js:280 :
So the only solution for me rn is to remove telegraf from my project and rewrite functionality by my hands with appropriate handling.
Why don’t I have it? Maybe it’s your environment issue? Check out things like a firewall and so on…
I finally decided to edit the bot to add the option to reconnect after the 409 error. You can take a look to it here: https://github.com/telegraf/telegraf/pull/494
Lol I don’t know how scaling of Node.js works in your world, but in mine I use pm2 that runs multiple node instances plus several physical hosts thats comes out with 12 parallel node instances minimum. All of them running the same code and sharing the same telegram bot token. And ultimately expected that after running u momentally get this error:
Dear telegram and telegraph, I don’t need to make sure, I completely sure that I run multiple instances and I will not left only one!
@msolefonte I completely agree with your problem. It turns out that Telegraph needs to be finalized to become production-ready
You could also look at this: https://telegraf.js.org/#/?id=error-handling
To auto reconnect after this kind of conflict, leaving it as a warning or something like that