import * as lark from '@larksuiteoapi/node-sdk'; import type { Readable } from 'node:stream'; import { type AgentFeishuScopeGrant, type FeishuConfig } from '../../shared/agent-config.js'; import type { FeishuMessageResourceType } from './feishu-file.service.js'; import type { FeishuPostContent } from './markdown-to-feishu-post.js'; export declare const FEISHU_OPEN_API_BASE_URL = "https://open.feishu.cn/open-apis"; export type FeishuReceiveIdType = 'chat_id' | 'open_id'; export type FeishuTextSendInput = { chatId: string; text: string; } | { receiveId: string; receiveIdType: FeishuReceiveIdType; text: string; }; export interface FeishuTextReplyInput { messageId: string; replyInThread: boolean; text: string; } export type FeishuPostSendInput = { receiveId: string; receiveIdType: FeishuReceiveIdType; content: FeishuPostContent; }; export interface FeishuPostReplyInput { messageId: string; replyInThread: boolean; content: FeishuPostContent; } export interface FeishuPostUpdateInput { messageId: string; content: FeishuPostContent; } export interface FeishuTextSendResult { chatId?: string; messageId?: string; threadId?: string; } export type FeishuUploadedFileKind = 'file' | 'image'; export interface FeishuFileUploadInput { bytes: Buffer; filename: string; mimetype: string; } export interface FeishuUploadedFile { fileKey: string; kind: FeishuUploadedFileKind; } export interface FeishuFileSendInput { file: FeishuUploadedFile; receiveId: string; receiveIdType: FeishuReceiveIdType; threadMessageId?: string; } export interface FeishuMessageResourceDownloadInput { fileKey: string; messageId: string; resourceType: FeishuMessageResourceType; } export interface FeishuMessageResourceDownload { bytes: Buffer; contentType?: string; filename?: string; } export interface FeishuMessageListInput { chatId: string; cursor?: string; limit: number; threadId?: string; } export interface FeishuMessageListResult { hasMore: boolean; messages: FeishuConversationMessage[]; nextCursor?: string; } export interface FeishuChatInfo { avatarUrl?: string; chatId: string; chatName?: string; chatType?: string; } export interface FeishuUserBasicInfo { i18nName?: Record; name?: string; openId: string; unionId?: string; userId?: string; } export interface FeishuConversationMessage { bodyContent?: string; chatId?: string; chatType?: string; createTime?: string; deleted?: boolean; mentions?: FeishuConversationMention[]; messageId: string; messageType?: string; parentId?: string; rootId?: string; sender?: FeishuConversationSender; threadId?: string; updated?: boolean; } export interface FeishuConversationMention { id?: string; idType?: string; key: string; name?: string; tenantKey?: string; } export interface FeishuConversationSender { id?: string; idType?: string; senderName?: string; senderType?: string; tenantKey?: string; } export interface FeishuMessageGetInput { messageId: string; } export interface FeishuReactionAddInput { emojiType: string; messageId: string; } export interface FeishuReactionAddResult { reactionId: string; } export interface FeishuReactionRemoveInput { messageId: string; reactionId: string; } export interface FeishuMessageClient { addReaction(input: FeishuReactionAddInput): Promise; downloadMessageResource(input: FeishuMessageResourceDownloadInput): Promise; getChat?(input: { chatId: string; }): Promise; getMessage?(input: FeishuMessageGetInput): Promise; getUserBasics?(input: { openIds: string[]; }): Promise; listMessages(input: FeishuMessageListInput): Promise; removeReaction(input: FeishuReactionRemoveInput): Promise; replyText(input: FeishuTextReplyInput): Promise; replyPost(input: FeishuPostReplyInput): Promise; sendUploadedFile(input: FeishuFileSendInput): Promise; sendText(input: FeishuTextSendInput): Promise; sendPost(input: FeishuPostSendInput): Promise; updatePost?(input: FeishuPostUpdateInput): Promise; uploadFile(input: FeishuFileUploadInput): Promise; } export interface FeishuTenantAccessToken { expiresAt?: string; tenantAccessToken: string; } export interface FeishuBotInfo { appName?: string; avatarUrl?: string; openId?: string; } export interface FeishuRegisterAppInput { appPreset?: { avatar?: string | string[]; desc?: string; name?: string; }; onQRCodeReady(info: { expireIn: number; url: string; }): void; onStatusChange?(info: { interval?: number; status: 'polling' | 'slow_down' | 'domain_switched'; }): void; signal?: AbortSignal; source?: string; } export interface FeishuRegisterAppResult { appId: string; appSecret: string; tenantBrand?: 'feishu' | 'lark'; userOpenId?: string; } type FetchLike = (url: string, init: { body: string; headers: Record; method: 'POST'; }) => Promise<{ json(): Promise; ok: boolean; status: number; text(): Promise; }>; interface FeishuTenantAccessTokenDeps { apiBaseUrl?: string; fetch?: FetchLike; nowMs?: () => number; } interface FeishuSdkMessageCreateInput { data: { content: string; msg_type: 'file' | 'image' | 'post' | 'text'; receive_id: string; }; params: { receive_id_type: FeishuReceiveIdType; }; } interface FeishuSdkMessageReplyInput { data: { content: string; msg_type: 'file' | 'image' | 'post' | 'text'; reply_in_thread: boolean; }; path: { message_id: string; }; } interface FeishuSdkMessageReplyResult { data?: { chat_id?: string; message_id?: string; thread_id?: string; }; } interface FeishuSdkMessageListInput { params: { container_id: string; container_id_type: 'chat' | 'thread'; page_size: number; page_token?: string; sort_type: 'ByCreateTimeDesc'; }; } interface FeishuSdkMessageGetInput { params?: { user_id_type?: 'open_id' | 'union_id' | 'user_id'; }; path: { message_id: string; }; } interface FeishuSdkMessageListResult { data?: { has_more?: boolean; items?: FeishuSdkListedMessage[]; page_token?: string; }; } type FeishuSdkFileType = 'doc' | 'mp4' | 'opus' | 'pdf' | 'ppt' | 'stream' | 'xls'; interface FeishuSdkFileCreateInput { data: { file: Buffer; file_name: string; file_type: FeishuSdkFileType; }; } interface FeishuSdkFileCreateResult { data?: { file_key?: string; }; file_key?: string; } interface FeishuSdkImageCreateInput { data: { image: Buffer; image_type: 'message'; }; } interface FeishuSdkImageCreateResult { data?: { image_key?: string; }; image_key?: string; } interface FeishuSdkListedMessage { body?: { content?: string; }; chat_id?: string; chat_type?: string; create_time?: string; deleted?: boolean; mentions?: Array<{ id?: string; id_type?: string; key?: string; name?: string; tenant_key?: string; }>; message_id?: string; msg_type?: string; parent_id?: string; root_id?: string; sender?: { id?: string; id_type?: string; sender_name?: string; sender_type?: string; tenant_key?: string; }; thread_id?: string; updated?: boolean; } interface FeishuSdkReactionCreateInput { data: { reaction_type: { emoji_type: string; }; }; path: { message_id: string; }; } interface FeishuSdkReactionCreateResult { data?: { reaction_id?: string; }; } interface FeishuSdkReactionDeleteInput { path: { message_id: string; reaction_id: string; }; } interface FeishuSdkMessageResourceGetInput { params: { type: 'file' | 'image'; }; path: { file_key: string; message_id: string; }; } interface FeishuSdkMessageResourceGetResult { getReadableStream(): Readable; headers?: Record; } interface FeishuSdkMessageUpdateInput { data: { content: string; msg_type: 'post'; }; path: { message_id: string; }; } interface FeishuSdkClient { request?(input: { data?: unknown; method: 'GET' | 'POST'; url: string; }): Promise; im: { file?: { create(input: FeishuSdkFileCreateInput): Promise; }; image?: { create(input: FeishuSdkImageCreateInput): Promise; }; message: { create(input: FeishuSdkMessageCreateInput): Promise; get?(input: FeishuSdkMessageGetInput): Promise; list?(input: FeishuSdkMessageListInput): Promise; reply(input: FeishuSdkMessageReplyInput): Promise; update?(input: FeishuSdkMessageUpdateInput): Promise; }; messageReaction: { create(input: FeishuSdkReactionCreateInput): Promise; delete(input: FeishuSdkReactionDeleteInput): Promise; }; messageResource?: { get(input: FeishuSdkMessageResourceGetInput): Promise; }; }; } interface FeishuOpenApiDeps { fetch?: typeof fetch; fetchFeishuTenantAccessToken?: typeof fetchFeishuTenantAccessToken; nowMs?: () => number; } interface FeishuMessageClientDeps extends FeishuOpenApiDeps { createClient?(config: FeishuConfig): FeishuSdkClient; } export declare class FeishuApiError extends Error { readonly code: string; readonly vendorMessage?: string; constructor(input: { code: number | string; operation: string; vendorMessage?: string; }); } export declare function fetchFeishuTenantAccessToken(config: FeishuConfig, deps?: FeishuTenantAccessTokenDeps): Promise; export declare function registerFeishuApp(input: FeishuRegisterAppInput): Promise; export declare function fetchFeishuBotInfo(config: FeishuConfig, deps?: FeishuMessageClientDeps): Promise; export declare function fetchFeishuAppScopes(config: FeishuConfig, deps?: FeishuOpenApiDeps): Promise; export declare function feishuScopeAuthUrl(appId: string, scopes: readonly string[]): string | undefined; export declare function feishuProfileNameScopeAuthUrl(appId: string): string | undefined; export declare function createFeishuMessageClient(config: FeishuConfig, deps?: FeishuMessageClientDeps): FeishuMessageClient; export declare function createFeishuEventDispatcher(input: { config: FeishuConfig; onReactionCreated?(data: unknown): Promise; onReceiveMessage(data: unknown): Promise; }): lark.EventDispatcher; export declare function createFeishuWsClient(config: FeishuConfig): lark.WSClient; export {}; //# sourceMappingURL=client.d.ts.map