Manav sharma
Manav sharma

Reputation: 11

How can i read message of particular user in telegram group using telegram bot i am using node-telegram-bot

How to read particular user latest messages i have userId but i want to read all messages send by that user. I want if there is any bot functions which can be used for this. I also want to know can i read reactions on a particular message of that user

Upvotes: 0

Views: 1352

Answers (1)

MuhammadMP
MuhammadMP

Reputation: 462

It's pretty easy to filter the messages by sender id. You should:

  1. Disable the privacy mode.

A bot running in privacy mode will not receive all messages that people send to the group.

  1. When you have an incoming update, check for the update.message.from.id to know if he's the target user.

  2. use copyMessage or forwardMessage to send his message to yourself.

Here's a simple example using PHP/TeleBot:

$tg = new TeleBot('your-token');
if ($tg->user->id == 'target-user-id') {
    $tg->forwardMessage([
        'chat_id' => 'your-user-id',
        'from_chat_id' => $tg->chat->id,
        'message_id' => $tg->message->message_id,
    ]);
}

You can also check out this repository to more know and get inspired: https://github.com/mkleymenov/telespy-bot

Upvotes: 0

Related Questions