feat: per-topic announce target (move guild+channel from env to topic row)
Operator decision: backend env hard-coding a single guild/channel was
wrong because (a) one Center can host many guilds and (b) one guild
can have many announce channels for different purposes. The
proposing agent now chooses where this topic's lifecycle events go,
passed as create-topic params and stored on the topic row.
Schema migration 002:
- ALTER topics ADD announce_guild_base_url VARCHAR(255) NULL,
announce_channel_id VARCHAR(64) NULL.
- Both nullable; one-of-two is rejected at POST time; both null =
topic creator opted out of broadcasts (announcer skips with log).
handlers/topics.go: createTopicBody adds announce_guild_base_url +
announce_channel_id; validates both-or-neither.
fabric/announce.go: rewritten signature. NewAnnouncer takes only
the system api key. PostTopicAnnouncement + PostLifecycleEvent take
a Target {GuildBaseURL, ChannelID} per call. Zero-value Target -> skip.
orchestrator/ticker.go: new helper topicTarget(topic) extracts the
target from the topic row; all broadcasts route through it.
verdict.go: same per-topic target extraction at completion.
config: removed FabricGuildBaseURL, FabricAnnounceChannelID,
FabricBotBearerToken from the Config struct + env reads.
FabricSystemAPIKey env renamed to DIALECTIC_FABRIC_SYSTEM_API_KEY
to disambiguate from the Fabric backend's own
FABRIC_BACKEND_GUILD_SYSTEM_API_KEY (operator: paste the same value
into both - one says "I am the system caller", the other says "I
accept this caller as system").
FABRIC_BOT_BEARER_TOKEN is gone entirely. The upgraded Guild
ApiKeyGuard accepts x-fabric-system-key alone for announce posts;
no per-user Bearer needed. Pairs with the matching change on
nav/Fabric.Backend.Guild commit 985b06a.
This commit is contained in:
@@ -135,7 +135,7 @@ func (t *Ticker) tickOnce(ctx context.Context) {
|
||||
topicID, res.CancelReason)
|
||||
if err == nil {
|
||||
go t.broadcastLifecycle(topic, "cancelled",
|
||||
fmt.Sprintf("debate cancelled at signup close — %s", res.CancelReason))
|
||||
fmt.Sprintf("debate cancelled at signup close - %s", res.CancelReason))
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -249,12 +249,15 @@ func (t *Ticker) applyOne(ctx context.Context, topicID string,
|
||||
// broadcastLifecycle wraps the announcer's lifecycle-event post with
|
||||
// the standard signup_closed / cancelled / debating / completed
|
||||
// formats. Best-effort; runs in its own goroutine outside any tx.
|
||||
// Target is resolved from the topic's per-topic announce columns;
|
||||
// null on either column → announcer skips with a log (creator opted
|
||||
// out of broadcasts).
|
||||
func (t *Ticker) broadcastLifecycle(topic *models.Topic, kind, summary string) {
|
||||
if topic == nil {
|
||||
return
|
||||
}
|
||||
if err := t.announcer.PostLifecycleEvent(
|
||||
context.Background(), topic.ID, topic.Title, kind, summary,
|
||||
context.Background(), topicTarget(topic), topic.ID, topic.Title, kind, summary,
|
||||
); err != nil {
|
||||
log.Printf("orchestrator: lifecycle broadcast topic=%s kind=%s failed: %v", topic.ID, kind, err)
|
||||
}
|
||||
@@ -265,7 +268,7 @@ func (t *Ticker) broadcastAnnouncement(topic *models.Topic) {
|
||||
return
|
||||
}
|
||||
if err := t.announcer.PostTopicAnnouncement(
|
||||
context.Background(),
|
||||
context.Background(), topicTarget(topic),
|
||||
topic.ID, topic.Title, topic.Summary,
|
||||
topic.SignupOpenAt, topic.SignupCloseAt,
|
||||
topic.DebateStartAt, topic.DebateEndAt,
|
||||
@@ -274,3 +277,16 @@ func (t *Ticker) broadcastAnnouncement(topic *models.Topic) {
|
||||
log.Printf("orchestrator: announce topic=%s failed: %v", topic.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
// topicTarget extracts the per-topic announce target from the topic
|
||||
// row; returns zero-value Target if either column is null (which the
|
||||
// announcer treats as "skip").
|
||||
func topicTarget(topic *models.Topic) fabric.Target {
|
||||
if topic.AnnounceGuildBaseURL == nil || topic.AnnounceChannelID == nil {
|
||||
return fabric.Target{}
|
||||
}
|
||||
return fabric.Target{
|
||||
GuildBaseURL: *topic.AnnounceGuildBaseURL,
|
||||
ChannelID: *topic.AnnounceChannelID,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user