im using python and telethon to get messages.. I can download the message photos but i dont want to store and download. I want to know the url of the photo to access it any time later using that. is there any way to do that?
2 Answers
telegram APIs won't give you direct URL to media files of posts. but, as a workaround, take a look at the new feature that Telegram has added to its website a few months ago:
you can see posts of public channels in the web just by typing URLs with this pattern: https://t.me/"channel-username"/"post-No"
(e.g. https://t.me/gizmiztel/2350)
this way you can parse the DOM and find the direct URL to each media file.
Note: you may need a separate method for each type of files to extract files' URLs.

- 2,331
- 1
- 22
- 29
An extension to @tashakori's answer
For channels that have no username set (I've seen a few), it is https://t.me/c/channel_id/message_id
eg.
async def main():
# TODO setup client etc.
# this channel id was obtained from using something similar to https://stackoverflow.com/a/62849271/8608146
channel = await client.get_entity(-1001006503122)
async for message in client.iter_messages(channel, reverse=True):
# channel.id and the above -100.. id are not same
# this channel.id looks like 1006503122
print("message URL", f"https://t.me/c/{channel.id}/{message.id}")
Also note: These links are accessible only to users who are joined in the channel, of course.
There's also the message.chat_id
property which returns the -100...

- 4,030
- 3
- 25
- 60