Files
goclaw/migrations/000012_channel_pending_messages.up.sql
viettranx 5f7ca84876 feat(channels): persist pending messages to PostgreSQL with Web UI
- Add channel_pending_messages table with UUID v7 PK, sender_id tracking
- Implement PendingMessageStore interface with batched flush (3s/20 msgs)
- Add LLM-based auto-compaction when entries exceed threshold (50)
- Wire persistent history into all channel factories (Telegram, Discord, Slack, Feishu, Zalo)
- Extract channel type constants (TypeTelegram, TypeDiscord, etc.) to eliminate magic strings
- Add HTTP API endpoints for pending messages management (list, view, compact, clear)
- Add Pending Messages dashboard page with group titles resolved from session metadata
- Track sender_id across entire pipeline (migration → store → history → handlers)
2026-03-09 12:39:43 +07:00

20 lines
891 B
SQL

-- Channel pending messages: persists group chat messages when bot is NOT mentioned.
-- Used to provide conversational context when bot IS mentioned.
-- Supports LLM-based compaction (is_summary rows) and 7-day TTL cleanup.
CREATE TABLE channel_pending_messages (
id UUID PRIMARY KEY DEFAULT uuid_generate_v7(),
channel_name VARCHAR(100) NOT NULL,
history_key VARCHAR(200) NOT NULL,
sender VARCHAR(255) NOT NULL,
sender_id VARCHAR(255) NOT NULL DEFAULT '',
body TEXT NOT NULL,
platform_msg_id VARCHAR(100) NOT NULL DEFAULT '',
is_summary BOOLEAN NOT NULL DEFAULT false,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX idx_channel_pending_messages_lookup
ON channel_pending_messages (channel_name, history_key, created_at);