notify

package
v0.1.0-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 22 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	NoticeReminder   = "reminder"
	NoticeEscalation = "escalation"
)

Notice kinds.

View Source
const LinkTTL = 7 * 24 * time.Hour

LinkTTL is how long a decision link works.

Variables

This section is empty.

Functions

func Ago

func Ago(d time.Duration) string

Ago is a waiting time in words: "45 minutes", "2 hours", "3 days".

func Render

func Render(m *a2a.Message) string

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

func ValidSlackWebhook(url string) bool

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 Email

type Email interface {
	Send(ctx context.Context, to, subject, body string) error
}

Email sends one plain-text email.

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.

func (*Message) Text

func (m *Message) Text() string

Text renders the message as a plain-text email body.

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

func (n *Notifier) Notify(ctx context.Context, nt Notice) error

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).

func (*Notifier) Slack

func (n *Notifier) Slack(ctx context.Context, webhook string, m *Message) error

Slack posts m to a Slack incoming webhook.

func (*Notifier) Test

func (n *Notifier) Test(ctx context.Context, u *directory.User) error

Test sends a test notification to a person's channels.

func (*Notifier) Wait

func (n *Notifier) Wait()

Wait blocks until the notifications in flight are sent.

func (*Notifier) Waiting

func (n *Notifier) Waiting(ctx context.Context, w relay.Waiting)

Waiting notifies the person a task waits on, in the background. Wait waits for the notifications in flight.

type SMTP

type SMTP struct {
	// contains filtered or unexported fields
}

SMTP sends email through an SMTP server.

func ParseSMTP

func ParseSMTP(rawURL, from string) (*SMTP, error)

ParseSMTP configures SMTP from a URL such as smtp://user:pass@smtp.example.com:587 or smtps://user:pass@smtp.example.com:465, sending as from. Credentials are optional.

func (*SMTP) Send

func (s *SMTP) Send(ctx context.Context, to, subject, body string) error

Send implements Email.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL