diff --git a/apps/bot/src/telegram/state.ts b/apps/bot/src/telegram/state.ts index e4ede55..5a8cd25 100644 --- a/apps/bot/src/telegram/state.ts +++ b/apps/bot/src/telegram/state.ts @@ -41,3 +41,53 @@ export function consumePendingSendToGroup(userId: number): string | null { if (Date.now() >= pending.expiresAt) return null; return pending.groupId; } + +// Reminder creation wizard state. +export type WizardStep = + | "pick_account" + | "pick_group" + | "compose" + | "set_time" + | "confirm"; + +export type WizardState = { + step: WizardStep; + accountId?: string; + groupId?: string; + text?: string | null; + mediaId?: string | null; + caption?: string | null; + scheduledAt?: Date; + expiresAt: number; +}; + +const wizardState = new Map(); +const WIZARD_TTL_MS = 30 * 60 * 1000; + +export function getWizard(userId: number): WizardState | null { + const w = wizardState.get(userId); + if (!w) return null; + if (Date.now() >= w.expiresAt) { + wizardState.delete(userId); + return null; + } + return w; +} + +export function startWizard(userId: number): WizardState { + const w: WizardState = { step: "pick_account", expiresAt: Date.now() + WIZARD_TTL_MS }; + wizardState.set(userId, w); + return w; +} + +export function updateWizard(userId: number, patch: Partial): WizardState | null { + const w = getWizard(userId); + if (!w) return null; + const next = { ...w, ...patch, expiresAt: Date.now() + WIZARD_TTL_MS }; + wizardState.set(userId, next); + return next; +} + +export function clearWizard(userId: number): void { + wizardState.delete(userId); +}