PicoBot/.qoder/skills/lark-im/references/lark-im-chat-search.md
ooodc a7883dbed9 refactor(todo): 重构待办事项管理逻辑及更新状态规则
- 移除 TodoItem 中的 priority、created_at 和 updated_at 字段
- 强制每个任务都必须有唯一 id,且由用户负责生成
- 修改合并模式逻辑,merge=true 下保留未提及的旧任务
- 支持已完成和已取消任务重新激活(状态改回 pending 或 in_progress)
- 禁止 in_progress 状态退回到 pending,必须标记为 completed 或 cancelled
- 优化状态转换校验,允许特定状态间合法切换
- 简化任务变更消息,移除详细的新增/更新/移除统计
- 更新文档和示例,明确 id 必须由用户生成和使用
- 修复和补充测试,增强状态转换和合并模式验证
- 调整任务时间戳生成逻辑,统一使用当前时间及索引
- 该变更提供更合理的任务状态机械及管理模式,提升稳定性和易用性
2026-06-13 09:22:33 +08:00

7.7 KiB

im +chat-search

Prerequisite: Read ../lark-shared/SKILL.md first to understand authentication, global parameters, and safety rules.

Search the list of group chats visible to a user or bot, including chats the user or bot belongs to and public chats visible to them. Supports keyword matching on chat names and member names, including pinyin and prefix fuzzy search.

This skill maps to the shortcut: lark-cli im +chat-search (internally calls POST /open-apis/im/v2/chats/search).

Commands

# Search chats by keyword
lark-cli im +chat-search --query "project"

# Restrict by search types
lark-cli im +chat-search --query "project" --search-types "private,public_joined"

# Filter by chat mode (group = regular group, topic = topic/thread group)
lark-cli im +chat-search --query "project" --chat-modes "topic"

# Filter by member open_ids (with keyword)
lark-cli im +chat-search --query "project" --member-ids "ou_xxx,ou_yyy"

# Search by member open_ids only
lark-cli im +chat-search --member-ids "ou_xxx,ou_yyy"

# Only show chats you created or manage
lark-cli im +chat-search --query "project" --is-manager

# Set page size
lark-cli im +chat-search --query "project" --page-size 10

# Pagination
lark-cli im +chat-search --query "project" --page-token "xxx"

# JSON output
lark-cli im +chat-search --query "project" --format json

# Preview the request without executing it
lark-cli im +chat-search --query "project" --dry-run

Parameters

Parameter Required Limits Description
--query <keyword> No (at least one of --query / --member-ids required) Max 64 characters Search keyword. Supports matching localized chat names, member names, multilingual search, pinyin, and prefix fuzzy search. If the query contains -, it is automatically wrapped in quotes
--search-types <types> No Comma-separated: private, external, public_joined, public_not_joined Restrict the visible chat types returned by search
--chat-modes <modes> No Comma-separated: group, topic Filter by chat mode (server-side): group = regular group, topic = topic/thread group
--member-ids <ids> No (at least one of --query / --member-ids required) Up to 50, format ou_xxx Filter by member open_ids; can be used alone or combined with --query
--is-manager No - Only show chats you created or manage
--disable-search-by-user No - Disable member-name-based matching and search by group name only
--sort <field> No create_time, update_time, member_count Sort field (always descending)
--page-size <n> No 1-100, default 20 Number of results per page
--page-token <token> No - Pagination token from the previous response
--exclude-muted No User identity only Drop chats the current user has muted (do-not-disturb). Under --as bot, the flag is silently inactive (mute is a per-user setting); see "Filtering muted chats" below
--format json No - Output as JSON
--dry-run No - Preview the request without executing it

Note: Supports both --as user (default) and --as bot. When using bot identity, the app must have bot capability enabled.

CAUTION: --sort is always descending — the search API only ranks the chosen field high-to-low (e.g. member_count = most members first). There is no ascending option. If the user asks for "fewest first / ascending / 从少到多", tell them the search API does not support ascending order; any low-to-high view requires re-sorting the fetched page client-side and is not an upstream sort. Do not invent values like member_count_asc or pass asc (they are rejected).

Output Fields

Field Description
chat_id Chat ID (oc_xxx format)
name Chat name
description Chat description
owner_id Owner ID
external Whether the chat is external
chat_status Chat status (normal / dissolved / dissolved_save)

Filtering muted chats

--exclude-muted (user identity only) drops chats the current user has set to do-not-disturb. After the search call, the CLI batches the page's chat_ids through POST /open-apis/im/v1/chat_user_setting/batch_get_mute_status and filters client-side. Under --as bot, the mute API is UAT-only and the filter is silently skipped.

When the flag is set, the JSON envelope gains a filter sub-object (absent otherwise, so existing consumers are unaffected); fetched_count == returned_count + filtered_count always holds:

{
  "chats": [...],
  "filter": {
    "applied": "exclude_muted",
    "fetched_count": 20,
    "returned_count": 19,
    "filtered_count": 1,
    "hint": "Filtered out 1 muted chat(s) on this page (19 remaining, including 2 non-member public group(s)); use --page-token to fetch more."
  }
}

Note: only confirmed-muted chats count toward filtered_count; non-member public groups are retained and surfaced in hint. For strict member-only results, combine with --search-types "private,public_joined,external".

Usage Scenarios

Scenario 1: Search chats that contain a keyword

lark-cli im +chat-search --query "design review"

Scenario 2: Search a chat and list recent messages

CHAT_ID=$(lark-cli im +chat-search --query "project" --format json | jq -r '.data.chats[0].chat_id')
lark-cli im +chat-messages-list --chat-id "$CHAT_ID"

Scenario 3: Search a chat and send a message

CHAT_ID=$(lark-cli im +chat-search --query "daily report" --format json | jq -r '.data.chats[0].chat_id')
lark-cli im +messages-send --chat-id "$CHAT_ID" --text "Today's progress update"

Common Errors and Troubleshooting

Symptom Root Cause Solution
--query and --member-ids cannot both be empty Both were omitted Provide at least --query or --member-ids
Empty results No visible chats matched the keyword or filters Relax the keyword or filters and try again
--page-size must be an integer between 1 and 100 page-size is out of range or not an integer Use an integer between 1 and 100
Permission denied (99991672) The bot app does not have im:chat:read TAT permission enabled Enable the permission for the app in the Open Platform console
Permission denied (99991679) with --as user UAT is not authorized for im:chat:read Run lark-cli auth login --scope "im:chat:read"
Bot ability is not activated (232025) The app does not have bot capability enabled Enable bot capability in the Open Platform console

AI Usage Guidance

When the user asks to search chats, follow these rules:

  1. At least one filter required: --query and --member-ids cannot both be empty. Either alone or combined together are valid.
  2. Search scope is limited: only chats visible to the current user or bot can be found (joined chats plus public chats). This is not a global search over all chats.
  3. Control result volume: the result set may be large. Use --page-size deliberately.
  4. Suggest follow-up actions: after finding a chat, common next steps include listing recent messages (im +chat-messages-list) or sending a message (im +messages-send).
  5. NEVER fall back to chats list: If +chat-search returns empty results, do NOT attempt to use +chat-list or GET /open-apis/im/v1/chats as a fallback. The list API is not a search API — it returns all chats without keyword filtering and will not help locate the target chat. Instead, ask the user to refine the keyword or check whether the chat is visible to the current identity.

References