Warshow
Warshow

Reputation: 1

Bot - Telethon don't scrape Telegram message

So I've coded a Telegram user bot, which retrieves messages the moment they are received in the Telegram channel. It allows me to scrape messages directly.

Except I have a problem, when a certain message is sent in the Telegram channel, the bot doesn't detect it, as if the message was invisible for the bot.

with TelegramClient('bot', config('API_ID'), config('API_HASH')) as client:
  ...

  @client.on(events.NewMessage(chats=list(dialog_ids.keys())))
  async def new_message_listener(event):
    new_message = event.message.message
    print(new_message)
    

It's as if the message is invisible to the bot, and I don't know that the message is there when I check the web or mobile application.

Which is really annoying because it's precisely this kind of message that I want to retrieve.

I asked if there were any restrictions on certain messages on Telegram, but I couldn't find anything clear.

I also changed the part of the code that listens to the event, but without much result.

Upvotes: 0

Views: 222

Answers (1)

Warshow
Warshow

Reputation: 1

After some research, I've deduced that either Telegram allows you to protect channels from scrapping by the @client.on(events.NewMessage method of Telethon package. I therefore downloaded the last 5 messages every minutes, which I save as a database.

messages = client.iter_messages(id_channel, limit=5)

After that, i do the difference with stocked in database messages and downloaded messages by their id.

Problem "solved"

Upvotes: -1

Related Questions