mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-22 18:07:16 +00:00
onReplyToMessage
This commit is contained in:
parent
0d1db09c09
commit
17cb062c96
@ -43,6 +43,7 @@ var TelegramBot = function (token, options) {
|
|||||||
'new_chat_photo', 'delete_chat_photo', 'group_chat_created'
|
'new_chat_photo', 'delete_chat_photo', 'group_chat_created'
|
||||||
]; // Telegram message events
|
]; // Telegram message events
|
||||||
this.textRegexpCallbacks = [];
|
this.textRegexpCallbacks = [];
|
||||||
|
this.onReplyToMessages = [];
|
||||||
|
|
||||||
this.processUpdate = this._processUpdate.bind(this);
|
this.processUpdate = this._processUpdate.bind(this);
|
||||||
|
|
||||||
@ -92,6 +93,19 @@ TelegramBot.prototype._processUpdate = function (update) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (message.reply_to_message) {
|
||||||
|
// Only callbacks waiting for this message
|
||||||
|
this.onReplyToMessages.forEach(function (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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
} else if (inline_query) {
|
} else if (inline_query) {
|
||||||
debug('Process Update inline_query %j', inline_query);
|
debug('Process Update inline_query %j', inline_query);
|
||||||
this.emit('inline_query', inline_query);
|
this.emit('inline_query', inline_query);
|
||||||
@ -549,4 +563,18 @@ TelegramBot.prototype.onText = function (regexp, callback) {
|
|||||||
this.textRegexpCallbacks.push({regexp: regexp, callback: callback});
|
this.textRegexpCallbacks.push({regexp: regexp, callback: callback});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a reply to wait for a message response.
|
||||||
|
* @param {Number|String} messageId The ID of the message to be replied
|
||||||
|
* @param {Function} callback Callback will be called with the reply
|
||||||
|
* message.
|
||||||
|
*/
|
||||||
|
TelegramBot.prototype.onReplyToMessage = function (chatId, messageId, callback) {
|
||||||
|
this.onReplyToMessages.push({
|
||||||
|
chatId: chatId,
|
||||||
|
messageId: messageId,
|
||||||
|
callback: callback
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = TelegramBot;
|
module.exports = TelegramBot;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user