Developer documentation

Telegram message pagination, search and caching

Distinguish message cursors, search filters and cache hashes to prevent duplicate pages and premature history termination.

GetTGAPI editorial teamUpdated
Documentation notesReviewed

Based on official sources and independently maintained by GetTGAPI. Documentation and glossary →

On this page
  1. A cursor is not a page number
  2. Choose the search scope first
  3. Implementation recommendations

A cursor is not a page number

Telegram methods may combine offset_id, add_offset, dates or range boundaries. Check each method’s semantics; a reverse-chronological message list cannot be paginated by inventing consecutive message IDs. Some lists support cache hashes and NotModified responses. These hashes are unrelated to the application API Hash.

Choose the search scope first

messages.search and global search target different scopes. Media filters narrow the requested message category, while public channel posts and other features may use separate methods and eligibility rules. Explain the scope before accepting a query.

Implementation recommendations

Persist an appropriate next-page cursor and deduplicate by dialog and message identity. When prepending older messages, preserve a visible message as a scroll anchor. Discard responses from obsolete search conditions rather than merging them into the new result list.

Test empty and partial responses, duplicates, incoming messages during pagination and deleted history. Determine completion from the method’s contract, not a universal assumption that a short page means the end.