/**
 * Webhook Server
 *
 * Shared webhook server for handling incoming webhooks from
 * Telegram, Discord, Slack, and other platforms.
 */
import { EventEmitter } from 'events';
import http from 'http';
import type { TelegramChannel } from './telegram/index.js';
import type { SlackChannel } from './slack/index.js';
/**
 * Webhook server configuration
 */
export interface WebhookServerConfig {
    /** Port to listen on */
    port: number;
    /** Host to bind to */
    host?: string;
    /** Path prefix for webhooks */
    pathPrefix?: string;
    /** Use HTTPS */
    https?: boolean;
    /** SSL certificate for HTTPS */
    sslCert?: string;
    /** SSL key for HTTPS */
    sslKey?: string;
    /** Request timeout in ms */
    timeout?: number;
    /** Maximum request body size in bytes */
    maxBodySize?: number;
}
/**
 * Webhook request
 */
export interface WebhookRequest {
    method: string;
    path: string;
    query: URLSearchParams;
    headers: http.IncomingHttpHeaders;
    body: unknown;
    rawBody: string;
}
/**
 * Webhook response
 */
export interface WebhookResponse {
    status?: number;
    headers?: Record<string, string>;
    body?: string | object;
}
/**
 * Webhook server for handling incoming webhooks
 */
export declare class WebhookServer extends EventEmitter {
    private config;
    private server;
    private handlers;
    private running;
    constructor(config?: Partial<WebhookServerConfig>);
    /**
     * Start the webhook server
     */
    start(): Promise<void>;
    /**
     * Stop the webhook server
     */
    stop(): Promise<void>;
    /**
     * Register a webhook handler
     */
    registerHandler(path: string, handler: (req: WebhookRequest) => Promise<WebhookResponse>): void;
    /**
     * Unregister a webhook handler
     */
    unregisterHandler(path: string): void;
    /**
     * Register Telegram webhook handler
     */
    registerTelegram(channel: TelegramChannel, path?: string): void;
    /**
     * Register Slack webhook handler
     */
    registerSlack(channel: SlackChannel, path?: string): void;
    /**
     * Handle incoming request
     */
    private handleRequest;
    /**
     * Derive a session key from a webhook request.
     *
     * Extracts a chat/channel ID from the request body when possible
     * (e.g. Telegram chat.id, Slack channel), falling back to the
     * webhook path so that all requests for the same endpoint are
     * serialized together.
     */
    private deriveSessionKey;
    /**
     * Attempt to resolve a peer route from a webhook request body.
     *
     * Builds a minimal InboundMessage from the webhook payload and
     * runs it through the PeerRouter. Returns null if no route matches
     * or if the body lacks the necessary fields.
     */
    private resolveWebhookRoute;
    /**
     * Parse request body
     */
    private parseBody;
    /**
     * Get server URL
     */
    getUrl(): string;
    /**
     * Check if server is running
     */
    isRunning(): boolean;
}
/**
 * Get webhook server instance
 */
export declare function getWebhookServer(config?: Partial<WebhookServerConfig>): WebhookServer;
/**
 * Reset webhook server
 */
export declare function resetWebhookServer(): void;
export default WebhookServer;
