Documentation
¶
Overview ¶
Package engine owns the WhatsApp connection, the local store and every operation the CLI exposes.
Index ¶
- Constants
- Variables
- func ParseWhen(at, in string, now time.Time) (time.Time, error)
- func RegisterMethod(m *Method)
- type Action
- type Bus
- type Call
- type Engine
- func (e *Engine) Client() *whatsmeow.Client
- func (e *Engine) Config() *config.Config
- func (e *Engine) Dispatch(ctx context.Context, req *api.Request, emit func(any) error) (res any, err error)
- func (e *Engine) OwnJID() types.JID
- func (e *Engine) SendToSelf(ctx context.Context, text string) error
- func (e *Engine) Start()
- func (e *Engine) State() (string, string)
- func (e *Engine) StatusInfo(ctx context.Context) api.Status
- func (e *Engine) Stop()
- func (e *Engine) WaitConnected(ctx context.Context) error
- type Handler
- type Method
Constants ¶
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 ¶
var Version = "dev"
Version is set at build time.
Functions ¶
func ParseWhen ¶
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 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 ¶
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.
type Engine ¶
type Engine struct {
Acct *config.Account
Log zerolog.Logger
DB *store.DB
Bus *Bus
// contains filtered or unexported fields
}
func (*Engine) 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) SendToSelf ¶
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) StatusInfo ¶
StatusInfo is also used by the daemon when the socket is up but nothing else is.
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.