mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-29 05:17:41 +00:00
Merge pull request #117 from w-site/bug/#116-get-409-error
Fix: If use switch between webHook or Polling you get an 409 (http://telegram.wiki/bots:boterrorcode) telegram error. #116
This commit is contained in:
commit
b28f30a2d2
@ -2,6 +2,7 @@ const Promise = require('bluebird');
|
|||||||
const debug = require('debug')('node-telegram-bot-api');
|
const debug = require('debug')('node-telegram-bot-api');
|
||||||
const request = require('request-promise');
|
const request = require('request-promise');
|
||||||
const URL = require('url');
|
const URL = require('url');
|
||||||
|
const ANOTHER_WEB_HOOK_USED = 409;
|
||||||
|
|
||||||
class TelegramBotPolling {
|
class TelegramBotPolling {
|
||||||
|
|
||||||
@ -62,6 +63,25 @@ class TelegramBotPolling {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_unsetWebHook() {
|
||||||
|
return request({
|
||||||
|
url: URL.format({
|
||||||
|
protocol: 'https',
|
||||||
|
host: 'api.telegram.org',
|
||||||
|
pathname: `/bot${this.token}/setWebHook`
|
||||||
|
}),
|
||||||
|
simple: false,
|
||||||
|
resolveWithFullResponse: true
|
||||||
|
})
|
||||||
|
.promise()
|
||||||
|
.then(resp => {
|
||||||
|
if (!resp) {
|
||||||
|
throw new Error(resp);
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
_getUpdates() {
|
_getUpdates() {
|
||||||
const opts = {
|
const opts = {
|
||||||
qs: {
|
qs: {
|
||||||
@ -84,6 +104,10 @@ class TelegramBotPolling {
|
|||||||
.promise()
|
.promise()
|
||||||
.timeout((10 + this.timeout) * 1000)
|
.timeout((10 + this.timeout) * 1000)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
|
if (resp.statusCode === ANOTHER_WEB_HOOK_USED) {
|
||||||
|
return this._unsetWebHook();
|
||||||
|
}
|
||||||
|
|
||||||
if (resp.statusCode !== 200) {
|
if (resp.statusCode !== 200) {
|
||||||
throw new Error(`${resp.statusCode} ${resp.body}`);
|
throw new Error(`${resp.statusCode} ${resp.body}`);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user