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

Bot stops randomly

Open LBreda opened this issue 8 years ago • 21 comments

Every now and then, the bot stops working (without crashing).

The forever log is the same every time: http://pastebin.com/0Cwhbe6i

LBreda avatar Aug 05 '16 12:08 LBreda

Seems to be that when telegram-node-bot tries to getUpdates, your network connection closed or (lower probability) Telegram can't answer on domain api.telegram.org. I'm pretty sure, that you have problem with internet connection or DNS server of your provider/machine, because Node.js native module dns.js fires this Error:

No network connection. Error: Error: getaddrinfo ENOTFOUND api.telegram.org api.telegram.org:443
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:79:26)

and that's why module tiny_request can't receive appropriate JSON:

api request error: Body: undefined
Error: SyntaxError: Unexpected token < in JSON at position 0
    at Object.parse (native)
    at IncomingMessage.response.on.e (/node_modules/tiny_request/lib/network.js:68:38)

Also pls see nodejs/node-v0.x-archive#5488 So, that's not fault of telegram-node-bot :smirk:

TemaSM avatar Aug 06 '16 18:08 TemaSM

The error is obviously not generated by telegram-node-bot, but telegram-node-bot does not correctly manage the error.

I don't expect the bot to stop getting updates after a single getUpdates fails.

LBreda avatar Aug 06 '16 18:08 LBreda

How about to manually find out what wrong is going on? Try to use only tiny_request module to make request to api.telegram.org and please submit every log to this issue. Maybe in near future I will make PR with fix for better handling this Error.

TemaSM avatar Aug 06 '16 18:08 TemaSM

I'm working to make my bot work well again in my free time. Still, I had to open this issue here, to enlight the bad behavior of this library.

If you'll work on it I'll be grateful! I haven't explored the version 3 internals yet.

LBreda avatar Aug 06 '16 18:08 LBreda

So, I gonna try to reproduce the same issue as you have, and then find out how to fix or just handle this Error. Please stay tuned, I will give you a link for forked repo, where I will submit commits with fix, then you may just npm install name/repo in a while instead just npm update, cause author of this repo doesn't maintain it so often :pensive:

TemaSM avatar Aug 06 '16 18:08 TemaSM

This is a Telegram API error. Affecting everyone. Confirmed.

kamikazechaser avatar Aug 06 '16 18:08 kamikazechaser

Thanks for info, but anyway we should implement error handling :sweat_smile:

TemaSM avatar Aug 06 '16 19:08 TemaSM

Any news?

LBreda avatar Aug 15 '16 10:08 LBreda

Upgrade both node and the module to the latest versions.

kamikazechaser avatar Aug 15 '16 11:08 kamikazechaser

I'm already on v6@latest and its reproducing

VitaliyR avatar Aug 24 '16 21:08 VitaliyR

hey, can i get message id and chat id user with bot, i wanna use forwardMessage method but don't know how to get the parameter...

frengkys avatar Aug 25 '16 09:08 frengkys

@frengkys Please read documentation/API here

TemaSM avatar Aug 25 '16 09:08 TemaSM

actually i am still reading it but dont know how to call it heheheh

frengkys avatar Aug 25 '16 09:08 frengkys

how to get what user send to the bot? there is some method ?

im just wanna console.log(whatUserSend) on my command prompt

frengkys avatar Aug 29 '16 07:08 frengkys

@frengkys Welcome to Gitter chat: telegram-node-bot - answered you here to prevent spam in Issues.

TemaSM avatar Aug 29 '16 11:08 TemaSM

Hey guys, at this moment we have:

  • retry requests on any network error code
  • retry requests when we cant parse Json (because of error in tg api)
  • retry on 500 code
  • reject on any other errors

Dont know what else to add, any ideas?

Naltox avatar Sep 09 '16 18:09 Naltox

p.s. I will publish soon v4.0 with webhooks, hope that helps

Naltox avatar Sep 09 '16 18:09 Naltox

@Naltox how is v4.0 is going? :)

sosnovsky avatar Sep 27 '16 14:09 sosnovsky

using version 3.0.12 . Bot unresponsive after this error:

Sep 27 12:02:02  app/web.1:  [error]    
Sep 27 12:02:02  app/web.1:  api request error: Telegram returned some html instead of json. Body: undefined 
Sep 27 12:02:02  app/web.1:  Error: SyntaxError: Unexpected token < in JSON at position 0 
Sep 27 12:02:02  app/web.1:      at Object.parse (native) 
Sep 27 12:02:02  app/web.1:      at IncomingMessage.response.on.e (/app/node_modules/tiny_request/lib/network.js:68:38) 
Sep 27 12:02:02  app/web.1:      at emitNone (events.js:91:20) 
Sep 27 12:02:02  app/web.1:      at IncomingMessage.emit (events.js:185:7) 
Sep 27 12:02:02  app/web.1:      at endReadableNT (_stream_readable.js:934:12) 
Sep 27 12:02:02  app/web.1:      at _combinedTickCallback (internal/process/next_tick.js:74:11) 
Sep 27 12:02:02  app/web.1:      at process._tickCallback (internal/process/next_tick.js:98:9) 
Sep 27 12:02:03  app/web.1:  [log]    
Sep 27 12:02:03  app/web.1:  Retry request TelegramApiRequest { 
Sep 27 12:02:03  app/web.1:    _method: 'getUpdates', 
Sep 27 12:02:03  app/web.1:    _params: { timeout: 50, offset: 0 }, 
Sep 27 12:02:03  app/web.1:    _multipart: undefined } 
Sep 27 12:02:03  app/web.1:  [error]    
Sep 27 12:02:03  app/web.1:  api request error: Telegram returned some html instead of json. Body: undefined 
Sep 27 12:02:03  app/web.1:  Error: SyntaxError: Unexpected token < in JSON at position 0 
Sep 27 12:02:03  app/web.1:      at Object.parse (native) 
Sep 27 12:02:03  app/web.1:      at IncomingMessage.response.on.e (/app/node_modules/tiny_request/lib/network.js:68:38) 
Sep 27 12:02:03  app/web.1:      at emitNone (events.js:91:20) 
Sep 27 12:02:03  app/web.1:      at IncomingMessage.emit (events.js:185:7) 
Sep 27 12:02:03  app/web.1:      at endReadableNT (_stream_readable.js:934:12) 
Sep 27 12:02:03  app/web.1:      at _combinedTickCallback (internal/process/next_tick.js:74:11) 
Sep 27 12:02:03  app/web.1:      at process._tickCallback (internal/process/next_tick.js:98:9) 
Sep 27 12:02:04  app/web.1:  [error]    
Sep 27 12:02:04  app/web.1:  api request error: Telegram returned some html instead of json. Body: undefined 
Sep 27 12:02:04  app/web.1:  Error: SyntaxError: Unexpected token < in JSON at position 0 
Sep 27 12:02:04  app/web.1:      at Object.parse (native) 
Sep 27 12:02:04  app/web.1:      at IncomingMessage.response.on.e (/app/node_modules/tiny_request/lib/network.js:68:38) 
Sep 27 12:02:04  app/web.1:      at emitNone (events.js:91:20) 
Sep 27 12:02:04  app/web.1:      at IncomingMessage.emit (events.js:185:7) 
Sep 27 12:02:04  app/web.1:      at endReadableNT (_stream_readable.js:934:12) 
Sep 27 12:02:04  app/web.1:  [log]    
Sep 27 12:02:04  app/web.1:      at _combinedTickCallback (internal/process/next_tick.js:74:11) 
Sep 27 12:02:04  app/web.1:      at process._tickCallback (internal/process/next_tick.js:98:9) 
Sep 27 12:02:04  app/web.1:  Retry request TelegramApiRequest { 
Sep 27 12:02:04  app/web.1:    _method: 'getUpdates', 
Sep 27 12:02:04  app/web.1:    _params: { timeout: 50, offset: 0 }, 
Sep 27 12:02:04  app/web.1:    _multipart: undefined } 
Sep 27 12:02:06  app/web.1:  [log]    
Sep 27 12:02:06  app/web.1:  Retry request TelegramApiRequest { 
Sep 27 12:02:06  app/web.1:    _method: 'getUpdates', 
Sep 27 12:02:06  app/web.1:    _params: { timeout: 50, offset: 0 }, 
Sep 27 12:02:06  app/web.1:    _multipart: undefined } 
Sep 27 12:02:06  app/web.1:  [error]    
Sep 27 12:02:06  app/web.1:  api request error: Telegram returned some html instead of json. Body: undefined 
Sep 27 12:02:06  app/web.1:  Error: SyntaxError: Unexpected token < in JSON at position 0 
Sep 27 12:02:06  app/web.1:      at Object.parse (native) 
Sep 27 12:02:06  app/web.1:      at IncomingMessage.response.on.e (/app/node_modules/tiny_request/lib/network.js:68:38) 
Sep 27 12:02:06  app/web.1:      at emitNone (events.js:91:20) 
Sep 27 12:02:06  app/web.1:      at IncomingMessage.emit (events.js:185:7) 
Sep 27 12:02:06  app/web.1:      at endReadableNT (_stream_readable.js:934:12) 
Sep 27 12:02:06  app/web.1:      at _combinedTickCallback (internal/process/next_tick.js:74:11) 
Sep 27 12:02:06  app/web.1:      at process._tickCallback (internal/process/next_tick.js:98:9) 
Sep 27 12:02:07  app/web.1:  [log]    
Sep 27 12:02:07  app/web.1:  Retry request TelegramApiRequest { 
Sep 27 12:02:07  app/web.1:    _method: 'getUpdates', 
Sep 27 12:02:07  app/web.1:    _params: { timeout: 50, offset: 0 }, 
Sep 27 12:02:07  app/web.1:    _multipart: undefined } 
Sep 27 12:14:41  app/web.1:  [warn]    
Sep 27 12:14:41  app/web.1:  Got Internal server error from Telegram. Body: { ok: false, 
Sep 27 12:14:41  app/web.1:    error_code: 500, 
Sep 27 12:14:41  app/web.1:    description: 'Internal server error: restart' } 
Sep 27 12:14:42  app/web.1:  [log]    
Sep 27 12:14:42  app/web.1:  Retry request TelegramApiRequest { 
Sep 27 12:14:42  app/web.1:    _method: 'getUpdates', 
Sep 27 12:14:42  app/web.1:    _params: { timeout: 50, offset: 0 }, 
Sep 27 12:14:42  app/web.1:    _multipart: undefined } 
Sep 27 12:14:42  app/web.1:  [warn]    
Sep 27 12:14:42  app/web.1:  Api error: Body: { ok: false, 
Sep 27 12:14:42  app/web.1:    error_code: 429, 
Sep 27 12:14:42  app/web.1:    description: 'Too Many Requests: retry after 5', 
Sep 27 12:14:42  app/web.1:    parameters: { retry_after: 5 } }

dutu avatar Sep 28 '16 07:09 dutu

Issue persists on v4 API. Does the code have retry mechanism for network disconnection? And when the bot not response to commands, the web admin page also cannot be reached.

chiu0602 avatar Oct 23 '16 13:10 chiu0602

I usually force keep the bot alive by handling any uncaught exceptions!

kamikazechaser avatar Oct 23 '16 13:10 kamikazechaser