Interface IChannelAdapter

Core adapter interface for external messaging channels.

Implementors wrap a platform SDK (e.g., grammY for Telegram, discord.js for Discord) and normalize all interactions to this common contract.

Example

class TelegramAdapter implements IChannelAdapter {
readonly platform = 'telegram';
readonly displayName = 'Telegram';
readonly capabilities = ['text', 'images', 'inline_keyboard', 'typing_indicator'];

async initialize(auth: ChannelAuthConfig): Promise<void> {
this.bot = new Bot(auth.credential);
await this.bot.start();
}

async sendMessage(conversationId, content): Promise<ChannelSendResult> {
const textBlock = content.blocks.find(b => b.type === 'text');
const msg = await this.bot.api.sendMessage(conversationId, textBlock.text);
return { messageId: String(msg.message_id) };
}
// ...
}
interface IChannelAdapter {
    platform: ChannelPlatform;
    displayName: string;
    capabilities: readonly ChannelCapability[];
    initialize(auth): Promise<void>;
    shutdown(): Promise<void>;
    getConnectionInfo(): ChannelConnectionInfo;
    sendMessage(conversationId, content): Promise<ChannelSendResult>;
    sendTypingIndicator(conversationId, isTyping): Promise<void>;
    on(handler, eventTypes?): (() => void);
    editMessage?(conversationId, messageId, content): Promise<void>;
    deleteMessage?(conversationId, messageId): Promise<void>;
    addReaction?(conversationId, messageId, emoji): Promise<void>;
    getConversationInfo?(conversationId): Promise<{
        name?: string;
        memberCount?: number;
        isGroup: boolean;
        metadata?: Record<string, unknown>;
    }>;
}

Implemented by

Methods

  • Initialize the adapter with authentication credentials. Called once when the extension is activated. Must be idempotent — calling initialize on an already-initialized adapter should reconnect.

    Parameters

    Returns Promise<void>

  • Gracefully shut down the adapter, closing connections and releasing resources. Called during extension deactivation or application shutdown.

    Returns Promise<void>

  • Send a typing indicator to a conversation. Not all platforms support this — check capabilities for 'typing_indicator'.

    Parameters

    • conversationId: string
    • isTyping: boolean

    Returns Promise<void>

  • Register a handler for channel events. Multiple handlers can be registered. Use eventTypes to filter which events to receive.

    Parameters

    Returns (() => void)

    Unsubscribe function.

      • (): void
      • Returns void

  • Edit a previously sent message. Only available if adapter declares the 'editing' capability.

    Parameters

    Returns Promise<void>

  • Delete a previously sent message. Only available if adapter declares the 'deletion' capability.

    Parameters

    • conversationId: string
    • messageId: string

    Returns Promise<void>

  • Add a reaction to a message. Only available if adapter declares the 'reactions' capability.

    Parameters

    • conversationId: string
    • messageId: string
    • emoji: string

    Returns Promise<void>

  • Get conversation metadata (name, members, etc.). Useful for group chats.

    Parameters

    • conversationId: string

    Returns Promise<{
        name?: string;
        memberCount?: number;
        isGroup: boolean;
        metadata?: Record<string, unknown>;
    }>

Properties

platform: ChannelPlatform

Platform this adapter serves.

displayName: string

Human-readable display name (e.g., "WhatsApp Business").

capabilities: readonly ChannelCapability[]

Declared capabilities of this adapter.