envelope

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package envelope defines the fabric message envelope carried inside botbus message bodies. The botbus hub remains byte-agnostic; envelopes are a client-side convention.

Index

Constants

View Source
const (
	KindChat          = "chat"
	KindDM            = "dm"
	KindTask          = "task"
	KindEscalate      = "escalate"
	KindStatus        = "status"
	KindReviewRequest = "review_request"
	KindCouncilResult = "council_result"
	KindControl       = "control"
	KindBatch         = "batch"
)

Kind constants.

Variables

This section is empty.

Functions

func Encode

func Encode(e Envelope) ([]byte, error)

Encode serializes an envelope to JSON bytes.

func NewID

func NewID() string

NewID returns a 26-char Crockford-base32 ULID-style id: a 48-bit millisecond timestamp prefix (lexicographically sortable) followed by 80 random bits.

Types

type Envelope

type Envelope struct {
	V       int      `json:"v"`
	ID      string   `json:"id"`
	TS      string   `json:"ts,omitempty"`
	From    string   `json:"from"`
	To      []string `json:"to,omitempty"`
	Kind    string   `json:"kind"`
	Scope   string   `json:"scope,omitempty"`
	Channel string   `json:"channel,omitempty"`
	Subject string   `json:"subject,omitempty"`
	Body    string   `json:"body"`
	// Enc carries a base64-encoded end-to-end ciphertext envelope. When set,
	// Subject and Body are empty on the wire; the receiving daemon decrypts Enc
	// and repopulates Subject/Body in memory. The hub stays byte-agnostic.
	Enc string `json:"enc,omitempty"`
}

Envelope is the JSON payload placed in a botbus message body.

func Decode

func Decode(b []byte) (Envelope, error)

Decode parses JSON bytes into an envelope.

func ParseOrWrap

func ParseOrWrap(sender, fromChannel string, b []byte) (Envelope, bool)

ParseOrWrap tries to parse b as an envelope. If b is not valid envelope JSON (a human typing into a channel, or a non-fabric client), it wraps the raw text as a chat envelope from `sender` originating on `fromChannel`. The bool reports whether wrapping occurred.

Jump to

Keyboard shortcuts

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