webhooks

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 34 Imported by: 0 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

Index

Constants

View Source
const (
	ConnectTimeout   = 5 * time.Second
	TotalTimeout     = 15 * time.Second
	MaxResponseBytes = 64 << 10
	MaxConcurrent    = 4
)
View Source
const (
	EventMessageReceived = store.EventMessageReceived
	EventAccountState    = store.EventAccountState
)
View Source
const (
	ContentMinimal = "minimal"
	ContentFull    = "full"
)
View Source
const (
	FormatStandard      = "standard"
	FormatClaudeRoutine = "claude-routine"
)
View Source
const (
	ChatsAll    = "all"
	ChatsDirect = "direct"
	ChatsGroups = "groups"
	ChatsListed = "listed"
)
View Source
const (
	StateEnabled  = "enabled"
	StateDisabled = "disabled"
)
View Source
const (
	DefaultQuiet   = 5 * time.Second
	DefaultMaxWait = 30 * time.Second
)
View Source
const (
	SecretPrefix = "whsec_"
)

Variables

This section is empty.

Functions

func HeaderNames

func HeaderNames(webhook store.Webhook) []string

func NewSecret

func NewSecret() (string, error)

func Sign

func Sign(id string, at time.Time, body []byte, secrets ...string) (string, error)

func SigningSecrets

func SigningSecrets(w store.Webhook, now time.Time) []string

func State

func State(w store.Webhook) string

Types

type BlockedAddressError

type BlockedAddressError struct {
	Host string
	Addr netip.Addr
}

func (*BlockedAddressError) Error

func (e *BlockedAddressError) Error() string

type Body

type Body struct {
	Type      string `json:"type"`
	Timestamp string `json:"timestamp"`
	Notice    string `json:"notice,omitempty"`
	Data      any    `json:"data"`
}

type Clients

type Clients interface {
	Client(accountID int64) (whatsapp.Client, bool)
}

type Dispatcher

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

func NewDispatcher

func NewDispatcher(deps DispatcherDeps) *Dispatcher

func (*Dispatcher) Notice

func (d *Dispatcher) Notice(evt any)

func (*Dispatcher) Run

func (d *Dispatcher) Run(ctx context.Context) error

func (*Dispatcher) Wake

func (d *Dispatcher) Wake()

type DispatcherDeps

type DispatcherDeps struct {
	Store  *store.Store
	Sender *Sender
	Clock  clock.Clock
	Random func() float64
	Audit  *audit.Logger
	Log    *slog.Logger
}

type InvalidError

type InvalidError struct {
	Message string
}

func (*InvalidError) Error

func (e *InvalidError) Error() string

type Options

type Options struct {
	URL                 string
	AllExistingAccounts bool
	Accounts            []string
	Chats               string
	Events              []string
	Content             string
	Format              string
	Headers             []string
	Quiet               string
	MaxWait             string
}

type Post

type Post struct {
	URL       string
	ID        string
	Timestamp time.Time
	Body      []byte
	Secrets   []string
	Headers   map[string]string
}

type Registered

type Registered struct {
	store.Webhook
	Accounts    []string
	ListedChats []string
	Deliveries  store.DeliverySummary
}

type Registration

type Registration struct {
	Name string
	Options
}

type Registry

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

func NewRegistry

func NewRegistry(deps RegistryDeps) *Registry

func (*Registry) Add

func (*Registry) Enable

func (r *Registry) Enable(ctx context.Context, name string) (store.Webhook, error)

func (*Registry) List

func (r *Registry) List(ctx context.Context) ([]Registered, error)

func (*Registry) Redeliver

func (r *Registry) Redeliver(ctx context.Context, name, since string) (store.Webhook, int, error)

func (*Registry) Remove

func (r *Registry) Remove(ctx context.Context, name string) (store.Webhook, error)

func (*Registry) RotateSecret

func (r *Registry) RotateSecret(ctx context.Context, name string) (store.Webhook, error)

func (*Registry) Set

func (r *Registry) Set(ctx context.Context, name string, opts Options) (Registered, error)

func (*Registry) Test

func (r *Registry) Test(ctx context.Context, name string) (store.Webhook, Result, error)

type RegistryDeps

type RegistryDeps struct {
	Store    *store.Store
	Clock    clock.Clock
	Sender   *Sender
	Resolver Resolver
	Clients  Clients
	Wake     func()
}

type Resolver

type Resolver interface {
	LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error)
}

type Result

type Result struct {
	Status     int
	RetryAfter string
	Err        error
	Sent       bool
}

func (Result) Accepted

func (r Result) Accepted() bool

func (Result) AsksToWait

func (r Result) AsksToWait() bool

func (Result) Blocked

func (r Result) Blocked() bool

func (Result) Gone

func (r Result) Gone() bool

func (Result) Retryable

func (r Result) Retryable() bool

func (Result) Unanswered

func (r Result) Unanswered() bool

type Sender

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

func NewSender

func NewSender(resolver Resolver, timeout time.Duration) *Sender

func (*Sender) Send

func (s *Sender) Send(ctx context.Context, p Post) Result

Jump to

Keyboard shortcuts

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