feat(channels): add unified channel framework with Telegram and Discord support

Introduce the new channel unification architecture:
- Core framework: base channel class, bus, consumer, channel manager,
  middleware, mixins, capabilities, formatter, retry, plugin system
- Telegram channel implementation with bot token validation
- Discord channel implementation with bot token validation
- Refactored iMessage to use new base channel architecture
- Updated CLI: /channel commands, serve mode, channel setup wizard
- Updated onboard wizard to support multi-channel selection
- Config settings for all channel types
- Stream events: media attachment support, done event content field
- Comprehensive test coverage for channels, bus, and manager
This commit is contained in:
MuXinCG
2026-02-16 01:12:02 +08:00
parent 3da590acaf
commit 616a90ef1c
47 changed files with 9450 additions and 1209 deletions
+52
View File
@@ -0,0 +1,52 @@
"""Event types for the message bus."""
from dataclasses import dataclass, field
from datetime import datetime
from typing import Any
@dataclass
class InboundMessage:
"""Message received from a chat channel.
Carries enough context for the bus to route and for the agent
to build a session: which channel, who sent it, which chat.
"""
channel: str
sender_id: str
chat_id: str
content: str
timestamp: datetime = field(default_factory=datetime.now)
message_id: str = ""
media: list[str] = field(default_factory=list)
metadata: dict[str, Any] = field(default_factory=dict)
is_group: bool = False
was_mentioned: bool = True
@property
def sender(self) -> str:
"""Alias for ``sender_id`` (compatibility with IncomingMessage)."""
return self.sender_id
@property
def session_key(self) -> str:
"""Unique key for session identification: ``channel:chat_id``."""
return f"{self.channel}:{self.chat_id}"
@dataclass
class OutboundMessage:
"""Message to send to a chat channel."""
channel: str
chat_id: str
content: str
reply_to: str | None = None
media: list[str] = field(default_factory=list)
metadata: dict[str, Any] = field(default_factory=dict)
@property
def recipient(self) -> str:
"""Alias for ``chat_id`` (compatibility with OutgoingMessage)."""
return self.chat_id