Reputation: 3648
So the thought is that a user A replies to a post in a chat from user B using a command /command
. How can we get the contents of the message (of user B)?
Like, we get an Update update
and I can do
String messageText = update.getMessage().getText(); // what user A sent aka "\command" string
long messageId = update.getMessage().getMessageId();
But what commands do I use to get the message of user B which is technically inside update
, right?
Upvotes: 4
Views: 6739
Reputation: 2497
As per Telegram docs, Message object received in an Update will contain reply_to_message
field if the message was sent as a reply to a previous message. The reply_to_message
is of type Message
as well, so you can get its text and ID the usual way (via getText
and getMessageID
).
I am not sure how this would be done in java (I guess by simple getReplyToMessage
), this is how I would handle it in javascript.
const update = req.body;
const message = update.message || update.edited_message;
if (message.reply_to_message) {
// this means message was a reply to a previous message
const previousMessageID = message.reply_to_message.message_id;
const previousMessageText = message.reply_to_message.text;
...
}
Upvotes: 1