import type { AgentIntegrationChatType, AgentIntegrationDropReason, AgentIntegrationProvider } from "@rudderhq/shared";
export interface FeishuInboundMessage {
    provider: "feishu";
    eventId: string;
    appId: string;
    botOpenId: string | null;
    chatId: string;
    chatType: AgentIntegrationChatType;
    messageId: string;
    senderOpenId: string;
    senderUnionId: string | null;
    body: string;
    commandBody: string;
    addressedToBot: boolean;
    messageType: string;
    parentMessageId?: string | null;
    receivedAt?: Date;
}
export interface ResolvedAgentIntegration {
    id: string;
    orgId: string;
    agentId: string;
    provider: AgentIntegrationProvider;
    status: "active" | "revoked" | "error";
}
export interface ResolvedIntegrationUserBinding {
    userId: string;
    orgMember: boolean;
}
export interface ResolvedIntegrationChatBinding {
    conversationId: string;
    created?: boolean;
    initialTitle?: string | null;
}
export interface AppendedIntegrationMessage {
    chatMessageId: string;
}
export interface CreatedIntegrationIssue {
    issueId: string;
}
export interface StartedIntegrationRun {
    runId: string;
}
export type ParsedFeishuQuickCommand = {
    kind: "new";
} | {
    kind: "stop";
};
export interface HandledFeishuQuickCommand {
    command: ParsedFeishuQuickCommand["kind"];
    conversationId: string;
    chatMessageId: string | null;
    runId: string | null;
    text: string;
}
export interface MintedIntegrationBindingToken {
    token: string;
    expiresAt: Date;
}
export interface FeishuOutboundResponse {
    provider: "feishu";
    externalChatId: string;
    externalMessageId: string | null;
    text: string;
}
export interface AgentIntegrationInboundAuditInput {
    orgId: string | null;
    integrationId: string | null;
    provider: AgentIntegrationProvider;
    externalChatId: string | null;
    externalChatType: AgentIntegrationChatType | null;
    externalEventId: string | null;
    externalMessageId: string | null;
    senderOpenId: string | null;
    dropReason: AgentIntegrationDropReason;
    bodyPersisted: false;
    metadata?: Record<string, unknown> | null;
}
export interface AgentIntegrationInboundDispatcherDeps {
    resolveActiveIntegration: (event: FeishuInboundMessage) => Promise<ResolvedAgentIntegration | null>;
    auditDrop: (input: AgentIntegrationInboundAuditInput) => Promise<void>;
    resolveUserBinding: (integration: ResolvedAgentIntegration, event: FeishuInboundMessage) => Promise<ResolvedIntegrationUserBinding | null>;
    mintBindingToken: (integration: ResolvedAgentIntegration, event: FeishuInboundMessage) => Promise<MintedIntegrationBindingToken>;
    tryInsertDedup: (integration: ResolvedAgentIntegration, event: FeishuInboundMessage) => Promise<boolean>;
    ensureChatBinding: (integration: ResolvedAgentIntegration, binding: ResolvedIntegrationUserBinding, event: FeishuInboundMessage) => Promise<ResolvedIntegrationChatBinding>;
    appendInboundMessage: (integration: ResolvedAgentIntegration, binding: ResolvedIntegrationUserBinding, chat: ResolvedIntegrationChatBinding, event: FeishuInboundMessage) => Promise<AppendedIntegrationMessage>;
    createIssueFromCommand?: (integration: ResolvedAgentIntegration, binding: ResolvedIntegrationUserBinding, chat: ResolvedIntegrationChatBinding, message: AppendedIntegrationMessage, command: ParsedIntegrationIssueCommand, event: FeishuInboundMessage) => Promise<CreatedIntegrationIssue>;
    handleQuickCommand?: (integration: ResolvedAgentIntegration, binding: ResolvedIntegrationUserBinding, chat: ResolvedIntegrationChatBinding, command: ParsedFeishuQuickCommand, event: FeishuInboundMessage) => Promise<HandledFeishuQuickCommand>;
    enqueueAgentRun?: (integration: ResolvedAgentIntegration, binding: ResolvedIntegrationUserBinding, chat: ResolvedIntegrationChatBinding, message: AppendedIntegrationMessage, event: FeishuInboundMessage, issue: CreatedIntegrationIssue | null) => Promise<StartedIntegrationRun | null>;
    createOutboundPlaceholder?: (integration: ResolvedAgentIntegration, chat: ResolvedIntegrationChatBinding, event: FeishuInboundMessage, message: AppendedIntegrationMessage, issue: CreatedIntegrationIssue | null, run: StartedIntegrationRun | null) => Promise<void>;
}
export type AgentIntegrationInboundDispatchResult = {
    status: "dropped";
    reason: AgentIntegrationDropReason;
} | {
    status: "binding_required";
    bindingToken: MintedIntegrationBindingToken;
    outbound: FeishuOutboundResponse;
} | {
    status: "quick_command";
    command: ParsedFeishuQuickCommand["kind"];
    conversationId: string;
    chatMessageId: string | null;
    runId: string | null;
    outbound: FeishuOutboundResponse;
} | {
    status: "accepted";
    conversationId: string;
    chatMessageId: string;
    issueId: string | null;
    runId: string | null;
    outbound: FeishuOutboundResponse;
};
export interface ParsedIntegrationIssueCommand {
    title: string;
    body: string | null;
}
export declare function parseIntegrationIssueCommand(commandBody: string): ParsedIntegrationIssueCommand | null;
export declare function parseFeishuQuickCommand(commandBody: string): ParsedFeishuQuickCommand | null;
export declare function dispatchFeishuInboundMessage(event: FeishuInboundMessage, deps: AgentIntegrationInboundDispatcherDeps): Promise<AgentIntegrationInboundDispatchResult>;
//# sourceMappingURL=inbound-dispatcher.d.ts.map