/** * Channel Base - Base class and interfaces for channel adapters * * Channel adapters handle communication with specific messaging platforms * (Telegram, Discord, Slack, etc.) */ import type { ChannelScope, InboundMessage, OutboundMessage, SenderInfo } from "../types/index.js"; /** Channel adapter interface */ export interface ChannelAdapter { /** Channel type identifier */ readonly channelType: string; /** Initialize the adapter */ initialize(): Promise; /** Shutdown the adapter */ shutdown(): Promise; /** Send a message to the channel */ send(message: OutboundMessage): Promise; /** Get channel profile/info */ getProfile(): Promise; /** Check if adapter is connected */ isConnected(): boolean; /** Set message handler */ onMessage(handler: (message: InboundMessage) => void): void; /** Set error handler */ onError(handler: (error: Error) => void): void; } /** Channel monitor interface (for webhook-based channels) */ export interface ChannelMonitor { /** Start monitoring */ start(): Promise; /** Stop monitoring */ stop(): Promise; /** Get webhook URL (if applicable) */ getWebhookUrl?(): string; /** Handle incoming webhook payload */ handleWebhook?(payload: unknown): Promise; } /** Channel configuration */ export interface ChannelConfig { /** Channel type */ type: string; /** Channel name */ name: string; /** Enabled */ enabled: boolean; /** Channel-specific configuration */ config: Record; /** Access control */ access: { dmPolicy: "pairing" | "allowlist" | "open"; dmAllowlist?: string[]; groupPolicy: "mention" | "allowlist" | "open"; groupAllowlist?: string[]; }; } /** Channel profile */ export interface ChannelProfile { /** Channel type */ type: string; /** Bot/app ID */ id: string; /** Bot/app name */ name: string; /** Username/handle */ username?: string; /** Avatar URL */ avatar?: string; /** Connected status */ connected: boolean; /** Capabilities */ capabilities: ChannelCapabilities; } /** Channel capabilities */ export interface ChannelCapabilities { /** Supports text messages */ text: boolean; /** Supports images */ images: boolean; /** Supports files */ files: boolean; /** Supports reactions */ reactions: boolean; /** Supports threads */ threads: boolean; /** Supports editing messages */ editMessages: boolean; /** Supports deleting messages */ deleteMessages: boolean; /** Supports typing indicators */ typing: boolean; /** Supports cards/buttons */ cards: boolean; /** Supports voice/audio */ voice: boolean; /** Maximum message length */ maxMessageLength: number; /** Maximum file size */ maxFileSize: number; } /** Channel scope types */ export type { ChannelScope }; /** Base channel adapter implementation */ export declare abstract class BaseChannelAdapter implements ChannelAdapter { abstract readonly channelType: string; protected config: ChannelConfig; protected connected: boolean; protected messageHandler?: (message: InboundMessage) => void; protected errorHandler?: (error: Error) => void; constructor(config: ChannelConfig); abstract initialize(): Promise; abstract shutdown(): Promise; abstract send(message: OutboundMessage): Promise; abstract getProfile(): Promise; isConnected(): boolean; onMessage(handler: (message: InboundMessage) => void): void; onError(handler: (error: Error) => void): void; /** * Build session key from channel and identifier */ protected buildSessionKey(agentId: string, scope: ChannelScope, identifier: string): string; /** * Create inbound message */ protected createInboundMessage(params: { id: string; agentId: string; scope: ChannelScope; identifier: string; sender: SenderInfo; content: { type: "text"; text: string; } | { type: "image"; url: string; } | { type: "file"; url: string; name: string; } | { type: "command"; command: string; args: string[]; }; replyTo?: string; threadId?: string; }): InboundMessage; /** * Emit message to handler */ protected emitMessage(message: InboundMessage): void; /** * Emit error to handler */ protected emitError(error: Error): void; /** * Chunk text for platforms with message length limits */ protected chunkText(text: string, maxLength: number): string[]; } /** Channel registry */ export declare class ChannelRegistry { private adapters; /** Register a channel adapter */ register(type: string, adapter: new (config: ChannelConfig) => ChannelAdapter): void; /** Create adapter instance */ create(type: string, config: ChannelConfig): ChannelAdapter; /** Check if channel type is registered */ has(type: string): boolean; /** Get all registered channel types */ getTypes(): string[]; } /** Global channel registry instance */ export declare const globalChannelRegistry: ChannelRegistry; //# sourceMappingURL=base.d.ts.map