/** * Pairing Integration Helpers * * Utility functions for integrating the PairingService with channel plugins. * This provides a consistent interface for handling the pairing workflow * across different messaging platforms. */ import type { PairingChannel } from "../types/pairing.js"; import type { IAgentRuntime } from "../types/runtime.js"; import type { PairingService } from "./pairing.js"; /** * Result of a pairing check */ export interface PairingCheckResult { /** Whether the sender is allowed to proceed */ allowed: boolean; /** If not allowed, the pairing code (if a new request was created) */ pairingCode?: string; /** Whether a new pairing request was created */ newRequest?: boolean; /** Human-readable message to send to the user */ replyMessage?: string; /** The ID label for this channel (e.g., "phoneNumber", "userId") */ idLabel?: string; } /** * Parameters for checking pairing */ export interface PairingCheckParams { /** The messaging channel (telegram, discord, whatsapp, etc.) */ channel: PairingChannel; /** User identifier on the channel */ senderId: string; /** Optional metadata about the requester (e.g., name, username) */ metadata?: Record; /** Whether to suppress sending a pairing reply (e.g., for historical messages) */ suppressReply?: boolean; } /** * Get the PairingService from the runtime, or null if not available. */ export declare function getPairingService(runtime: IAgentRuntime): PairingService | null; /** * Check if a sender is allowed based on the pairing policy. * * This function implements the core pairing workflow: * 1. Check if the sender is already in the allowlist -> allowed * 2. If not, create or update a pairing request * 3. Return the pairing code and reply message * * @example * ```typescript * const result = await checkPairingAllowed(runtime, { * channel: "whatsapp", * senderId: "+14155551234", * metadata: { name: "John Doe" }, * }); * * if (!result.allowed) { * if (result.replyMessage) { * await sendMessage(result.replyMessage); * } * return; // Block the message * } * // Process the message... * ``` */ export declare function checkPairingAllowed(runtime: IAgentRuntime, params: PairingCheckParams): Promise; /** * Build the pairing reply message sent to unauthorized users. */ export declare function buildPairingReplyMessage(params: { channel: PairingChannel; senderId: string; code: string; idLabel?: string; }): string; /** * Directly add a sender to the allowlist (bypass pairing). * Useful for CLI commands or admin actions. */ export declare function addToAllowlist(runtime: IAgentRuntime, channel: PairingChannel, senderId: string, metadata?: Record): Promise; /** * Remove a sender from the allowlist. */ export declare function removeFromAllowlist(runtime: IAgentRuntime, channel: PairingChannel, senderId: string): Promise; /** * Check if a sender is in the allowlist. */ export declare function isInAllowlist(runtime: IAgentRuntime, channel: PairingChannel, senderId: string): Promise; /** * Approve a pairing code and add the sender to the allowlist. * Returns the approved sender ID or null if the code was not found. */ export declare function approvePairingCode(runtime: IAgentRuntime, channel: PairingChannel, code: string): Promise;