ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / image (pull_request) Waiting for needed jobs
ci / lint (pull_request) Successful in 11m8s
ci / test (pull_request) Successful in 13m45s
ci / build (pull_request) In progress
Alert mails and chat messages named regions by id. They now show the region's name and mails link the monitor in the console. Visitors of a status page accept the platform's terms and the page's privacy policy, where set, before they can subscribe to it; the status page server and the API both check it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
67 lines
2.4 KiB
Go
67 lines
2.4 KiB
Go
package agentapi
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
)
|
|
|
|
// Visitors of a status page subscribe to its incidents by email. The status
|
|
// page server passes their requests on; the API checks its limits, mails
|
|
// the confirmation and later the incidents.
|
|
|
|
// SubscribeRequest asks for an email subscription to the page at Host, or
|
|
// Slug if Host is empty.
|
|
type SubscribeRequest struct {
|
|
Host string `json:"host,omitempty"`
|
|
Slug string `json:"slug,omitempty"`
|
|
Email string `json:"email"`
|
|
// IP is the visitor's address, for rate limits.
|
|
IP string `json:"ip"`
|
|
// Locale is the language of the mails, as the visitor's browser asks.
|
|
Locale string `json:"locale,omitempty"`
|
|
// PageURL is where the visitor saw the page, ending in "/". The API
|
|
// uses it for the links in mails only where it does not know the
|
|
// page's address itself.
|
|
PageURL string `json:"page_url,omitempty"`
|
|
// Accepted says the visitor accepted the terms and privacy policy the
|
|
// page links in its form, if it links any.
|
|
Accepted bool `json:"accepted"`
|
|
}
|
|
|
|
// SubscriptionInfo describes a subscription that was confirmed or ended.
|
|
type SubscriptionInfo struct {
|
|
PageTitle string `json:"page_title"`
|
|
Email string `json:"email"`
|
|
}
|
|
|
|
// ErrInvalidInput means the API refused the request's content, e.g. an
|
|
// email address that is none.
|
|
var ErrInvalidInput = errors.New("agentapi: invalid input")
|
|
|
|
type tokenRequest struct {
|
|
Token string `json:"token"`
|
|
}
|
|
|
|
// Subscribe asks for a subscription and has the confirmation mailed. It
|
|
// succeeds whether or not the address was subscribed already, so it tells
|
|
// nobody who is. ErrRateLimited means a limit was reached, ErrNotFound
|
|
// that the page takes no subscriptions.
|
|
func (c *Client) Subscribe(ctx context.Context, r SubscribeRequest) error {
|
|
return c.do(ctx, http.MethodPost, "/subscriptions", r, nil)
|
|
}
|
|
|
|
// ConfirmSubscription confirms the subscription token was mailed for.
|
|
func (c *Client) ConfirmSubscription(ctx context.Context, token string) (SubscriptionInfo, error) {
|
|
var out SubscriptionInfo
|
|
err := c.do(ctx, http.MethodPost, "/subscriptions/confirm", tokenRequest{token}, &out)
|
|
return out, err
|
|
}
|
|
|
|
// Unsubscribe ends the subscription of an unsubscribe token.
|
|
func (c *Client) Unsubscribe(ctx context.Context, token string) (SubscriptionInfo, error) {
|
|
var out SubscriptionInfo
|
|
err := c.do(ctx, http.MethodPost, "/subscriptions/unsubscribe", tokenRequest{token}, &out)
|
|
return out, err
|
|
}
|