export declare const DEFAULT_TELEGRAM_SETUP_API_BASE = "https://api.telegram.org"; export declare const DEFAULT_TELEGRAM_SETUP_POLL_TIMEOUT_MS = 60000; export declare const DEFAULT_TELEGRAM_SETUP_POLL_INTERVAL_MS = 1000; export type TelegramThreadedModeState = "enabled" | "disabled" | "unknown"; export type TelegramThreadedModeLabel = "verified" | "unverified" | "unknown"; export type TelegramSetupPairingSource = "discovered" | "provided" | "reused"; export type TelegramSetupFailureStatus = "error" | "cancelled" | "requires_explicit_chat" | "ownership_lost" | "aborted"; export interface TelegramSetupTimers { now(): number; sleep(ms: number, signal?: AbortSignal): Promise; } export interface TelegramSetupDeps { fetchImpl: typeof fetch; apiBase?: string; timers?: TelegramSetupTimers; } /** Current daemon ownership facts collected by the caller before setup starts. */ export interface TelegramSetupPreflight { storedChatId?: string; daemon?: { live: boolean; tokenFingerprint?: string; /** Required with a live daemon so reuse verifies the complete token/chat identity. */ chatId?: string; }; } export type TelegramSetupPollingPolicy = { kind: "discover"; } | { kind: "reuse_stored_chat"; chatId: string; } | { kind: "validate_explicit_chat"; chatId: string; } | { kind: "requires_explicit_chat"; } | { kind: "cancel_foreign_or_unknown_owner"; identity: "foreign" | "unknown"; }; export type TelegramSetupEvent = { kind: "token_validated"; message: string; } | { kind: "threaded_mode_guidance"; message: string; } | { kind: "rejected_chat"; message: string; }; export interface TelegramSetupSuccess { ok: true; chatId: string; tokenFingerprint: string; threadedMode: TelegramThreadedModeState; threadedLabel: TelegramThreadedModeLabel; pairingSource: TelegramSetupPairingSource; } export interface TelegramSetupFailure { ok: false; status: TelegramSetupFailureStatus; detail: string; } export type TelegramSetupResult = TelegramSetupSuccess | TelegramSetupFailure; export interface TelegramBot { id: number; isBot?: boolean; firstName?: string; username?: string; hasTopicsEnabled?: boolean; allowsUsersToCreateTopics?: boolean; } export type TelegramTokenValidationResult = { ok: true; bot: TelegramBot; threadedMode: TelegramThreadedModeState; } | TelegramSetupFailure; export type TelegramPrivateChatValidationResult = { ok: true; chatId: string; } | TelegramSetupFailure; export interface RunTelegramSetupInput { token: string; preflight: TelegramSetupPreflight; /** * Re-reads daemon ownership immediately before any `getUpdates` call. It is * mandatory for discovery because an earlier preflight cannot own Telegram's * single-poller slot. */ revalidatePreflight?: (signal?: AbortSignal) => Promise; chatId?: string; interactive: boolean; threadedModePrompt?: (message: string) => Promise; pollTimeoutMs?: number; pollIntervalMs?: number; signal?: AbortSignal; onEvent?: (event: TelegramSetupEvent) => void; deps: TelegramSetupDeps; } export declare function withTelegramSetupLease(token: string, operation: () => Promise): Promise; /** Validate a token with getMe without exposing it in diagnostics or results. */ export declare function validateTelegramBotToken(input: { token: string; deps: TelegramSetupDeps; signal?: AbortSignal; }): Promise; /** Validate that a supplied or stored chat is an actual Telegram private chat. */ export declare function validateTelegramPrivateChat(input: { token: string; chatId: string; deps: TelegramSetupDeps; signal?: AbortSignal; }): Promise; /** * Decide whether setup may call getUpdates. Any live daemon is a hard polling * boundary: only a verified complete token/chat identity may reuse the stored * chat; setup never polls while any live owner exists. */ export declare function resolveTelegramSetupPollingPolicy(input: { token: string; preflight: TelegramSetupPreflight; chatId?: string; }): TelegramSetupPollingPolicy; /** * Validate a token, assess Threaded Mode, and obtain a private chat according * to the daemon poller-contention policy. No settings are written here. */ export declare function runTelegramSetup(input: RunTelegramSetupInput): Promise;