Telethon icon indicating copy to clipboard operation
Telethon copied to clipboard

Global Search

Open ammaremami opened this issue 5 years ago • 4 comments

Hello Can I use the get_message() function to global search ?

ammaremami avatar Jul 29 '18 06:07 ammaremami

No, use raw requests for now.

Lonami avatar Jul 29 '18 09:07 Lonami

If you client.iter_messages(None, search='text') (or get_messages for that matter), you can now search globally. Thanks for the suggestion.

Lonami avatar Jul 29 '18 21:07 Lonami

Hi, I'm trying to use None in place of the client ID in iter_messages, however I'm not getting any results back (it works if I put a channel ID there for example).

This works: client.iter_messages(1010229649, limit=10, search='hello', wait_time=0)

But this does not: client.iter_messages(None, limit=10, search='hello', wait_time=0)

Any help would be appreciated and thanks for the great package!

lukes-hd avatar Jun 17 '22 12:06 lukes-hd

Still not getting anything back on global searches here. Can anyone confirm if it's working/not working for them? (Python 3.9 + Telethon 1.24)

lukes-hd avatar Jun 23 '22 15:06 lukes-hd

This functionality does work for searching within your own messages - tested on a message sent to self. I have not tested further, but it seems likely that it will search only within your own chats, in contrast to when you supply a peer id which can be used to search within public channels even if you are not a member/participant. This does not appear to be a truly "global" (i.e. across all available telegram data) search.

KingRuairidh avatar Oct 18 '22 13:10 KingRuairidh

The above should not fix "global search returns no results", but it should fix "global search gets stuck when it returns less than 100 results in some cases".

Anyway, I've tried and am not able to reproduce. You are welcome to use the raw API method searchGlobal. If that works, then Telethon may be doing something wrong. If that doesn't work, then the results you're getting are what Telegram is sending and there's nothing Telethon can do to "fix" it.

Lonami avatar Oct 18 '22 14:10 Lonami

For anyone else who is looking for the answer, I tested the raw API method searchGlobal and received the same result as using iter_messages with peer_id=None i.e. only the message I sent to myself on a test account. It seems likely to me that the telegram API means "within your chats" or similar when it says "global".

KingRuairidh avatar Oct 18 '22 15:10 KingRuairidh