Answer the question
In order to leave comments, you need to log in
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
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)
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 questionAsk a Question
731 491 924 answers to any question