PlatformAdapter Protocol 패턴
PlatformAdapter Protocol 패턴
한 줄 정의
typing.Protocol로 플랫폼 인터페이스를 정의하여 Telegram/Discord/Messenger 등을 교체 가능하게 설계.
구조
# core/protocols.py
class PlatformAdapter(Protocol):
async def send_message(self, chat_id: str, text: str) -> None: ...
async def send_file(self, chat_id: str, file_path: str) -> None: ...
async def get_updates(self) -> list[Update]: ...
# 구현체
class TelegramAdapter:
async def send_message(self, chat_id: str, text: str) -> None:
await self.bot.send_message(chat_id, text)
class DiscordAdapter:
async def send_message(self, chat_id: str, text: str) -> None:
channel = self.client.get_channel(int(chat_id))
await channel.send(text)
훅 기반 IPC 패턴
Claude Code hook → /tmp/claude-telegram-hooks/{session_id}.json 파일 write
Bot process → 파일 polling → Telegram 전송
프로세스 간 통신을 파일 시스템으로 처리 → 단순하고 디버깅 쉬움.
적용 맥락
멀티플랫폼 봇/알림 시스템. 초기에 Telegram만 지원해도 Protocol로 설계하면 Discord 추가 시 구현체만 추가하면 됨.
Relationships
derived_from ARIA (Claude Telegram Bridge)
related_to LLM-System 경계 설계 (Action 제안 vs Outcome 확정)