Files
openclaw/extensions/feishu/src/comment-target.ts
wittam-01 1b94e8ca14 feat: feishu comment event (#58497)
Merged via squash.

Prepared head SHA: a9dfeb0d62
Co-authored-by: wittam-01 <271711640+wittam-01@users.noreply.github.com>
Co-authored-by: odysseus0 <8635094+odysseus0@users.noreply.github.com>
Reviewed-by: @odysseus0
2026-04-01 00:12:38 -07:00

45 lines
1.2 KiB
TypeScript

export const FEISHU_COMMENT_FILE_TYPES = ["doc", "docx", "file", "sheet", "slides"] as const;
export type CommentFileType = (typeof FEISHU_COMMENT_FILE_TYPES)[number];
export function normalizeCommentFileType(value: unknown): CommentFileType | undefined {
return typeof value === "string" &&
(FEISHU_COMMENT_FILE_TYPES as readonly string[]).includes(value)
? (value as CommentFileType)
: undefined;
}
export type FeishuCommentTarget = {
fileType: CommentFileType;
fileToken: string;
commentId: string;
};
export function buildFeishuCommentTarget(params: FeishuCommentTarget): string {
return `comment:${params.fileType}:${params.fileToken}:${params.commentId}`;
}
export function parseFeishuCommentTarget(
raw: string | undefined | null,
): FeishuCommentTarget | null {
const trimmed = raw?.trim();
if (!trimmed?.startsWith("comment:")) {
return null;
}
const parts = trimmed.split(":");
if (parts.length !== 4) {
return null;
}
const fileType = normalizeCommentFileType(parts[1]);
const fileToken = parts[2]?.trim();
const commentId = parts[3]?.trim();
if (!fileType || !fileToken || !commentId) {
return null;
}
return {
fileType,
fileToken,
commentId,
};
}