Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

2.9 KB
Raw Blame
/**
 * Lark/Feishu adapter configuration.
 */
export interface LarkAdapterConfig {
  /** Lark app ID */
  appId: string;
  /** Lark app secret */
  appSecret: string;
  /** AES decrypt key for encrypted events (optional) */
  encryptKey?: string;
  /** 'lark' (international) or 'feishu' (China) β€” determines API base URL */
  platform?: 'lark' | 'feishu';
  /** Bot display name override */
  userName?: string;
  /** Verification token for webhook event validation (optional β€” skip verification when unset) */
  verificationToken?: string;
}

/**
 * Lark thread ID components.
 */
export interface LarkThreadId {
  /** Lark chat ID (group or P2P) */
  chatId: string;
  /**
   * Lark chat type, encoded into the threadId so the sync `isDM(threadId)`
   * the Chat SDK requires can derive the answer without a side cache.
   * `undefined` means unknown β€” produced by paths that don't have the chat
   * type at hand (e.g. `parseMessage` for historical fetches), and decoded
   * back from the legacy 2-segment threadId format for backward compat.
   */
  chatType?: 'p2p' | 'group';
  /** Platform variant */
  platform: 'lark' | 'feishu';
}

/**
 * Lark sender info from im.message.receive_v1 event.
 */
export interface LarkSender {
  sender_id: {
    open_id: string;
    union_id?: string;
    user_id?: string;
  };
  sender_type: string;
  tenant_key?: string;
}

/**
 * Lark message body from im.message.receive_v1 event.
 */
export interface LarkMessageBody {
  chat_id: string;
  chat_type?: string;
  content: string;
  create_time: string;
  mentions?: LarkMention[];
  message_id: string;
  message_type: string;
  /**
   * ID of the message this one replies to (the quoted message). Feishu only
   * sends the ID β€” the quoted content and attachments have to be fetched via
   * `GET /im/v1/messages/:message_id`.
   */
  parent_id?: string;
  /** Root message ID of the reply chain / topic thread, when applicable. */
  root_id?: string;
  /** Topic thread ID, when the message lives in a thread. */
  thread_id?: string;
}

export interface LarkMention {
  id: { open_id: string; union_id?: string; user_id?: string };
  key: string;
  name: string;
  tenant_key?: string;
}

/**
 * Lark event header.
 */
export interface LarkEventHeader {
  app_id: string;
  create_time: string;
  event_id: string;
  event_type: string;
  tenant_key: string;
  token: string;
}

/**
 * Lark im.message.receive_v1 event body.
 */
export interface LarkMessageEvent {
  message: LarkMessageBody;
  sender: LarkSender;
}

/**
 * Full Lark webhook payload (Event Subscription v2).
 */
export interface LarkWebhookPayload {
  challenge?: string;
  encrypt?: string;
  event?: LarkMessageEvent;
  header?: LarkEventHeader;
  /** Verification token β€” present at top level in url_verification events */
  token?: string;
  type?: string;
}

/** Raw message type for the adapter generic */
export type LarkRawMessage = LarkMessageBody;