alfem/telegram-download-daemon

Script don't work with Saved Messages Chat

Arduingo opened this issue · 3 comments

Hi, first of all great work!

I have been testing the script and found it dont work if the chat passed is the Saved Message, I tested with another chat room owned by me and works fine, all forwarded media is downloaded properly, but if the Chat ID passed is the Saved Messages one it fails with an error:

(Channel ID edited)
ValueError: Could not find the input entity for PeerChannel(channel_id=XXXXXXXXX) (PeerChannel).

I get the channel id from telegram Web and it works in another test script I have

Is this an expected behavior?

alfem commented

I would need to know how yo use this script. Are you using your own Saved Message for downloads or are you forwarding files from your Saved Message chat to another one?

How did you get the chat_id of "Saved Messages"?

Hi,

For the Chat ID I used Telegram Web, and used the last part of the URL for example

https://web.telegram.org/z/#123456789, so the chat ID would be 123456789, one difference I found is that this Chat ID is a positive number while If i look into a channel I created the number is negative.

I forward Media from others chats to my Saved Message folder

I think I found what the problem is, the Saved Messages Chat is not seen by Telegram as a Chat but as a User, so when we execute peerChannel = PeerChannel(channel_id) we get an error.

I fixed my problem by removing that line and replacing by peerChannel = channel_id, filtering the event by using client.on(events.NewMessage(chats=channel_id) instead of the if inside and removing the if statement comparing if the event if from the user selected chat. if event.to_id != peerChannel:

so the code ended being
...
queue = asyncio.Queue()
#peerChannel = PeerChannel(channel_id)
peerChannel = channel_id

@client.on(events.NewMessage(chats=channel_id))
async def handler(event):
            
    #if event.to_id != peerChannel:
    #    return

    print(event)
    
    try:

...

Now the script allow me to use the saved messages as my "media storage", the detail to have into account is if you want to use a different chat then the Saved Messages you should remove the negative sign from the Chat ID you want to use.

I don't know if I broke something else, I'm testing, so far so good