node-telegram-bot-api icon indicating copy to clipboard operation
node-telegram-bot-api copied to clipboard

using stopPolling in polling_error with cancel param

Open DynamicSTOP opened this issue 7 years ago • 0 comments

Bug Report

I have read:

I am using the latest version of the library. node v8.11.1

Expected Behavior

Once i get polling_error event i want to stop polling for sometime (couple minutes) and then turn polling on again. I am not 100% sure, but i expect that cancel param shouldn't affect anything since i am inside polling_error.

Actual Behavior

If i use cancel:true it keeps polling.

Sun Apr 29 13:20:47 Telegram Bot error: {"code":"EFATAL","message":"EFATAL: Error: write EPROTO 101057795:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:openssl\\ssl\\s23_clnt.c:827:\n"}
Sun Apr 29 13:20:47 is polling? true
Sun Apr 29 13:20:47 stopPolling
Sun Apr 29 13:20:47 is polling? false
Sun Apr 29 13:20:48 Telegram Bot error: {"code":"EFATAL","message":"EFATAL: Error: write EPROTO 101057795:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:openssl\\ssl\\s23_clnt.c:827:\n"}
Sun Apr 29 13:20:48 is polling? true
Sun Apr 29 13:20:48 stopPolling
Sun Apr 29 13:20:48 is polling? false

Steps to reproduce the Behavior

Get VPN to Russia (ban telegram.org in /etc/hosts ?) and use this with any bot (i guess).

        this.bot.on('polling_error', async (error) => {
            console.log((`Telegram Bot error: `+JSON.stringify(error)).error);
            console.log(`is polling? `+this.bot.isPolling());
            await this.bot.stopPolling({cancel: true});
            console.log(`stopPolling`);
            console.log(`is polling? `+this.bot.isPolling());
            //setTimeout(this.bot.startPolling,60000,{restart:true});
        });

P.S. generally i tried feed telegram bot with custom request that has custom agent require('proxy-agent') to my proxy. It failed so i gave up and used VPN to tunnel all traffic. It usually goes 99.9(9)% ok, but sometimes fails (i blame dns requests to local ISP) and i would like to stop filling my logs with telegram bot errors.

P.P.S. it's great bot api! thanks for your work on it!

DynamicSTOP avatar Apr 29 '18 10:04 DynamicSTOP