Documentation
¶
Overview ¶
Package notify tells people that a task waits on them: by email and in Slack, each with a one-time link that opens the question and answers it without logging in.
The relay calls Waiting whenever a task stops on INPUT_REQUIRED or AUTH_REQUIRED. The task waits on the address it names as awaiting, or else on its sender (an agent's question goes back to whoever asked it). Only people are notified: an agent that sent a task hears about the question from its own A2A client.
Index ¶
- Constants
- func Ago(d time.Duration) string
- func Render(m *a2a.Message) string
- func ValidSlackWebhook(url string) bool
- type Channel
- type Email
- type Message
- type Notice
- type Notifier
- func (n *Notifier) Notify(ctx context.Context, nt Notice) error
- func (n *Notifier) Slack(ctx context.Context, webhook string, m *Message) error
- func (n *Notifier) Test(ctx context.Context, u *directory.User) error
- func (n *Notifier) Wait()
- func (n *Notifier) Waiting(ctx context.Context, w relay.Waiting)
- type SMTP
Constants ¶
const ( NoticeReminder = "reminder" NoticeEscalation = "escalation" )
Notice kinds.
const LinkTTL = 7 * 24 * time.Hour
LinkTTL is how long a decision link works.
Variables ¶
This section is empty.
Functions ¶
func Render ¶
Render renders a message for people: its text, then each data part as "key: value" lines, so nobody has to read JSON. Parts meant for machines (an input schema, a credential challenge, whose text part already carries the link) are left out.
func ValidSlackWebhook ¶
ValidSlackWebhook reports whether url is a Slack incoming webhook. Only those are accepted, so a setting can't make the server post to arbitrary hosts.
Types ¶
type Channel ¶
type Channel interface {
// Notice sends nt to u, if u has the channel on; sent says whether it did.
Notice(ctx context.Context, u *directory.User, nt Notice) (sent bool, err error)
// Test sends a test message to u, if u has the channel on.
Test(ctx context.Context, u *directory.User) (sent bool, err error)
}
Channel is a notification channel of its own, such as a person's Telegram bot. It decides for itself whether a person has it on, and gets no decision link: a channel that answers does so through its own, narrower path.
type Message ¶
type Message struct {
Subject string
// Intro comes first: why this arrives again (a reminder) or to someone else (an escalation).
Intro string
// Asker is the address asking, Question what it asks (text, then data as key: value lines).
Asker, Question string
// Of is who is asked, when it isn't the reader (an escalation); empty means "you".
Of string
// Link answers the task once, without logging in. Inbox is the person's inbox.
Link, Inbox string
}
Message is one notification, before it is rendered for a channel.
type Notice ¶
type Notice struct {
// To is the person notified; Asker the address asking.
To, Asker string
TaskID string
// State is the task's state (TASK_STATE_AUTH_REQUIRED asks to connect an account).
State string
Question *a2a.Message
// Kind is "" for the first notice, NoticeReminder or NoticeEscalation.
Kind string
// Waited is how long the task has waited, for reminders and escalations.
Waited time.Duration
// For is who the task waits on, when To is someone else (an escalation).
For string
}
Notice is one notification about a task waiting on someone.
type Notifier ¶
type Notifier struct {
Directory *directory.Directory
// PublicURL is the server's base URL, for links.
PublicURL string
Email Email
// Channels are the other channels (Telegram).
Channels []Channel
// HTTP posts to Slack (default: a client with a 10s timeout).
HTTP *http.Client
Logger *slog.Logger
// contains filtered or unexported fields
}
Notifier sends notifications. Its zero channels are off: without Email it sends no email, and Slack is per person (NotificationSettings.SlackWebhook).
func (*Notifier) Notify ¶
Notify sends a notice to its person's channels, with a one-time answer link. Agents and people with no channel on get nothing (the task waits in the inbox).
type SMTP ¶
type SMTP struct {
// contains filtered or unexported fields
}
SMTP sends email through an SMTP server.