Naltox / telegram-node-bot

Node module for creating Telegram bots.
MIT License
721 stars 143 forks source link

Bot stops randomly #101

Open LBreda opened 8 years ago

LBreda commented 8 years ago

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

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

TemaSM commented 8 years ago

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:

LBreda commented 8 years ago

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.

TemaSM commented 8 years ago

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.

LBreda commented 8 years ago

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.

TemaSM commented 8 years ago

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:

kamikazechaser commented 8 years ago

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

TemaSM commented 8 years ago

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

LBreda commented 8 years ago

Any news?

kamikazechaser commented 8 years ago

Upgrade both node and the module to the latest versions.

VitaliyR commented 8 years ago

I'm already on v6@latest and its reproducing

frengkys commented 8 years ago

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...

TemaSM commented 8 years ago

@frengkys Please read documentation/API here

frengkys commented 8 years ago

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

frengkys commented 8 years ago

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

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

TemaSM commented 8 years ago

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

Naltox commented 7 years ago

Hey guys, at this moment we have:

Dont know what else to add, any ideas?

Naltox commented 7 years ago

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

sosnovsky commented 7 years ago

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

dutu commented 7 years ago

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 } }
chiu0602 commented 7 years ago

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.

kamikazechaser commented 7 years ago

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