diff --git a/doc/api.md b/doc/api.md index 0adb3133..f4d6b5a4 100644 --- a/doc/api.md +++ b/doc/api.md @@ -205,7 +205,7 @@ Emits `message` when a message arrives. | [options.polling] | Boolean \| Object | false | Set true to enable polling or set options. If a WebHook has been set, it will be deleted automatically. | | [options.polling.timeout] | String \| Number | 10 | *Deprecated. Use `options.polling.params` instead*. Timeout in seconds for long polling. | | [options.testEnvironment] | Boolean | false | Set true to work with test enviroment. When working with the test environment, you may use HTTP links without TLS to test your Web App. | -| [options.polling.interval] | String \| Number | 300 | Interval between requests in miliseconds | +| [options.polling.interval] | String \| Number | 300 | Interval between requests in milliseconds | | [options.polling.autoStart] | Boolean | true | Start polling immediately | | [options.polling.params] | Object | | Parameters to be used in polling API requests. See https://core.telegram.org/bots/api#getupdates for more information. | | [options.polling.params.timeout] | Number | 10 | Timeout in seconds for long polling. | diff --git a/package.json b/package.json index d3aae127..63f69471 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,8 @@ "eventemitter3": "^3.0.0", "file-type": "^3.9.0", "mime": "^1.6.0", - "pump": "^2.0.0" + "pump": "^2.0.0", + "tough-cookie": "~2.5.0" }, "devDependencies": { "babel-cli": "^6.26.0", diff --git a/src/telegram.js b/src/telegram.js index 306fba00..5e3393d0 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -125,7 +125,7 @@ class TelegramBot extends EventEmitter { * Timeout in seconds for long polling. * @param {Boolean} [options.testEnvironment=false] Set true to work with test enviroment. * When working with the test environment, you may use HTTP links without TLS to test your Web App. - * @param {String|Number} [options.polling.interval=300] Interval between requests in miliseconds + * @param {String|Number} [options.polling.interval=300] Interval between requests in milliseconds * @param {Boolean} [options.polling.autoStart=true] Start polling immediately * @param {Object} [options.polling.params] Parameters to be used in polling API requests. * See https://core.telegram.org/bots/api#getupdates for more information. @@ -276,7 +276,7 @@ class TelegramBot extends EventEmitter { * @see https://core.telegram.org/bots/api#sendmessage */ _fixReplyParameters(obj) { - if (obj.hasOwnProperty('reply_parameters') && typeof obj.reply_parameters !== 'string') { + if (Object.prototype.hasOwnProperty.call(obj, 'reply_parameters') && typeof obj.reply_parameters !== 'string') { obj.reply_parameters = stringify(obj.reply_parameters); } } @@ -765,7 +765,7 @@ class TelegramBot extends EventEmitter { const channelPost = update.channel_post; const editedChannelPost = update.edited_channel_post; const businessConnection = update.business_connection; - const businesssMessage = update.business_message; + const businessMessage = update.business_message; const editedBusinessMessage = update.edited_business_message; const deletedBusinessMessage = update.deleted_business_messages; const messageReaction = update.message_reaction; @@ -819,6 +819,7 @@ class TelegramBot extends EventEmitter { } if (message.reply_to_message) { // Only callbacks waiting for this message + const listenerIdsToRemove = []; this._replyListeners.forEach(reply => { // Message from the same chat if (reply.chatId === message.chat.id) { @@ -826,9 +827,15 @@ class TelegramBot extends EventEmitter { if (reply.messageId === message.reply_to_message.message_id) { // Resolve the promise reply.callback(message); + // Mark listener for removal to prevent memory leaks + listenerIdsToRemove.push(reply.id); } } }); + // Remove matched listeners + listenerIdsToRemove.forEach(id => { + this.removeReplyListener(id); + }); } } else if (editedMessage) { debug('Process Update edited_message %j', editedMessage); @@ -854,9 +861,9 @@ class TelegramBot extends EventEmitter { } else if (businessConnection) { debug('Process Update business_connection %j', businessConnection); this.emit('business_connection', businessConnection); - } else if (businesssMessage) { - debug('Process Update business_message %j', businesssMessage); - this.emit('business_message', businesssMessage); + } else if (businessMessage) { + debug('Process Update business_message %j', businessMessage); + this.emit('business_message', businessMessage); } else if (editedBusinessMessage) { debug('Process Update edited_business_message %j', editedBusinessMessage); this.emit('edited_business_message', editedBusinessMessage); @@ -2405,7 +2412,7 @@ class TelegramBot extends EventEmitter { */ unpinAllGeneralForumTopicMessages(chatId, form = {}) { form.chat_id = chatId; - return this._request('unhideGeneralForumTopic', { form }); + return this._request('unpinAllGeneralForumTopicMessages', { form }); } /** @@ -3004,7 +3011,7 @@ class TelegramBot extends EventEmitter { form.user_id = userId; form.name = name; form.old_sticker = oldSticker; - return this._request('deleteStickerFromSet', { form }); + return this._request('replaceStickerInSet', { form }); } diff --git a/src/telegramPolling.js b/src/telegramPolling.js index 9e6cf904..c60f742b 100644 --- a/src/telegramPolling.js +++ b/src/telegramPolling.js @@ -122,7 +122,7 @@ class TelegramBotPolling { } delete err._processing; /* - * An error occured while processing the items, + * An error occurred while processing the items, * i.e. in `this.bot.processUpdate()` above. * We need to mark the already-processed items * to avoid fetching them again once the application @@ -164,7 +164,7 @@ class TelegramBotPolling { if (this._abort) { debug('Polling is aborted!'); } else { - debug('setTimeout for %s miliseconds', this.options.interval); + debug('setTimeout for %s milliseconds', this.options.interval); this._pollingTimeout = setTimeout(() => this._polling(), this.options.interval); } });