0

we tried to use 1 telegram client to continuously streaming messages from a list of channels, and then produce the messages to kafka. We then have a 2nd telegram client to consume the messages and download the associated media (photos/videos) using client.download_media(). Our issue is that this only works if client 1 and 2 are the same, but not when they are different accounts. We are not sure if this has to do with the session files or access hash, or maybe something else?

Is support for our use case possible? The main thing we are trying to address is that the async media download could result in a large backlog, and the backlog may go away if our server dies. That's why we wanted to put the messages into kafka for short term storage in the first place. Would also appreciate if you have better suggestions.

this is producer side

    async with client:
        messages = client.iter_messages(channel_id, limit=10)
        async for message in messages:
            print(message)
            if message.media is not None:
                # orig_media = message.media
                # converted_media = BinaryReader(bytes(orig_media)).tgread_object()
                # print('orig, media', orig_media)
                # print('converted media', converted_media)
                message_bytes = bytes(message) #convert to bytes
                producer.produce(topic, message_bytes)

this is consumer side with a different client

            with self._client:
                #telethon.errors.rpcerrorlist.FileReferenceExpiredError: The file reference has expired and is no longer valid or it belongs to self-destructing media and cannot be resent (caused by GetFileRequest)
                try:
                    self._client.loop.run_until_complete(self._client.download_media(orig_media, in_memory))
                except Exception as e:
                    print(e)

  • From the official documentation, `The file download operation may return a FILE_REFERENCE_EXPIRED error (or another error starting with FILE_REFERENCE_): in this case, the file_reference field of the input location must be refreshed`. Please check [this link](https://core.telegram.org/api/files). – SpEcHiDe Feb 14 '23 at 01:40

1 Answers1

1

Media files (among many other things in Telegram) contain an access_hash. While Account-A and Account-B will both see media with ID 1234, Account-A may have a hash of 5678 and Account-B may have a hash of 8765.

This is a roundabout way of saying that every account will see an access_hash that is only valid within that account. If that same hash is attempted to be used by a different account, it will fail, because that other account needs its own hash.

There is no way to bypass this, other than giving actual access to the right media files (or whatever it is) so that it can obtain its own hash.

Lonami
  • 5,945
  • 2
  • 20
  • 38