2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-31 06:16:07 +00:00

src/telegram: Add missing Message sub-types, Deprecate old ones (#340)

References:

    * PR: https://github.com/yagop/node-telegram-bot-api/pull/340
    * PR-by: @kamikazechaser
This commit is contained in:
Mohammed Sohail
2017-05-26 17:17:19 +03:00
committed by Gocho Mugo
parent 177c951340
commit 07a6e5ff23
2 changed files with 19 additions and 3 deletions

View File

@@ -14,9 +14,12 @@
1. Depending on the properties of the [Message][message], one of these
events will **ALSO** be emitted: `text`, `audio`, `document`, `photo`,
`sticker`, `video`, `voice`, `contact`, `location`,
`new_chat_participant`, `left_chat_participant`, `new_chat_title`,
`new_chat_members`, `left_chat_member`, `new_chat_title`,
`new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
`game`, `pinned_message`, `migrate_from_chat_id`, `migrate_to_chat_id`,
`channel_chat_created`, `supergroup_chat_created`,
`successful_payment`, `invoice`
1. `new_chat_participant`, `left_chat_participant` are **deprecated**
1. `callback_query`: Received a new incoming [Callback Query][callback-query]
1. `inline_query`: Received a new incoming [Inline Query][inline-query]
1. `chosen_inline_result`: Received result of an inline query i.e. [ChosenInlineResult][chosen-inline-result]

View File

@@ -21,8 +21,13 @@ const deprecate = require('depd')('node-telegram-bot-api');
const _messageTypes = [
'text', 'audio', 'document', 'photo', 'sticker', 'video', 'voice', 'contact',
'location', 'new_chat_participant', 'left_chat_participant', 'new_chat_title',
'new_chat_photo', 'delete_chat_photo', 'group_chat_created', 'successful_payment', 'invoice'
'location', 'new_chat_members', 'left_chat_member', 'new_chat_title',
'new_chat_photo', 'delete_chat_photo', 'group_chat_created', 'game', 'pinned_message',
'migrate_from_chat_id', 'migrate_to_chat_id', 'channel_chat_created', 'supergroup_chat_created',
'successful_payment', 'invoice'
];
const _deprecatedMessageTypes = [
'new_chat_participant', 'left_chat_participant'
];
// enable cancellation
@@ -40,6 +45,14 @@ class TelegramBot extends EventEmitter {
return _messageTypes;
}
on(event, listener) {
if (_deprecatedMessageTypes.indexOf(event) !== -1) {
const url = 'https://github.com/yagop/node-telegram-bot-api/blob/master/doc/usage.md#events';
deprecate(`Events ${_deprecatedMessageTypes.join(',')} are deprecated. See the updated list of events: ${url}`);
}
super.on(event, listener);
}
/**
* Both request method to obtain messages are implemented. To use standard polling, set `polling: true`
* on `options`. Notice that [webHook](https://core.telegram.org/bots/api#setwebhook) will need a SSL certificate.