feat(channels): add Moltchat websocket channel with polling fallback
This commit is contained in:
@@ -2,5 +2,6 @@
|
||||
|
||||
from nanobot.channels.base import BaseChannel
|
||||
from nanobot.channels.manager import ChannelManager
|
||||
from nanobot.channels.moltchat import MoltchatChannel
|
||||
|
||||
__all__ = ["BaseChannel", "ChannelManager"]
|
||||
__all__ = ["BaseChannel", "ChannelManager", "MoltchatChannel"]
|
||||
|
||||
@@ -77,6 +77,18 @@ class ChannelManager:
|
||||
logger.info("Feishu channel enabled")
|
||||
except ImportError as e:
|
||||
logger.warning(f"Feishu channel not available: {e}")
|
||||
|
||||
# Moltchat channel
|
||||
if self.config.channels.moltchat.enabled:
|
||||
try:
|
||||
from nanobot.channels.moltchat import MoltchatChannel
|
||||
|
||||
self.channels["moltchat"] = MoltchatChannel(
|
||||
self.config.channels.moltchat, self.bus
|
||||
)
|
||||
logger.info("Moltchat channel enabled")
|
||||
except ImportError as e:
|
||||
logger.warning(f"Moltchat channel not available: {e}")
|
||||
|
||||
async def start_all(self) -> None:
|
||||
"""Start WhatsApp channel and the outbound dispatcher."""
|
||||
|
||||
1227
nanobot/channels/moltchat.py
Normal file
1227
nanobot/channels/moltchat.py
Normal file
File diff suppressed because it is too large
Load Diff
@@ -366,6 +366,24 @@ def channels_status():
|
||||
"✓" if dc.enabled else "✗",
|
||||
dc.gateway_url
|
||||
)
|
||||
|
||||
# Feishu
|
||||
fs = config.channels.feishu
|
||||
fs_config = f"app_id: {fs.app_id[:10]}..." if fs.app_id else "[dim]not configured[/dim]"
|
||||
table.add_row(
|
||||
"Feishu",
|
||||
"✓" if fs.enabled else "✗",
|
||||
fs_config
|
||||
)
|
||||
|
||||
# Moltchat
|
||||
mc = config.channels.moltchat
|
||||
mc_base = mc.base_url or "[dim]not configured[/dim]"
|
||||
table.add_row(
|
||||
"Moltchat",
|
||||
"✓" if mc.enabled else "✗",
|
||||
mc_base
|
||||
)
|
||||
|
||||
# Telegram
|
||||
tg = config.channels.telegram
|
||||
|
||||
@@ -39,12 +39,49 @@ class DiscordConfig(BaseModel):
|
||||
intents: int = 37377 # GUILDS + GUILD_MESSAGES + DIRECT_MESSAGES + MESSAGE_CONTENT
|
||||
|
||||
|
||||
class MoltchatMentionConfig(BaseModel):
|
||||
"""Moltchat mention behavior configuration."""
|
||||
require_in_groups: bool = False
|
||||
|
||||
|
||||
class MoltchatGroupRule(BaseModel):
|
||||
"""Moltchat per-group mention requirement."""
|
||||
require_mention: bool = False
|
||||
|
||||
|
||||
class MoltchatConfig(BaseModel):
|
||||
"""Moltchat channel configuration."""
|
||||
enabled: bool = False
|
||||
base_url: str = "http://localhost:11000"
|
||||
socket_url: str = ""
|
||||
socket_path: str = "/socket.io"
|
||||
socket_disable_msgpack: bool = False
|
||||
socket_reconnect_delay_ms: int = 1000
|
||||
socket_max_reconnect_delay_ms: int = 10000
|
||||
socket_connect_timeout_ms: int = 10000
|
||||
refresh_interval_ms: int = 30000
|
||||
watch_timeout_ms: int = 25000
|
||||
watch_limit: int = 100
|
||||
retry_delay_ms: int = 500
|
||||
max_retry_attempts: int = 0 # 0 means unlimited retries
|
||||
claw_token: str = ""
|
||||
agent_user_id: str = ""
|
||||
sessions: list[str] = Field(default_factory=list)
|
||||
panels: list[str] = Field(default_factory=list)
|
||||
allow_from: list[str] = Field(default_factory=list)
|
||||
mention: MoltchatMentionConfig = Field(default_factory=MoltchatMentionConfig)
|
||||
groups: dict[str, MoltchatGroupRule] = Field(default_factory=dict)
|
||||
reply_delay_mode: str = "non-mention" # off | non-mention
|
||||
reply_delay_ms: int = 120000
|
||||
|
||||
|
||||
class ChannelsConfig(BaseModel):
|
||||
"""Configuration for chat channels."""
|
||||
whatsapp: WhatsAppConfig = Field(default_factory=WhatsAppConfig)
|
||||
telegram: TelegramConfig = Field(default_factory=TelegramConfig)
|
||||
discord: DiscordConfig = Field(default_factory=DiscordConfig)
|
||||
feishu: FeishuConfig = Field(default_factory=FeishuConfig)
|
||||
moltchat: MoltchatConfig = Field(default_factory=MoltchatConfig)
|
||||
|
||||
|
||||
class AgentDefaults(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user