Skip to content

Add channel management system with Telegram adapter#1

Closed
HaraldBregu wants to merge 12 commits into
mainfrom
claude/refine-local-plan-bjqSs
Closed

Add channel management system with Telegram adapter#1
HaraldBregu wants to merge 12 commits into
mainfrom
claude/refine-local-plan-bjqSs

Conversation

@HaraldBregu

Copy link
Copy Markdown
Owner

Summary

This PR introduces a complete channel management system that enables the application to handle multiple messaging adapters (starting with Telegram). It includes a new ChannelManager that owns the lifecycle of channel adapters, integrates channels into the store layer, and refactors the Telegram adapter to work within this new architecture.

Key Changes

  • New Channel Manager (src/main/channels/manager.ts): Centralized lifecycle management for all messaging channel adapters. Handles spawning, stopping, and updating adapters based on store state. Dispatches inbound messages to the default Assistant and routes replies back through the originating adapter.

  • Channel Adapter Interface (src/main/channels/adapter.ts): Defines the contract for channel implementations with start(), stop(), and dispatch capabilities.

  • Refactored Telegram Adapter:

    • Now implements the ChannelAdapter interface
    • Accepts a dispatch callback to decouple from the assistant module
    • Integrates with the logger service for consistent error handling
    • Processes inbound messages and sends assistant replies back to users
    • Includes proper error handling and logging throughout
  • Store Layer Integration:

    • Added Channel type support to StoreSchema
    • New channels.ts module with normalization and validation utilities
    • StoreService methods: getChannels(), getChannelById(), addChannel(), deleteChannel()
    • Automatic normalization of stored channels on initialization
  • Input Validation (ChannelValidators in src/main/shared/validators.ts):

    • Validates channel IDs, tokens, and allowlist entries
    • Enforces length limits and character restrictions
    • Ensures enabled channels have non-empty tokens

Implementation Details

  • The ChannelManager decouples adapters from the assistant module through a ChannelDispatch callback, allowing adapters to remain independent of business logic
  • Channel configuration is persisted in the store and automatically loaded on startup
  • The manager gracefully handles adapter startup/shutdown failures with appropriate logging
  • Telegram adapter now properly handles message dispatch, chunking for the 4096 character limit, and authorization checks

https://claude.ai/code/session_01R6i53ytUebsbZFZhF4ZuoB

HaraldBregu added 12 commits May 3, 2026 14:09
Persist messaging-channel configs (id/type/token/allowFrom/enabled) in
electron-store, mirroring the existing Provider lifecycle. Introduce a
ChannelAdapter interface with a dispatch-callback contract so adapters
never import the assistant module. Wire the existing TelegramAdapter to
route inbound text to AssistantRegistry.get(DEFAULT_ASSISTANT_ID).send and
reply via grammy. Register a ChannelManager service that owns adapter
lifecycles, started after IPC bootstrap so config edits hot-apply via
new app:get-channels / app:add-channel / app:delete-channel IPC.

https://claude.ai/code/session_01R6i53ytUebsbZFZhF4ZuoB
@HaraldBregu HaraldBregu closed this May 3, 2026
@HaraldBregu
HaraldBregu deleted the claude/refine-local-plan-bjqSs branch May 3, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant