Skip to content

Commit 1f60d9e

Browse files
authored
feat(feishu): let agents resend received stickers (#130374)
* feat(feishu): resend received stickers without losing topic routing Add opt-in agent sticker sending using received file keys, preserve inbound keys, and stop unsupported sticker resource downloads. Reuse keyed-media delivery and canonical reply selection; inherit source topics only within the same destination and account. Related: #114578. * fix(feishu): preserve topic mode for prepared implicit replies * docs(feishu): preserve account action gates when enabling stickers
1 parent 9afd058 commit 1f60d9e

16 files changed

Lines changed: 549 additions & 117 deletions

‎config/assertion-safety-baseline.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ extensions/feishu/src/bot-sender-name.ts 2
465465
extensions/feishu/src/bot.ts 9
466466
extensions/feishu/src/card-action.ts 1
467467
extensions/feishu/src/card-interaction.ts 1
468-
extensions/feishu/src/channel.ts 9
468+
extensions/feishu/src/channel.ts 7
469469
extensions/feishu/src/chat.ts 2
470470
extensions/feishu/src/client.ts 4
471471
extensions/feishu/src/comment-handler.ts 2

‎docs/channels/feishu.md‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ Full configuration: [Gateway configuration](/gateway/configuration)
648648
| `channels.feishu.accounts.<id>.domain` | Per-account domain override | `feishu` |
649649
| `channels.feishu.accounts.<id>.replyToMode` | Per-account reply-reference mode | inherited |
650650
| `channels.feishu.accounts.<id>.tts` | Per-account TTS override | `tts` |
651+
| `channels.feishu.accounts.<id>.actions.sticker` | Per-account sticker action override | inherited |
651652
| `channels.feishu.dmPolicy` | DM policy (`pairing`, `allowlist`, `open`) | `pairing` |
652653
| `channels.feishu.allowFrom` | DM allowlist (open_id list) | - |
653654
| `channels.feishu.groupPolicy` | Group policy (`open`, `allowlist`, `disabled`) | `allowlist` |
@@ -662,6 +663,7 @@ Full configuration: [Gateway configuration](/gateway/configuration)
662663
| `channels.feishu.replyToMode` | Reply-reference mode (`off`, `first`, `all`, `batched`) | `all` |
663664
| `channels.feishu.replyInThread` | Bot replies create/continue topic threads (`disabled`, `enabled`) | `disabled` |
664665
| `channels.feishu.reactionNotifications` | Inbound reaction events (`off`, `own`, `all`) | `own` |
666+
| `channels.feishu.actions.sticker` | Enable sending stickers previously received by the bot | `false` |
665667
| `channels.feishu.vcAutoJoin` | Join invited VC meetings after normal DM authorization | `false` |
666668
| `channels.feishu.dynamicAgentCreation.enabled` | Enable automatic per-user agent creation | `false` |
667669
| `channels.feishu.dynamicAgentCreation.workspaceTemplate` | Path template for dynamic agent workspaces | `~/.openclaw/workspace-{agentId}` |
@@ -705,6 +707,10 @@ repair it before starting the gateway.
705707
- ✅ Video/media
706708
- ✅ Stickers
707709

710+
Received stickers expose their reusable `file_key` to the agent as
711+
`<sticker key="..."/>`. Feishu/Lark does not support downloading sticker
712+
resources, so OpenClaw preserves the key without fetching an attachment.
713+
708714
Inbound Feishu/Lark audio messages are normalized as media placeholders instead
709715
of raw `file_key` JSON. When `tools.media.audio` is configured, OpenClaw
710716
downloads the voice-note resource and runs shared audio transcription before the
@@ -722,6 +728,7 @@ resource payload.
722728
- ✅ Audio
723729
- ✅ Video/media
724730
- ✅ Interactive cards (including streaming updates)
731+
- ✅ Stickers previously received by the same bot (requires `actions.sticker`)
725732
- ⚠️ Rich text (post-style formatting; doesn't support full Feishu/Lark authoring capabilities)
726733

727734
Native Feishu/Lark audio bubbles use the Feishu `audio` message type and require
@@ -732,6 +739,49 @@ delivery (`audioAsVoice` / message tool `asVoice`, including TTS voice-note
732739
replies). Ordinary MP3 attachments stay regular files. If `ffmpeg` is missing or
733740
conversion fails, OpenClaw falls back to a file attachment and logs the reason.
734741

742+
### Sticker replies
743+
744+
Enable the sticker action to let the agent resend stickers:
745+
746+
```json5
747+
{
748+
channels: {
749+
feishu: {
750+
actions: { sticker: true },
751+
},
752+
},
753+
}
754+
```
755+
756+
For one account only, set `channels.feishu.accounts.<id>.actions.sticker: true`
757+
instead. An account-level `actions` object **replaces**, rather than merges
758+
with, the channel-level object. Repeat any action gates you want to preserve.
759+
For example, keep reactions disabled while enabling stickers for `work`:
760+
761+
```json5
762+
{
763+
channels: {
764+
feishu: {
765+
actions: { reactions: false },
766+
accounts: {
767+
work: {
768+
actions: { reactions: false, sticker: true },
769+
},
770+
},
771+
},
772+
},
773+
}
774+
```
775+
776+
Send a sticker to that bot first, then ask it to resend the sticker.
777+
The shared `message` tool uses `action: "sticker"` with the received `file_key`
778+
in `fileId` or the first entry of `stickerId`. In multi-account setups, use the
779+
same `accountId` that received the sticker.
780+
781+
Only stickers previously received by that bot can be sent. Uploading new
782+
stickers, downloading sticker resources, and searching the sticker store are
783+
not supported.
784+
735785
### Threads and replies
736786

737787
- ✅ Inline replies

‎extensions/feishu/src/bot-content.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Feishu plugin module implements bot content behavior.
22
import { parseStrictNonNegativeInteger } from "openclaw/plugin-sdk/number-runtime";
3+
import { escapeHtml } from "openclaw/plugin-sdk/text-utility-runtime";
34
import type { ClawdbotConfig } from "../runtime-api.js";
45
import { buildFeishuConversationId } from "./conversation-id.js";
56
import { normalizeFeishuExternalKey } from "./external-keys.js";
@@ -178,6 +179,10 @@ export function parseMessageContent(content: string, messageType: string): strin
178179
const FEISHU_MEDIA_MESSAGE_TYPES = new Set(["image", "file", "audio", "video", "media", "sticker"]);
179180

180181
function formatFeishuMediaContent(parsed: Record<string, unknown>, messageType: string): string {
182+
if (messageType === "sticker") {
183+
const fileKey = normalizeFeishuExternalKey(parsed?.file_key);
184+
return fileKey ? `<sticker key="${escapeHtml(fileKey)}"/>` : "[Sticker]";
185+
}
181186
const speechToText =
182187
messageType === "audio" && typeof parsed.speech_to_text === "string"
183188
? parsed.speech_to_text.trim()
@@ -207,7 +212,7 @@ function formatSubMessageContent(content: string, contentType: string): string {
207212
case "video":
208213
return "[Video]";
209214
case "sticker":
210-
return "[Sticker]";
215+
return formatFeishuMediaContent(parsed, contentType);
211216
case "merge_forward":
212217
return "[Nested Merged Forward]";
213218
default:
@@ -333,7 +338,6 @@ function parseMediaKeys(
333338
return { imageKey, fileName: parsed.file_name };
334339
case "file":
335340
case "audio":
336-
case "sticker":
337341
return { fileKey, fileName: parsed.file_name };
338342
case "video":
339343
case "media":
@@ -383,8 +387,6 @@ function resolveFeishuMediaKind(messageType: string): FeishuMediaInfo["kind"] {
383387
case "video":
384388
case "media":
385389
return "video";
386-
case "sticker":
387-
return "sticker";
388390
default:
389391
return "document";
390392
}
@@ -400,7 +402,8 @@ export async function resolveFeishuMediaList(params: {
400402
accountId?: string;
401403
}): Promise<FeishuMediaInfo[]> {
402404
const { cfg, messageId, messageType, content, maxBytes, log, accountId } = params;
403-
const mediaTypes = ["image", "file", "audio", "video", "media", "sticker", "post"];
405+
// Sticker keys are reusable, but Feishu does not expose their resource bytes.
406+
const mediaTypes = ["image", "file", "audio", "video", "media", "post"];
404407
if (!mediaTypes.includes(messageType)) {
405408
return [];
406409
}

‎extensions/feishu/src/bot.helpers.test.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { describe, expect, it } from "vitest";
33
import type { ClawdbotConfig } from "../runtime-api.js";
44
import { buildFeishuAgentBody } from "./bot-agent-body.js";
55
import { buildBroadcastSessionKey, resolveBroadcastAgents } from "./bot-broadcast.js";
6-
import { parseMessageContent } from "./bot-content.js";
6+
import { parseMergeForwardContent, parseMessageContent } from "./bot-content.js";
77

88
describe("buildFeishuAgentBody", () => {
99
it("builds message id, speaker, quoted content, mention context, and permission notice in order", () => {
@@ -95,6 +95,30 @@ describe("parseMessageContent media captions", () => {
9595
it("keeps malformed media bodies empty", () => {
9696
expect(parseMessageContent("not-json", "image")).toBe("");
9797
});
98+
99+
it.each([
100+
[" file_sticker_received ", '<sticker key="file_sticker_received"/>'],
101+
['sticker_"<&', '<sticker key="sticker_&quot;&lt;&amp;"/>'],
102+
["", "[Sticker]"],
103+
["../sticker", "[Sticker]"],
104+
])("preserves a received sticker key as safe model-visible content: %s", (fileKey, expected) => {
105+
expect(parseMessageContent(JSON.stringify({ file_key: fileKey }), "sticker")).toBe(expected);
106+
});
107+
108+
it("keeps a forwarded sticker key available to the agent", () => {
109+
expect(
110+
parseMergeForwardContent({
111+
content: JSON.stringify([
112+
{ message_id: "om_forward", msg_type: "merge_forward" },
113+
{
114+
upper_message_id: "om_forward",
115+
msg_type: "sticker",
116+
body: { content: JSON.stringify({ file_key: "file_forwarded_sticker" }) },
117+
},
118+
]),
119+
}),
120+
).toBe('[Merged and Forwarded Messages]\n- <sticker key="file_forwarded_sticker"/>');
121+
});
98122
});
99123

100124
describe("resolveBroadcastAgents", () => {

‎extensions/feishu/src/channel.runtime.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
listFeishuDirectoryGroupsLive as listFeishuDirectoryGroupsLiveImpl,
1111
listFeishuDirectoryPeersLive as listFeishuDirectoryPeersLiveImpl,
1212
} from "./directory.js";
13+
import { sendStickerFeishu as sendStickerFeishuImpl } from "./media.js";
1314
import { feishuOutbound as feishuOutboundImpl } from "./outbound.js";
1415
import {
1516
createPinFeishu as createPinFeishuImpl,
@@ -49,4 +50,5 @@ export const feishuChannelRuntime = {
4950
getMessageFeishu: getMessageFeishuImpl,
5051
sendCardFeishu: sendCardFeishuImpl,
5152
sendMessageFeishu: sendMessageFeishuImpl,
53+
sendStickerFeishu: sendStickerFeishuImpl,
5254
};

0 commit comments

Comments
 (0)