mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-29 13:27:44 +00:00
New events. 😄
This commit is contained in:
parent
7b7191b464
commit
1dd81e4343
@ -33,6 +33,11 @@ var requestPromise = Promise.promisify(request);
|
|||||||
var TelegramBot = function (token, options) {
|
var TelegramBot = function (token, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
this.token = token;
|
this.token = token;
|
||||||
|
this.messageTypes = [
|
||||||
|
'text', 'audio', 'document', 'photo', 'sticker', 'video', 'contact',
|
||||||
|
'location', 'new_chat_participant', 'left_chat_participant', 'new_chat_title',
|
||||||
|
'new_chat_photo', 'delete_chat_photo', 'group_chat_created'
|
||||||
|
]; // Telegram message events
|
||||||
|
|
||||||
var processUpdate = this._processUpdate.bind(this);
|
var processUpdate = this._processUpdate.bind(this);
|
||||||
|
|
||||||
@ -48,10 +53,18 @@ var TelegramBot = function (token, options) {
|
|||||||
util.inherits(TelegramBot, EventEmitter);
|
util.inherits(TelegramBot, EventEmitter);
|
||||||
|
|
||||||
TelegramBot.prototype._processUpdate = function (update) {
|
TelegramBot.prototype._processUpdate = function (update) {
|
||||||
debug('Process Update', update);
|
debug('Process Update %j', update);
|
||||||
debug('Process Update message', update.message);
|
var message = update.message;
|
||||||
if (update.message) {
|
debug('Process Update message %j', message);
|
||||||
this.emit('message', update.message);
|
if (message) {
|
||||||
|
this.emit('message', message);
|
||||||
|
var processMessageType = function (messageType) {
|
||||||
|
if (message[messageType]) {
|
||||||
|
debug('Emtting %s: %j', messageType, message);
|
||||||
|
this.emit(messageType, message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.messageTypes.forEach(processMessageType.bind(this));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user