Files
archie/modules/runs/message.go
T
sam de05bc2cbd feat(runs): show each step's summary and target on the run page
- a finished top-level step records its summary and target in a done marker; stages return them
- a message step's summary is the message, and its target the channel and chat
- the trail no longer lists the engine's markers as entries
- run page: short run ID in the breadcrumb, copyable IDs, version badge, step rows from stages, No output for an empty result
- event detail: No payload for an empty body, and links only the dispatches that started a run
- ui/AGENTS.md lists the components that exist
2026-11-24 00:04:20 +11:00

47 lines
1.6 KiB
Go

package runs
import (
"context"
"errors"
"fmt"
"strings"
)
// Messenger delivers text to one chat on a messaging channel.
type Messenger interface {
Send(ctx context.Context, channel, chatID, text, key string) error
}
// messageSettings send an authored message.
type messageSettings struct {
Channel string `yaml:"channel" json:"channel" jsonschema:"the messaging channel to send through"`
ChatID string `yaml:"chat_id" json:"chat_id" jsonschema:"the channel's identifier for the chat"`
Text string `yaml:"text" json:"text" jsonschema:"the message; references to earlier steps and inputs are filled in"`
}
func (s messageSettings) valid() error {
if strings.TrimSpace(s.Channel) == "" || strings.TrimSpace(s.ChatID) == "" || strings.TrimSpace(s.Text) == "" {
return errors.New("channel, chat_id and text are required")
}
return nil
}
func (s messageSettings) describe() string {
return fmt.Sprintf("Sends a message to a chat on %s", s.Channel)
}
// runMessage sends the message. A dry run records it without sending.
func runMessage(d Deps, rc *Context, _ *progress, _ string, s messageSettings) (StepResult, error) {
res := StepResult{Summary: s.Text, Target: &Target{Kind: s.Channel, ID: s.ChatID}}
if rc.Dry() {
_, err := rc.Step("send-skipped", func(context.Context, string) (string, error) {
return fmt.Sprintf("send to %s chat %s: %s", s.Channel, s.ChatID, s.Text), nil
})
return res, err
}
_, err := rc.Step("send", func(ctx context.Context, key string) (bool, error) {
return true, d.Messenger.Send(ctx, s.Channel, s.ChatID, s.Text, key)
})
return res, err
}