Files
archie/internal/channels/channel.go
T
sam f4787a819d feat: email channel + Channel interface with config schema validation
Email channel (internal/channels/email):
- SMTP server receiving inbound emails on configurable port
- Multipart body extraction (text/plain from MIME)
- SMTP relay for outbound replies with STARTTLS + AUTH
- 8 tests, race-clean

Channel interface (internal/channels/channel.go):
- ConfigSchema() — JSON Schema for channel configuration
- ValidateConfig() — validates channel-specific config at startup
- All three channels (Telegram, Email, Webhook) implement it
- Compile-time guard: var _ channels.Channel = (*Gateway)(nil)

Config: ChatConfig.Email added (listen_addr, relay_addr).
Daemon: email gateway wired into main.go behind chat.email block.

40 packages pass with -race.
2026-07-26 13:36:56 +10:00

42 lines
1.7 KiB
Go

// Package channels defines the interface every chat channel must satisfy
// to integrate with archie-core's gateway router. Channels own their
// persistent connection lifecycle; the gateway handles message dispatch.
//
// Each channel declares its required configuration via ConfigSchema so
// the daemon can validate wiring at startup — catching missing tokens,
// invalid ports, or misconfigured credentials before accepting connections.
package channels
import (
"encoding/json"
"github.com/samcharles93/archie-core/internal/gateway"
)
// Channel is the contract every chat platform must satisfy. It extends
// gateway.Gateway with configuration introspection so the daemon can
// validate and introspect channels at startup without knowing about
// specific implementations.
type Channel interface {
gateway.Gateway
// ConfigSchema returns the JSON Schema for this channel's required
// configuration. The daemon uses this at startup to validate that
// the user's config file provides all required fields and to surface
// clear errors when a channel is misconfigured.
//
// The schema must include:
// - type: object
// - required: [...] (fields that must be present)
// - properties: {...} (field definitions with types and descriptions)
ConfigSchema() json.RawMessage
// ValidateConfig checks that the provided configuration is valid for
// this channel. Returns nil when the config is acceptable, or a
// descriptive error when required fields are missing or invalid.
//
// The cfg argument is the channel-specific portion of the daemon
// config (e.g. the [chat.telegram] block, not the full Config).
ValidateConfig(cfg map[string]any) error
}