depoio / node-telegram-bot

Client wrapper for Telegram Bot API (Under heavy development)
MIT License
136 stars 30 forks source link

release 0.1.4 - bug with BOT /getUpdates #49

Closed offerm closed 8 years ago

offerm commented 8 years ago

Bot.prototype._poll is used to poll message to the bot.

the HTTP response in most cases is 409 (timeout). New code (0.1.4) is raising an error for that.

works perfectly with 0.1.2

shernshiou commented 8 years ago

@offerm will look into it. Do you have some code snippet to refer?

vbauer commented 8 years ago

Hello, it looks like a have the same problem:

events.js:87
      throw Error('Uncaught, unspecified "error" event.');
            ^
Error: Uncaught, unspecified "error" event.
    at Error (native)
    at Bot.emit (events.js:87:13)
    at Request._callback (/Users/vbauer/Documents/workspace/js/catzbot/node_modules/node-telegram-bot/lib/Bot.js:232:12)
    at Request.self.callback (/Users/vbauer/Documents/workspace/js/catzbot/node_modules/node-telegram-bot/node_modules/request/request.js:198:22)
    at Request.emit (events.js:110:17)
    at Request.<anonymous> (/Users/vbauer/Documents/workspace/js/catzbot/node_modules/node-telegram-bot/node_modules/request/request.js:1082:10)
    at Request.emit (events.js:129:20)
    at IncomingMessage.<anonymous> (/Users/vbauer/Documents/workspace/js/catzbot/node_modules/node-telegram-bot/node_modules/request/request.js:1009:12)
    at IncomingMessage.emit (events.js:129:20)
    at _stream_readable.js:908:16

UPD: Hmm... Maybe it will be interesting:

shernshiou commented 8 years ago

@vbauer thanks for the headsup. Do you mind sharing your code snippet?

shernshiou commented 8 years ago

I am trying to solve it with this commit 7cc76493911dad5cf4d5b8df05af55751f6e7637

offerm commented 8 years ago

I'm still at 0.1.2 and can't upgrade to latest version. I have 2 servers which share the same token and use pulling. From time to time they get 409 error. with 0.1.2 the pulling continues. with 0.1.9 pulling stops on 409 error.

longstone commented 8 years ago

I'm sure its the programmers intend in the current version, to stop if the response is not 200. However, this seems not optional for a reliabe and stable operation. May be there should be a configuration option to determ the behavior?

https://github.com/depoio/node-telegram-bot/blob/master/lib/Bot.js#L214

      if (err && err.code !== 'ETIMEDOUT') {
        self.emit('error', err);
      } else if (res && res.statusCode === 200) {
        if (body.ok) {
        ....
        }

        if (self.polling) {
            self._poll();
        }

      } else if(res && res.hasOwnProperty('statusCode') && res.statusCode === 401) {
        self.emit('error', new Error('Invalid token.'));
      } else if(res && res.hasOwnProperty('statusCode') && res.statusCode === 409) {
        self.emit('error', new Error('Duplicate token.'));
      } else if(res && res.hasOwnProperty('statusCode') && res.statusCode === 502) {
        self.emit('error', new Error('Gateway error.'));
      } else if(self.pollingRequest && !self.pollingRequest._aborted) { //Skip error throwing, this is an abort due to stopping
        self.emit('error', new Error(util.format('Unknown error')));
      }

So there is no "restart" of polling in the not 200 section.