mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-29 13:27:44 +00:00
Fix: If use switch between webHook or Polling you get an 409 (http://telegram.wiki/bots:boterrorcode) telegram error.
This commit is contained in:
parent
2498e44ed7
commit
91dcb2b9d8
@ -2,6 +2,7 @@ const Promise = require('bluebird');
|
||||
const debug = require('debug')('node-telegram-bot-api');
|
||||
const request = require('request-promise');
|
||||
const URL = require('url');
|
||||
const ANOTHER_WEB_HOOK_USED = 409;
|
||||
|
||||
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() {
|
||||
const opts = {
|
||||
qs: {
|
||||
@ -84,6 +104,10 @@ class TelegramBotPolling {
|
||||
.promise()
|
||||
.timeout((10 + this.timeout) * 1000)
|
||||
.then(resp => {
|
||||
if (resp.statusCode === ANOTHER_WEB_HOOK_USED) {
|
||||
return this._unsetWebHook();
|
||||
}
|
||||
|
||||
if (resp.statusCode !== 200) {
|
||||
throw new Error(`${resp.statusCode} ${resp.body}`);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user