//#region extensions/crypto/src/services/channel-sender.d.ts /** * Channel-Agnostic Message Sender * * Abstracts OpenClaw's per-channel sendMessage* functions into a single * interface so the rest of the crypto extension never hard-codes a channel. * * Dynamically discovers available channels from `api.runtime.channel` at * runtime, so new channels added to OpenClaw (e.g. Matrix, Teams, Nostr) * are picked up automatically. * * Usage: * const sender = createChannelSender(api); * await sender.send('telegram', chatId, 'Hello!'); * * Or with auto-detection from session key / hook context: * await sender.sendToSession(sessionKey, chatId, 'Hello!'); */ /** * Channel identifier. This is a string (not a union) so new channels added * upstream are supported without code changes here. */ type ChannelId = string; interface SendOptions { /** Account ID for multi-account setups. Defaults to 'default'. */ accountId?: string; } interface ChannelSender { /** * Send a message to a specific channel + recipient. * Returns true on success, false if the channel's send function isn't available. */ send(channel: ChannelId, recipientId: string, text: string, opts?: SendOptions): Promise; /** * Auto-detect channel from a session key (e.g. "telegram-123456", "discord:789") * and send to the extracted recipient. */ sendToSession(sessionKey: string, text: string, opts?: SendOptions): Promise; /** * Check if a channel's send function is available on the current runtime. */ isAvailable(channel: ChannelId): boolean; /** * List all channels that have a send function available on the current runtime. */ availableChannels(): string[]; } /** * Provide runtime channel names so parseSessionKey can recognize dynamically * registered channels. Called once when createChannelSender initializes. */ declare function setRuntimeChannelNames(names: Set): void; /** * Parse a session key to extract the channel and user/chat ID. * * OpenClaw session keys follow these patterns: * telegram-123456789 (Telegram user ID) * telegram:123456789 (alternate separator) * discord-987654321 (Discord user/channel ID) * discord:987654321 * slack-U1234567 (Slack user ID) * signal-+15551234567 (Signal phone number) * whatsapp-15551234567 (WhatsApp) * imessage-user@icloud.com (iMessage) * matrix-@user:server.com (Matrix) * line-U1234567 (LINE user ID) * * Also handles compound keys like "telegram-123456789-agent-default". */ declare function parseSessionKey(sessionKey: string): { channel: ChannelId; userId: string; } | null; /** * Extract a user/sender ID from hook context — channel-agnostic. * * Tries multiple sources in priority order: * 1. ctx.requesterSenderId (OpenClaw tool context) * 2. ctx.senderId * 3. event.from / event.metadata.senderId * 4. parseSessionKey(ctx.sessionKey).userId */ declare function extractSenderId(event: any, ctx: any): string | null; /** * Extract the channel ID from hook context — channel-agnostic. * * Tries: * 1. ctx.channelId (directly from OpenClaw hook context) * 2. ctx.messageChannel * 3. parseSessionKey(ctx.sessionKey).channel */ declare function extractChannelId(ctx: any): ChannelId | null; /** * Create a channel-agnostic sender backed by the plugin API's runtime. * * Dynamically discovers channels from `api.runtime.channel` so new upstream * channels are automatically supported. */ declare function createChannelSender(api: any): ChannelSender; //#endregion export { ChannelId, ChannelSender, SendOptions, createChannelSender, extractChannelId, extractSenderId, parseSessionKey, setRuntimeChannelNames }; //# sourceMappingURL=channel-sender.d.mts.map