Skip to content

feat(message): add list/get/search/members read actions to Lark channel#467

Open
KevinWangQQ wants to merge 1 commit into
larksuite:mainfrom
KevinWangQQ:feat/message-tool-read-actions
Open

feat(message): add list/get/search/members read actions to Lark channel#467
KevinWangQQ wants to merge 1 commit into
larksuite:mainfrom
KevinWangQQ:feat/message-tool-read-actions

Conversation

@KevinWangQQ
Copy link
Copy Markdown

Problem

Agents using the message tool against the Feishu/Lark channel can today only write (send / react / reactions / delete / unsend). To answer questions like "what was just said in group X?" or "who's in this chat?", they have to fall back to grepping local message-cache files, which is lossy (rolling truncation, ~hours of replication lag) and asymmetric with the write surface.

Solution

Add 4 read actions to feishuMessageActions, parallel to the existing write set:

Action Params Returns
list chatId (required, also accepts chat/channel/to); optional limit (≤200), scan (≤200), sender (open_id), since_hours / since_days { messages: [...], nextPageToken?, hasMore, scanned, count }
get messageId (required); optional full/expand to enable expandForward in getMessageFeishu { message: FeishuMessageInfo }
search chatId + text/query/q (required); optional limit (≤200), scan (≤500) { messages: [...], scanned, count } (client-side substring)
members chatId (required); optional pageToken { members: [...], hasMore, nextPageToken }

Implementation reuses already-exported package helpers wherever possible:

  • getgetMessageFeishu (from messaging/shared/message-lookup.ts)
  • memberslistChatMembersFeishu (from messaging/outbound/chat-manage.ts)
  • list / search → thin loops around im/v1/messages (ByCreateTimeDesc paging) plus a small buildExcerpt helper that handles text / post / interactive / media / system message types.

API surface

message action=list    chatId=<oc_xxx> [limit=20] [scan=60] [sender=<open_id>] [since_hours=24]
message action=get     messageId=<om_xxx> [full=true]
message action=search  chatId=<oc_xxx> text="..." [limit=20] [scan=100]
message action=members chatId=<oc_xxx> [pageToken=...]

Backward compatibility

Pure addition. No existing action's signature, return shape, or behaviour changes.

Type-system note

ChannelMessageActionName in the openclaw SDK currently only contains 'search' of the four — 'list', 'get', 'members' are not yet in the union. Rather than block this PR on an SDK change, SUPPORTED_ACTIONS casts the new names through unknown as ChannelMessageActionName[] and the switch widens to string. A follow-up SDK PR (against openclaw/openclaw) can extend the union and remove the casts. Two unrelated pre-existing typecheck failures on main (capabilities: ['cards'] literal vs 'presentation'|'delivery-pin', and task.ts agent_task_status) are untouched.

Required scopes

Same scopes as the existing read helpers being reused — im:message:readonly, im:chat:readonly. Already documented for getMessageFeishu / listChatMembersFeishu.

Tests

Smoke-verified locally against the live Feishu API (@larksuite/[email protected] install with this patch applied):

  • list returned 3 most-recent messages from a real group chat with count/scanned/nextPageToken/hasMore and a sane textExcerpt for each.
  • get returned a full FeishuMessageInfo for a known message id including reactions/sender/parsed body.
  • search returned 5 substring hits over a 50-row scan window with scanned/count accounting.
  • members returned 10 human members of the same chat with memberId/name/memberIdType.

I'm happy to add a Vitest harness if the project would like one for read paths — let me know the preferred shape.

Related downstream

A standalone Python skill (feishu-group/scripts/fg.py) currently provides similar read functionality outside the SDK; once this PR ships it becomes a fallback for patch drift / pre-merge installs only. Local install + idempotent patch script that motivated this PR: it overlays these two files onto the npm-installed package and skips when upstream already supports them.

Add 4 read actions to the Lark/Feishu `message` tool adapter, parallel to
the existing send/react/reactions/delete/unsend write actions, so agents
can answer 'what was just said in chat X' without grepping local cache.

API surface:
  - message action=list    chatId=<oc_xxx> [limit] [scan] [sender] [since_hours|since_days]
  - message action=get     messageId=<om_xxx> [full=true]
  - message action=search  chatId=<oc_xxx> text=... [limit] [scan]
  - message action=members chatId=<oc_xxx> [pageToken]

Implementation reuses the already-exported helpers `getMessageFeishu` and
`listChatMembersFeishu`; `list` and `search` add a thin wrapper around
`im/v1/messages` GET with ByCreateTimeDesc paging plus a small client-side
filter layer (sender / substring text / since-hours).

The new action names ('list', 'get', 'members') are not yet in the openclaw
SDK `ChannelMessageActionName` union (only 'search' is). They are valid Lark
actions, so the `SUPPORTED_ACTIONS` Set casts the new names through unknown
and the switch labels widen to `string`. A follow-up SDK PR can extend the
union and remove the casts. No write actions or backward compat changed.

Smoke verified locally against live Feishu API: 4 actions all return well-
formed JSON over a real chat (containers, members, messages, search hits).

Pre-existing typecheck failures on main (capabilities literal in
describeMessageTool, task.ts agent_task_status) are unaffected by this
patch and out of scope.
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants