Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Emits `message` when a message arrives.
| [options.polling] | <code>Boolean</code> \| <code>Object</code> | <code>false</code> | Set true to enable polling or set options. If a WebHook has been set, it will be deleted automatically. |
| [options.polling.timeout] | <code>String</code> \| <code>Number</code> | <code>10</code> | *Deprecated. Use `options.polling.params` instead*. Timeout in seconds for long polling. |
| [options.testEnvironment] | <code>Boolean</code> | <code>false</code> | 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] | <code>String</code> \| <code>Number</code> | <code>300</code> | Interval between requests in miliseconds |
| [options.polling.interval] | <code>String</code> \| <code>Number</code> | <code>300</code> | Interval between requests in milliseconds |
| [options.polling.autoStart] | <code>Boolean</code> | <code>true</code> | Start polling immediately |
| [options.polling.params] | <code>Object</code> | | Parameters to be used in polling API requests. See https://core.telegram.org/bots/api#getupdates for more information. |
| [options.polling.params.timeout] | <code>Number</code> | <code>10</code> | Timeout in seconds for long polling. |
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 15 additions & 8 deletions src/telegram.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -819,16 +819,23 @@ 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) {
// Responding to that message
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);
Expand All @@ -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);
Expand Down Expand Up @@ -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 });
}

/**
Expand Down Expand Up @@ -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 });
}


Expand Down
4 changes: 2 additions & 2 deletions src/telegramPolling.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
});
Expand Down