tgs search messages#

在一个或多个聊天、频道或群组中搜索消息。

用法#

tgs search messages [query] [flags]

query 参数为必填项,指定要搜索的文本。

参数#

参数缩写类型默认值说明
--chat-cstring[]要搜索的聊天(用户名、电话、ID;可重复使用,支持逗号分隔)。未设置 --folder 时必填。
--folderstring""搜索此文件夹内的所有聊天(id 或名称);文件夹中的对等体与 --chat 累加
--from-fstring按发送者筛选(用户名、电话或 ID)
--filterstring消息类型过滤器(参见过滤器值
--afterstring仅返回此日期之后的消息(YYYY-MM-DD 或 unix 时间戳)
--beforestring仅返回此日期之前的消息(YYYY-MM-DD 或 unix 时间戳)
--topicint0论坛主题 ID
--limit-lint50最大返回消息数(1-100)
--cursorstring上次响应中的分页游标
--max-waitint60FLOOD_WAIT 最大等待秒数
--no-cacheboolfalse禁用对等体解析缓存
--include-commentsboolfalse同时搜索每个频道关联的讨论组
--profile-pstring账户配置文件名称

未设置 --profile 时的配置文件解析顺序:TGS_PROFILE 环境变量 -> .tgs.yaml 文件 -> "default"

过滤器值#

photovideophoto-videodocumenturlgifvoicemusicround-videogeocontactpinnedmentionphone-callchat-photo

示例#

在频道中搜索关键词:

tgs search messages "release notes" -c @golang

跨多个聊天搜索:

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

按发送者和消息类型筛选:

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

在日期范围内搜索:

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

搜索文件夹内所有聊天:

tgs search messages "announcement" --folder Work

分页浏览结果:

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

输出#

返回 JSON,包含匹配消息的数组、total 总数以及可选的分页游标 cursor

JSON(默认):

{
  "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"
}

文本(--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]

每行的格式为 [日期] 会话: 文本(频道帖子),或当消息有独立发送者(群组、超级群组)时为 [日期] 会话 | 作者: 文本。如有反应和查看计数,会以方括号附加在行尾。

消息字段#

字段类型说明
idint聊天内的消息 ID
chatobject{id, type, title?, username?}id 为 Bot API 形式(channel/supergroup/group 为负数,private 为正数),可直接传回 --chattypechannelsupergroupgroupprivate
fromobject发送者信息(频道帖子省略,群组消息和评论包含)
datestringRFC3339 UTC 时间戳
textstring消息文本
mediaobject附件类型和元数据;纯文本消息省略
reply_to_msg_idint回复的目标消息 ID;讨论组中指向转发的频道帖子
topic_idint论坛主题 ID(若适用)
views, forwards, repliesint活跃度计数(频道帖子)
reactionsarray{emoji, count} 数组;自定义表情显示为 custom:<doc_id>,付费为
cursorstring分页游标;没有更多结果时省略

另请参阅#