pengrad / java-telegram-bot-api

Telegram Bot API for Java

Home Page:https://core.telegram.org/bots

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Provide error callbacks

maxim-kukushkin opened this issue · comments

Currently if the bot faces any general issues (like network errors while listening to updates), it writes its own log entries. For example:

Mar 10, 2023 1:25:07 AM com.pengrad.telegrambot.impl.UpdatesHandler$1 onFailure
INFO: Update listener failure
java.net.UnknownHostException: api.telegram.org
<...>

First of all it seems to use its own logger, not slf4j, which results in a different formatting than the rest of the app.

However, the main request is:

Would it be possible to set a custom events callback which will be invoked when it fails to connect or restores the connection? So that the application could provide its own logging/suppress the errors/etc., etc.

In this case the current logging that the bot does could be the default callback. However, if it's overridden by the app, then the app's callback is invoked instead.

There's ExceptionHandler

bot.setUpdatesListener(new UpdatesListener() {
    @Override
    public int process(List<Update> updates) {
        return UpdatesListener.CONFIRMED_UPDATES_ALL;
    }
}, new ExceptionHandler() {
    @Override
    public void onException(TelegramException e) {
    }
});

Thanks!
Like I mentioned in the other issue, may be you can consider adding an example in the sample code or the documentation?