search_global()

Client.search_global()

Search messages globally from all of your chats.

Note

Due to server-side limitations, you can only get up to around ~10,000 messages and each message retrieved will not have any reply_to_message field.

Parameters
  • query (str, optional) – Text query string. Use “@” to search for mentions.

  • filter (str, optional) – Pass a filter in order to search for specific kind of messages only:

    • "empty": Search for all kind of messages (default).

    • "photo": Search for photos.

    • "video": Search for video.

    • "photo_video": Search for either photo or video.

    • "document": Search for documents (generic files).

    • "url": Search for messages containing URLs (web links).

    • "animation": Search for animations (GIFs).

    • "voice_note": Search for voice notes.

    • "audio": Search for audio files (music).

    • "chat_photo": Search for chat photos.

    • "audio_video_note": Search for either audio or video notes.

    • "video_note": Search for video notes.

    • "location": Search for location messages.

    • "contact": Search for contact messages.

  • limit (int, optional) – Limits the number of messages to be retrieved. By default, no limit is applied and all messages are returned.

Returns

Generator – A generator yielding Message objects.

Example

# Search for "pyrogram". Get the first 420 results
for message in app.search_global("pyrogram", limit=420):
    print(message.text)

# Search for recent photos from Global. Get the first 69 results
for message in app.search_global(filter="photo", limit=69):
    print(message.photo)