L
L
leham12021-09-30 13:56:52
Python
leham1, 2021-09-30 13:56:52

Why telegram bot can't see messages?

Hello.
I created a bot "bot_1" in telegram, it receives messages from a specific service "service_1".

Right now I need to filter messages from 'service_1' (if the message contains the text "text_1" then I need to delete that message).

I tried to do like this:

import logging

from aiogram import Bot, Dispatcher, executor, types

API_TOKEN = 'token' # токен бота для отправки авито объявлений

# Configure logging
logging.basicConfig(level=logging.INFO)

# Initialize bot and dispatcher
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)

# удалить конкретные сообщения (содержащие в тексе "плохое слово")
@dp.message_handler()
async def filter_messages(message: types.Message):
    if 'text_1' in message.text:
        # remove massage
        await  message.delete()


if __name__ == '__main__':
    executor.start_polling(dp, skip_updates=True)

Created a bot "bot_2" in python using the 'aiogram' library (it's for managing bots).
And it works right. When I send a message that contains the text "text_1", it deletes it.
But the problem is that it does not see when a message from "service_1" arrives, and therefore does not delete it.

Question: how to make "bot_2" see messages from 'service_1'?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Golovanenko, 2021-09-30
@leham1

The Telegram Bot API prevents bots from reading messages sent by other bots.
You can get around this limitation using the MTProto API for bots. For Python to work with MTProto on behalf of a bot, there are Pyrogram and Telethon libraries .
For more information about the difference between Bot API and MTProto API, how to use bots with MTProto API, read this article: https://habr.com/ru/post/543676/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question