openclaw/extensions/lark/src/reply-dispatcher.ts
devsh e89378a0e7 feat(lark): add Feishu/Lark channel plugin with security fixes
- Initialize runtime in register() to fix 'runtime not initialized' error
- Move clawdbot from dependencies to devDependencies/peerDependencies
- Add security adapter with DM policy (pairing, allowlist, open)
- Add pairing adapter for user approval flow
- Add status adapter for health checks and diagnostics
- Add groups adapter for mention/tool policy resolution
- Add reload config prefixes for hot reload support
- Add outbound chunker for long messages
- Fix verification token enforcement in webhook handler
- Add allowFrom validation before processing messages
- Add comprehensive input validation in webhook handler
- Improve type safety and error handling throughout
2026-01-26 17:29:10 +08:00

36 lines
899 B
TypeScript

import type { ReplyDispatcher, ClawdbotConfig } from "clawdbot/plugin-sdk";
import { larkOutbound } from "./send.js";
type PayloadBody = string | { text?: string } | null | undefined;
function extractText(body: PayloadBody): string {
if (typeof body === "string") return body;
if (body && typeof body === "object" && "text" in body) {
return body.text ?? "";
}
return "";
}
export function createLarkReplyDispatcher(opts: {
cfg: ClawdbotConfig;
channelId: string;
}): ReplyDispatcher {
return {
dispatch: async (payload) => {
const text = extractText(payload.body as PayloadBody);
if (!text) {
return { id: "skipped", ts: Date.now() };
}
const result = await larkOutbound.sendText({
cfg: opts.cfg,
to: opts.channelId,
text,
});
return { id: result.id ?? "", ts: result.ts ?? Date.now() };
},
};
}