tgs search messages#

Search messages within one or more chats, channels, or groups.

Usage#

tgs search messages [query] [flags]

The query argument is required and specifies the text to search for.

Flags#

FlagShortTypeDefaultDescription
--chat-cstring[]Chat to search (username, phone, ID; repeatable, comma-separated). Required unless --folder is set.
--folderstring""Search all chats inside this folder (id or name); peers are additive to any --chat values
--from-fstringFilter by sender (username, phone, or ID)
--filterstringMessage type filter (see filter values)
--afterstringOnly messages after date (YYYY-MM-DD or unix timestamp)
--beforestringOnly messages before date (YYYY-MM-DD or unix timestamp)
--topicint0Forum topic ID
--limit-lint50Max messages to return (1-100)
--cursorstringPagination cursor from previous response
--max-waitint60Max seconds to wait on FLOOD_WAIT
--no-cacheboolfalseDisable peer resolution cache
--include-commentsboolfalseAlso search the linked discussion group of each channel
--profile-pstringAccount profile name

Profile resolution order when --profile is not set: TGS_PROFILE env -> .tgs.yaml file -> "default".

Filter values#

photo, video, photo-video, document, url, gif, voice, music, round-video, geo, contact, pinned, mention, phone-call, chat-photo.

Examples#

Search for a keyword in a channel:

tgs search messages "release notes" -c @golang

Search across multiple chats:

tgs search messages "deployment" -c @devops_team -c @infrastructure

Filter by sender and message type:

tgs search messages "config" -c @mygroup --from @alice --filter document

Search within a date range:

tgs search messages "outage" -c @incidents --after 2025-01-01 --before 2025-06-01

Search across all chats in a folder:

tgs search messages "announcement" --folder Work

Paginate through results:

tgs search messages "bug" -c @dev -l 10 --cursor "eyJvIjo1MCwiZCI6MH0"

Output#

Returns JSON with an array of matched messages and a cursor field for pagination.

JSON (default):

{
  "messages": [
    {
      "id": 520,
      "chat": {"id": -1001006503122, "type": "channel", "title": "Pavel Durov"},
      "date": "2026-05-23T13:26:07Z",
      "text": "WhatsApp encryption is a giant fraud...",
      "media": {"type": "webpage"},
      "views": 1128733,
      "forwards": 10748,
      "replies": 540,
      "reactions": [
        {"emoji": "👍", "count": 8412},
        {"emoji": "🔥", "count": 2103},
        {"emoji": "❤", "count": 991}
      ]
    }
  ],
  "total": 285,
  "cursor": "eyJvIjo1MjAsImQiOjB9"
}

Text (--output text):

[2026-05-23 13:26:07] Pavel Durov: WhatsApp encryption is a giant fraud... [👁 1128733 ↻ 10748 💬 540 👍 8412 🔥 2103 ❤ 991]
[2026-05-23 14:02:11] Go Talks | @rob: generics landed in 1.18 [💬 4]

Each line is [date] chat: text for channel posts, or [date] chat | author: text when the message has a distinct sender (groups, supergroups). Reaction and view counters are appended in brackets when present.

Message fields#

FieldTypeNotes
idintMessage ID within the chat
chatobject{id, type, title?, username?}id is in Bot-API form (negative for channel/supergroup/group, positive for private), so it feeds straight back into --chat; type is one of channel, supergroup, group, private
fromobjectSender info (omitted for channel posts, present for group messages and comments)
datestringRFC3339 UTC timestamp
textstringPlain text of the message
mediaobjectType and metadata for attached media; omitted for text-only messages
reply_to_msg_idintMessage this is a reply to; in discussion groups, points to the forwarded channel post
topic_idintForum topic ID if applicable
views, forwards, repliesintEngagement counters (channel posts)
reactionsarrayList of {emoji, count} pairs; custom emoji appear as custom:<doc_id>, paid as
cursorstringPagination cursor; absent when there are no more results

See Also#