engine

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 58 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

Overview

Package engine owns the WhatsApp connection, the local store and every operation the CLI exposes.

Index

Constants

View Source
const (
	StateLoggedOut    = "logged_out"
	StatePairing      = "pairing"
	StateConnecting   = "connecting"
	StateConnected    = "connected"
	StateReconnecting = "reconnecting"
	StateBanned       = "temporarily_banned"
	StateOutdated     = "client_outdated"
	StateReplaced     = "replaced_by_other_session"
	StateStopped      = "stopped"
)

Variables

View Source
var Version = "dev"

Version is set at build time.

Functions

func ParseWhen

func ParseWhen(at, in string, now time.Time) (time.Time, error)

ParseWhen reads "in" durations and human times in local time. It never returns a time in the past.

func RegisterMethod

func RegisterMethod(m *Method)

RegisterMethod lets other packages (the remote server) add methods to the registry at init.

Types

type Action

type Action struct {
	Targets     []types.JID
	Sends       int  // outgoing messages reserved now, for rate limits
	Messages    bool // sends messages even if Sends is 0 (batches account per item)
	Destructive bool // deletes, leaves, removals, logout
	Summary     string
}

Action describes what a mutating call is about to do.

type Bus

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

func NewBus

func NewBus() *Bus

func (*Bus) Publish

func (b *Bus) Publish(ev api.Event)

func (*Bus) Subscribe

func (b *Bus) Subscribe(buf int) (int, <-chan api.Event)

func (*Bus) Unsubscribe

func (b *Bus) Unsubscribe(id int)

type Call

type Call struct {
	Ctx    context.Context
	E      *Engine
	Method *Method
	Req    *api.Request
	// contains filtered or unexported fields
}

Call carries one request through a handler.

func (*Call) Authorize

func (c *Call) Authorize(a Action) (dry bool, err error)

Authorize applies the caller's policy profile. It returns dry=true when the caller should only describe the action. For sends it also serializes with other sends until the call finishes, so rate limits stay exact.

func (*Call) Bind

func (c *Call) Bind(v any) error

Bind decodes params strictly, so a typo in a field name fails loudly instead of being ignored.

func (*Call) Emit

func (c *Call) Emit(v any) error

Emit sends a stream event to the caller.

type Engine

type Engine struct {
	Acct *config.Account
	Log  zerolog.Logger

	DB  *store.DB
	Bus *Bus
	// contains filtered or unexported fields
}

func New

func New(acct *config.Account, log zerolog.Logger) (*Engine, error)

New opens the stores and builds a client, but does not connect.

func (*Engine) Client

func (e *Engine) Client() *whatsmeow.Client

Client returns the current whatsmeow client.

func (*Engine) Config

func (e *Engine) Config() *config.Config

Config returns the live config, re-reading config.toml at most once a second when it changed.

func (*Engine) Dispatch

func (e *Engine) Dispatch(ctx context.Context, req *api.Request, emit func(any) error) (res any, err error)

Dispatch runs one request.

func (*Engine) OwnJID

func (e *Engine) OwnJID() types.JID

OwnJID is the logged-in phone-number JID without device suffix.

func (*Engine) SendToSelf

func (e *Engine) SendToSelf(ctx context.Context, text string) error

SendToSelf posts a notice in the user's own chat (used for sign-in codes).

func (*Engine) Start

func (e *Engine) Start()

Start connects if a session exists and keeps the connection healthy until Stop.

func (*Engine) State

func (e *Engine) State() (string, string)

func (*Engine) StatusInfo

func (e *Engine) StatusInfo(ctx context.Context) api.Status

StatusInfo is also used by the daemon when the socket is up but nothing else is.

func (*Engine) Stop

func (e *Engine) Stop()

Stop disconnects and closes the stores.

func (*Engine) WaitConnected

func (e *Engine) WaitConnected(ctx context.Context) error

WaitConnected blocks until the socket is up and logged in, or returns a structured error.

type Handler

type Handler func(c *Call) (any, error)

Handler implements one API method.

type Method

type Method struct {
	Name     string
	Summary  string
	Params   any  // zero value of the params struct, used for schemas
	Mutating bool // goes through policy and the audit log
	Stream   bool // emits events before the final result
	Conn     bool // needs a live WhatsApp connection
	H        Handler
}

Method describes one operation exposed over the socket, the CLI and MCP.

func LookupMethod

func LookupMethod(name string) *Method

func Methods

func Methods() []*Method

Methods lists every method sorted by name.

Jump to

Keyboard shortcuts

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