Bot stops randomly
Every now and then, the bot stops working (without crashing).
The forever log is the same every time: http://pastebin.com/0Cwhbe6i
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:
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.
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.
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.
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:
This is a Telegram API error. Affecting everyone. Confirmed.
Thanks for info, but anyway we should implement error handling :sweat_smile:
Any news?
Upgrade both node and the module to the latest versions.
I'm already on v6@latest and its reproducing
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 Please read documentation/API here
actually i am still reading it but dont know how to call it heheheh
how to get what user send to the bot? there is some method ?
im just wanna console.log(whatUserSend) on my command prompt
@frengkys Welcome to Gitter chat: telegram-node-bot - answered you here to prevent spam in Issues.
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?
p.s. I will publish soon v4.0 with webhooks, hope that helps
@Naltox how is v4.0 is going? :)
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 } }
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.
I usually force keep the bot alive by handling any uncaught exceptions!