/** * Rate Limiting Middleware * * Sliding-window rate limiter keyed by caller phone number. * Prevents abuse by limiting requests per phone number within a time window. */ import type { Context, Next } from "hono"; import type { TalkerConfig } from "../types"; export declare const DEFAULT_MAX_REQUESTS = 30; export declare const DEFAULT_WINDOW_MS = 60000; /** * Stop the periodic cleanup timer without discarding tracked counts, so a * host can release the timer on shutdown (mirrors `core/context.ts`'s * `stopCleanup`) without resetting rate-limit state the way * `resetRateLimitStore` does. */ export declare function stopRateLimitCleanup(): void; /** * Check if a phone number has exceeded the rate limit. * Returns true if the request should be allowed. */ export declare function checkRateLimit(phoneNumber: string, maxRequests: number, windowMs: number): boolean; /** * Hono middleware factory for rate limiting. * * Limits requests per phone number (from body.From). * Returns a 429 TwiML response when the limit is exceeded. * * `talkerConfig` is what makes that response speak: the `rateLimited` phrase * is looked up in the caller's detected language and rendered by `sayTwiml`, * so it carries the configured voice and is escaped like every other spoken * string. It stays optional because the middleware is exported for hosts to * mount on their own routes; without it the phrase still resolves (built-in * copy, default voice), only a host's `languageDir` and `voices` overrides * are missed. */ export declare function rateLimitMiddleware(config?: { maxRequests?: number; windowMs?: number; }, talkerConfig?: TalkerConfig): (c: Context, next: Next) => Promise; /** * Reset rate limit store (for testing) */ export declare function resetRateLimitStore(): void;