E
E
Egor111112021-12-22 19:23:36
Bots
Egor11111, 2021-12-22 19:23:36

How to make a bot that will be in the Telegram chat and track the messages of a specific user?

Hello! We need a bot that will be in the Telegram chat and track the messages of a specific user and send information about this to another chat or private message. For example, a certain person wrote some message in the chat, the bot saw it and sent a signal. Is it possible to implement this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
desaki, 2021-12-23
@desaki

If you are a chat administrator , and you can add your bot there , then there will be no problems.

from aiogram import Bot, Dispatcher, executor

TOKEN = "Ваш токен"

bot = Bot(token=TOKEN)
dp = Dispatcher(bot)

@dp.message_handler(content_types=['text'])
async def text(message):
  print(message.text, message.from_user.id)
  user_id = 123456789 # id юзера, который вам нужен
  chat_id = 123456789 # id чата, в который надо отправлять сообщения этого юзера
  if message.from_user.id == user_id:
    print("Нужный пользователь отправил сообщение.")
    await message.dp.send_message(chat_id, message.text) # Отправляем сообщения юзера в ваш чат

executor.start_polling(dp, skip_updates=True)

A
Alexandr_VM, 2021-12-22
@Alexandr_VM

Take the api https://core.telegram.org/bots in the bot settings, turn off the private mode, add the bot to the chat, get updates, and by the user ID in the update, look for his messages, do what you need with them, that's all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question