Skip to content

Channel Adapter Abstraction #63

Closed

Description

@vybe

Summary

Extract a ChannelAdapter interface from the existing Slack integration (src/backend/routers/slack.py) to create a pluggable channel architecture. All external messaging channels (Slack now, Telegram/WhatsApp/Discord later) should implement this common interface.

Context

Trinity already has a working Slack adapter (~590 lines) with OAuth, DM routing, email verification, and session persistence. However, it's a monolithic router with channel-specific logic mixed into business logic. Before adding more channels, we need a clean abstraction layer.

Requirements

Channel Adapter Interface

  • Define ChannelAdapter base class with standard lifecycle methods:
    • authenticate(request) — Verify incoming webhook/event signatures
    • parse_message(raw_event) → NormalizedMessage — Extract sender, text, thread, attachments
    • send_response(channel_id, message) → None — Deliver formatted response
    • resolve_user(channel_user) → TrinityIdentity — Map channel user to Trinity user/email
    • get_session(channel_id, thread_id) → Session — Map channel thread to chat session
  • Define NormalizedMessage schema: sender, text, channel, thread_id, timestamp, attachments, metadata

Message Router

  • Central router that receives from any adapter, resolves the target agent, injects context, dispatches to the agent, and routes the response back through the adapter
  • Decouple agent execution from channel-specific code
  • Channel config per agent in manifest/database: which channel, which thread/channel ID, enabled/disabled

Session Mapping

  • Unified session model across channels (extend existing public_chat_sessions or create channel_sessions)
  • One agent ↔ one persistent thread per client per channel
  • Session state: active, paused, closed

What Exists Today

  • src/backend/routers/slack.py — Reference implementation to decompose
  • src/backend/db/public_chat.py — Session persistence pattern
  • src/backend/routers/chat.py — Core chat execution pipeline

Acceptance Criteria

  • ChannelAdapter base class defined with documented interface
  • SlackAdapter implements the interface (refactored from current slack.py)
  • Central message router dispatches to agents independent of channel
  • NormalizedMessage schema covers Slack's current needs without Slack-specific fields
  • Per-agent channel configuration (which channels enabled, channel-specific settings)
  • Existing Slack functionality preserved — no regressions
  • Adding a new channel requires only implementing ChannelAdapter + config

Non-Goals

  • No new channel implementations in this issue (Telegram, WhatsApp, etc.)
  • No UI for channel management (API-only for now)

Metadata

Metadata

Assignees

Labels

complexity-mediumpriority-p1type-feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions