notify

package
v3.1.0-dev.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package notify implements the switchboard /v1/messages HTTP client used by monitor.notify to post, replace, and thread-append monitoring digests.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSendFullText is returned by Replace when text exceeds MaxChunkRunes;
	// switchboard PUT replaces a single message and cannot split across chunks,
	// so the caller must fall back to posting a fresh message.
	ErrSendFullText = errors.New("notify: message exceeds single-message edit limit")

	// ErrEditUnsupported is returned by Replace when the gateway responds 501
	// Not Implemented (platform does not support message editing).
	ErrEditUnsupported = errors.New("notify: message edit unsupported by gateway (501)")

	// ErrNoSuchMessage is returned by Replace when the gateway responds 404 Not
	// Found (the referenced message was deleted).
	ErrNoSuchMessage = errors.New("notify: referenced message not found (404)")

	// ErrDenied is returned when the gateway rejects the request with 401 or 403.
	ErrDenied = errors.New("notify: request denied by gateway")
)

Sentinel errors returned by Client methods so callers (such as monitor.notify replace mode) can branch on upstream capabilities without inspecting raw status codes.

Functions

This section is empty.

Types

type Client

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

Client is a switchboard /v1/messages client.

func New

func New(cfg Config) (*Client, error)

New validates cfg and returns a ready Client.

func (*Client) Append

func (c *Client) Append(ctx context.Context, parent Ref, text string) (Ref, error)

Append posts text into an existing message's thread ("<channel>:<id>") via POST /v1/messages. Multi-chunk messages are posted sequentially to the same thread conversation key.

func (*Client) Post

func (c *Client) Post(ctx context.Context, text, sessionID string) (Ref, error)

Post sends text to the configured channel via POST /v1/messages. If text exceeds MaxChunkRunes, the first chunk is posted to c.channel and remaining chunks are appended to the returned message's thread (or c.channel if the gateway returned no message ID).

When sessionID is non-empty, Post sets the X-Agent-Session header on the initial POST so switchboard can bind replies in the thread back to that session.

func (*Client) Replace

func (c *Client) Replace(ctx context.Context, ref Ref, text string) (Ref, error)

Replace edits an existing message in place via PUT /v1/messages/{channel}/{id}.

Returns ErrSendFullText without making an HTTP call when text exceeds MaxChunkRunes, ErrEditUnsupported on HTTP 501, and ErrNoSuchMessage on HTTP 404.

type Config

type Config struct {
	// Endpoint is the base URL of the switchboard gateway (e.g.
	// "http://switchboard.Namespace.svc:8080").
	Endpoint string
	// Channel is the default conversation key passed to Post when no thread
	// parent is specified.
	Channel string
	// Token is the bearer token sent in Authorization: Bearer <token>.
	Token string
	// HTTPClient is the underlying HTTP client; defaults to a 15s timeout client.
	HTTPClient *http.Client
	// MaxChunkRunes caps the rune length of each POSTed message chunk. Defaults
	// to 3500.
	MaxChunkRunes int
	// MaxRetries is the number of retry attempts on HTTP 429 or 5xx responses
	// (excluding 501). Defaults to 3.
	MaxRetries int
	// BaseBackoff is the initial backoff before the first retry (doubled each
	// attempt). Defaults to 200ms.
	BaseBackoff time.Duration
	// Sleep is an optional hook for tests to intercept backoff sleeps.
	Sleep func(ctx context.Context, d time.Duration) error
}

Config configures a switchboard /v1/messages Client.

type Error

type Error struct {
	Status int
	Body   string
	Err    error
}

Error wraps an HTTP status failure from the switchboard gateway.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Ref

type Ref struct {
	Channel string `json:"channel"`
	ID      string `json:"id"`
}

Ref identifies a posted message on the switchboard gateway so a later cycle can Replace it in place or Append to its thread.

Jump to

Keyboard shortcuts

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