mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-30 13:58:27 +00:00
src/telegram: Add metadata argument in message
event (and friends)
References: * FR: https://github.com/yagop/node-telegram-bot-api/issues/409 * PR: https://github.com/yagop/node-telegram-bot-api/pull/413
This commit is contained in:
@@ -7,7 +7,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
Added:
|
Added:
|
||||||
|
|
||||||
* Add support for Node.js v9
|
1. Add `metadata` argument in `message` event (and
|
||||||
|
friends e.g. `text`, `audio`, etc.) (#409) (by @jlsjonas, @GochoMugo)
|
||||||
|
1. Add support for Node.js v9 (by @GochoMugo)
|
||||||
|
|
||||||
Changed:
|
Changed:
|
||||||
|
|
||||||
|
@@ -8,17 +8,19 @@
|
|||||||
<a name="events"></a>
|
<a name="events"></a>
|
||||||
## Events
|
## Events
|
||||||
|
|
||||||
*TelegramBot* is an event-emitter that emits the following events:
|
*TelegramBot* is an [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
|
||||||
|
that emits the following events:
|
||||||
|
|
||||||
1. `message`: Received a new incoming [Message][message] of any kind
|
1. `message`: Received a new incoming [Message][message] of any kind
|
||||||
1. Depending on the properties of the [Message][message], one of these
|
1. Depending on the properties of the [Message][message], one of these
|
||||||
events will **ALSO** be emitted: `text`, `audio`, `document`, `photo`,
|
events may **ALSO** be emitted: `text`, `audio`, `document`, `photo`,
|
||||||
`sticker`, `video`, `voice`, `contact`, `location`,
|
`sticker`, `video`, `voice`, `contact`, `location`,
|
||||||
`new_chat_members`, `left_chat_member`, `new_chat_title`,
|
`new_chat_members`, `left_chat_member`, `new_chat_title`,
|
||||||
`new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
|
`new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
|
||||||
`game`, `pinned_message`, `migrate_from_chat_id`, `migrate_to_chat_id`,
|
`game`, `pinned_message`, `migrate_from_chat_id`, `migrate_to_chat_id`,
|
||||||
`channel_chat_created`, `supergroup_chat_created`,
|
`channel_chat_created`, `supergroup_chat_created`,
|
||||||
`successful_payment`, `invoice`, `video_note`
|
`successful_payment`, `invoice`, `video_note`
|
||||||
|
1. **Arguments**: `message` ([Message][message]), `metadata` (`{ type?:string }`)
|
||||||
1. `new_chat_participant`, `left_chat_participant` are **deprecated**
|
1. `new_chat_participant`, `left_chat_participant` are **deprecated**
|
||||||
1. `callback_query`: Received a new incoming [Callback Query][callback-query]
|
1. `callback_query`: Received a new incoming [Callback Query][callback-query]
|
||||||
1. `inline_query`: Received a new incoming [Inline Query][inline-query]
|
1. `inline_query`: Received a new incoming [Inline Query][inline-query]
|
||||||
|
@@ -531,14 +531,15 @@ class TelegramBot extends EventEmitter {
|
|||||||
|
|
||||||
if (message) {
|
if (message) {
|
||||||
debug('Process Update message %j', message);
|
debug('Process Update message %j', message);
|
||||||
this.emit('message', message);
|
const metadata = {};
|
||||||
const processMessageType = messageType => {
|
metadata.type = TelegramBot.messageTypes.find((messageType) => {
|
||||||
if (message[messageType]) {
|
return message[messageType];
|
||||||
debug('Emitting %s: %j', messageType, message);
|
});
|
||||||
this.emit(messageType, message);
|
this.emit('message', message, metadata);
|
||||||
}
|
if (metadata.type) {
|
||||||
};
|
debug('Emitting %s: %j', metadata.type, message);
|
||||||
TelegramBot.messageTypes.forEach(processMessageType);
|
this.emit(metadata.type, message, metadata);
|
||||||
|
}
|
||||||
if (message.text) {
|
if (message.text) {
|
||||||
debug('Text message');
|
debug('Text message');
|
||||||
this._textRegexpCallbacks.some(reg => {
|
this._textRegexpCallbacks.some(reg => {
|
||||||
|
Reference in New Issue
Block a user