Search Telegram messages
telegram_search_messagesFind a topic, decision, link or mention in available Telegram messages. Archive search covers text, captions and saved transcripts, with all terms required and a prefix match on the last word. Connected Session uses Telegram cloud search; it does not search bot-archive transcripts for extra matches, although returned media may include a ready archive transcript. Neither path searches attachment bytes or filenames. Use a few distinctive words, not a full natural-language question. To search a person's or channel's conversation, resolve its name/@username/link with telegram_find_chat and pass chat_id; query searches message content, not contact names. Default 30 matches; archive maximum 200, Session maximum 50. Read effective_limit, source, coverage and partial; a full page is not an exhaustive search. Use since inclusively and before exclusively for a precise date interval. When has_more=true, pass next_cursor as cursor with the same query, chat_id and date filters to continue. Never construct or edit cursors. A repeated query without cursor starts again. Request another page only when needed for the user's question; stop when enough context is found, has_more=false, or a cursor fails/makes no progress. A filtered Session page can be empty with continuation; has_more means continuation is available, not guaranteed visible matches. Cursors expire after 15 minutes and may expire on restart or cache eviction: explain and restart explicitly, never claim complete history. Search reflects changing live data, not a fixed snapshot. For a conversation summary use telegram_get_messages. Use the user's known timezone; if unknown, silently use UTC without asking or adding a timezone caveat. Do not infer it from language. For calendar days pass since at inclusive midnight and before at the exclusive next midnight as ISO 8601 timestamps with the correct offsets; distinguish calendar days from rolling 24h windows. Do not silently broaden the requested period. Distinguish errors from successful zero matches. Read empty_reason, chat_found, history_notice and setup_required when present. chat_not_in_archive means this ID is absent from the saved archive, not from Telegram: resolve the chat again and follow telegram_find_chat recovery guidance. For no_matches, consider fewer distinctive words and verify the intended chat/time range; no_searchable_terms needs a word or number. Do not loop on unchanged searches or claim the conversation never happened. For limited archive history offer /import in https://t.me/lemma_telepath_bot or accessible older history through Session: send /session to that bot, tap Connect Telegram and sign in there. Never ask for login codes/passwords here. Do not prescribe reconnection from zero matches alone or reconnect a working Session. Errors need the reported cause and an appropriate next step; respect retry delays and never call a timeout missing history or lost permission. If unknown, say so and offer support at https://t.me/hellolemma. Use telegram_get_file with returned chat_id/message_id to read supported archive or Session attachments; photos use telegram_get_photo. Messages include is_forwarded and forward_origin (original author/channel and Unix date when available). For forwards, from identifies who forwarded it in this chat, not the original author. Missing origin data does not prove authorship; never infer a hidden author's identity.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Page size. Default 30; archive maximum 200, Session maximum 50. Use next_cursor to continue when has_more is true. | |
| query | Yes | Distinctive words in message content, not a contact lookup. Session supports up to 200 characters. | |
| since | No | Only messages at or after this time. Accepts an ISO 8601 timestamp, unix seconds, 'today', 'yesterday', or a relative window like '24h' / '7d'. | |
| before | No | Only messages strictly older than this time; exclusive end of the search interval. Accepts an ISO 8601 timestamp, unix seconds, 'today', 'yesterday', or a relative window like '24h' / '7d'. | |
| cursor | No | Opaque next_cursor from the preceding search page. Keep query, chat_id, since and before unchanged; do not invent a cursor. | |
| chat_id | No | Restrict to this chat, resolved with telegram_find_chat. |