AutoReplyRule complete integration: - bootstrap.go: instantiate AutoReplyRuleService + AutoReplyListener, register listener on channel dispatcher for message.created events - router.go: register /captain/auto_reply_rules CRUD + /evaluate routes - auto_reply_rule_handler.go: fix c.Param(id) → c.Param(account_id), override evalCtx.AccountID from path param - auto_reply_rule_service.go: add JSON tags to AutoReplyEvaluationContext for correct request body binding - auto_reply_listener.go (new): EventListener that triggers on incoming messages, evaluates active rules, composes reply (static/LLM/mixed), respects DelaySeconds and OneTimeOnly flags, sends via MessageService - migration 000048: create captain_auto_reply_rules table AgentBot + Captain integration: - agent_bot_listener.go: add captainConvSvc field + SetCaptainConversationService method. In HandleEvent loop, check bot.BotType == captain and route to CaptainConversationService.BuildConversationResponseByAccount instead of webhook push. Extract assistant_id from bot.Config JSONB, extract conversation_id from event data. - bootstrap.go: inject captainConversationService into agentBotListener CaptainConversationService improvement: - generateConversationResponse: use assistant config for system prompt, model name, and temperature instead of hardcoded values Verified: - go build ./... passes - go vet passes on all internal packages - go test passes (service + repository + llm, SQLite mode) - Auto-reply CRUD: create/get/update/delete all work - Auto-reply evaluate: correctly matches hello → should_reply=true, correctly rejects non-matching message - Existing routes unaffected (assistants, RAG, conversation respond) - Migration 000048 creates captain_auto_reply_rules table successfully
31 lines
1.7 KiB
SQL
31 lines
1.7 KiB
SQL
-- 000048_add_captain_auto_reply_rules.up.sql
|
|
-- Captain AI — Auto-Reply Rules table
|
|
-- Reference: M12 PRD §Captain AI — Auto-Reply Rules
|
|
-- Stores rules for automated replies when incoming messages match conditions.
|
|
|
|
CREATE TABLE IF NOT EXISTS captain_auto_reply_rules (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
account_id BIGINT NOT NULL,
|
|
assistant_id BIGINT NOT NULL,
|
|
inbox_id BIGINT NULL,
|
|
name VARCHAR(255) NOT NULL,
|
|
description TEXT DEFAULT '',
|
|
status VARCHAR(50) NOT NULL DEFAULT 'draft',
|
|
mode VARCHAR(50) NOT NULL DEFAULT 'static',
|
|
priority INTEGER NOT NULL DEFAULT 0,
|
|
conditions JSONB NOT NULL DEFAULT '[]'::jsonb,
|
|
response_text TEXT DEFAULT '',
|
|
llm_prompt_override TEXT DEFAULT '',
|
|
delay_seconds INTEGER NOT NULL DEFAULT 0,
|
|
one_time_only BOOLEAN NOT NULL DEFAULT TRUE,
|
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
deleted_at TIMESTAMP WITH TIME ZONE NULL
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_captain_auto_reply_rules_account_id ON captain_auto_reply_rules(account_id);
|
|
CREATE INDEX IF NOT EXISTS idx_captain_auto_reply_rules_assistant_id ON captain_auto_reply_rules(assistant_id);
|
|
CREATE INDEX IF NOT EXISTS idx_captain_auto_reply_rules_inbox_id ON captain_auto_reply_rules(inbox_id);
|
|
CREATE INDEX IF NOT EXISTS idx_captain_auto_reply_rules_status ON captain_auto_reply_rules(status);
|
|
CREATE INDEX IF NOT EXISTS idx_captain_auto_reply_rules_deleted_at ON captain_auto_reply_rules(deleted_at);
|