Documentation
¶
Overview ¶
Package httpapi serves WAHA's HTTP API. Each WAHA tag has its own file and registers its routes through Server.route, which authenticates, resolves the session the route acts on, checks the key's policy and, for routes that need a running session, waits for it the way WAHA does.
Index ¶
- func Environment(worker string) waha.Environment
- func HashKey(key string) string
- type APIKeyDTO
- type Action
- type Ctx
- type Error
- func ErrBadRequest(message any) *Error
- func ErrForbidden() *Error
- func ErrInternal(err error, r *http.Request) *Error
- func ErrNotFound(message string) *Error
- func ErrNotImplemented(why string) *Error
- func ErrSessionMissing(name string) *Error
- func ErrSessionNotFound() *Error
- func ErrSessionStatus(name, status string, expected ...string) *Error
- func ErrUnauthorized() *Error
- func ErrUnprocessable(message string) *Error
- type Handler
- type Principal
- type Route
- type SentMessage
- type Server
- type SessionDTO
- type SessionFrom
- type SessionInfo
- type Timestamps
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Environment ¶
func Environment(worker string) waha.Environment
Environment builds the environment block for a worker.
Types ¶
type APIKeyDTO ¶
type APIKeyDTO struct {
ID string `json:"id"`
Key string `json:"key"`
IsActive bool `json:"isActive"`
IsAdmin bool `json:"isAdmin"`
Session *string `json:"session"`
Sessions []string `json:"sessions"`
Actions json.RawMessage `json:"actions"`
}
APIKeyDTO is WAHA's ApiKeyDTO. Key is the plain key only in the answer that creates it; listings show it masked, because the store keeps only a hash (a deliberate difference from WAHA, which returns stored keys in full). Sessions extends it: a key may cover several sessions, and WAHA's Session is set only when it covers exactly one.
type Action ¶
type Action string
Action is what a route needs from a session key (WAHA's SessionActions), plus the two server-level grants.
const ( ActRead Action = "read" ActSend Action = "send" ActControl Action = "control" ActSetting Action = "setting" ActDelete Action = "delete" ActApp Action = "app" ActManage Action = "manage" // admin only: keys, server control, /health ActRetrieve Action = "retrieve" // any key: server version and status ActList Action = "list" // any key: the session list, filtered )
The actions a route can require.
type Ctx ¶
type Ctx struct {
W http.ResponseWriter
R *http.Request
S *Server
Principal Principal
Session string // the session name the route acts on ("" for NoSession)
Body []byte // the request body, read once
// contains filtered or unexported fields
}
Ctx is what a handler gets.
func (*Ctx) Account ¶
func (c *Ctx) Account() (*pb.AccountRef, error)
Account is the core's reference to the route's session account.
type Error ¶
Error is a response other than success. Body is written as JSON verbatim: WAHA answers some errors with NestJS's {message, error, statusCode} and others with a bare object, and clients match on both.
func ErrBadRequest ¶
ErrBadRequest is a 400; message is a string or a list of strings.
func ErrInternal ¶
ErrInternal is a 500 in WAHA's shape, minus the request body echo (which would hand base64 media and secrets back to any caller that triggers it).
func ErrNotImplemented ¶
ErrNotImplemented is WAHA's "not implemented by engine" 501. why, when set, names what wamux lacks, ahead of WAHA's sentence.
func ErrSessionMissing ¶
ErrSessionMissing is the 422 a working-session route gives for an unknown session.
func ErrSessionNotFound ¶
func ErrSessionNotFound() *Error
ErrSessionNotFound is the 404 of the session CRUD routes.
func ErrSessionStatus ¶
ErrSessionStatus is the 422 for a session that is not in an expected status.
func ErrUnprocessable ¶
ErrUnprocessable is a 422 with NestJS's string body.
type Principal ¶
type Principal struct {
Admin bool
Sessions []string // the sessions a non-admin key may touch
Actions map[string]bool // nil means WAHA's defaults
}
Principal is who a request authenticated as.
type Route ¶
type Route struct {
Action Action
From SessionFrom
Working bool // needs the session in WORKING
}
Route is one route's policy.
type SentMessage ¶
type SentMessage struct {
ID string `json:"id"`
Timestamp int64 `json:"timestamp"`
From string `json:"from"`
FromMe bool `json:"fromMe"`
Source string `json:"source"`
To *string `json:"to"`
Participant *string `json:"participant"`
Body *string `json:"body"`
HasMedia bool `json:"hasMedia"`
Ack int `json:"ack"`
AckName string `json:"ackName"`
Data json.RawMessage `json:"_data"`
}
SentMessage is WAHA's answer to a send. GOWS answers only `id` and `_data`; WAHA's document (and its other engines) answer a WAMessage. This is both: a WAMessage, with `_data` the core's own result.
type Server ¶
type Server struct {
Config *config.Config
Store store.Store
Core *core.Client
Sessions *sessions.Manager
Pub *events.Publisher
Media *media.Service
Tail *events.Tail
Log *slog.Logger
Started time.Time
Shutdown func() // POST /api/server/stop; nil disables the route
// How long a working-session route waits for the session to exist and
// to be WORKING before answering 422 (WAHA: 5 s and 10 s).
WaitExists, WaitStatus time.Duration
// contains filtered or unexported fields
}
Server is the HTTP API and everything its handlers reach.
type SessionDTO ¶
type SessionDTO struct {
Name string `json:"name"`
Status string `json:"status"`
Config json.RawMessage `json:"config"`
}
SessionDTO is what the session-changing routes answer.
type SessionFrom ¶
type SessionFrom int
SessionFrom says where a route reads its session name.
const ( NoSession SessionFrom = iota FromPath // the {session} path parameter FromBody // the "session" field of the JSON body FromQuery // the "session" query parameter )
Where a session name can come from.
type SessionInfo ¶
type SessionInfo struct {
Name string `json:"name"`
Status string `json:"status"`
Config json.RawMessage `json:"config"`
Me json.RawMessage `json:"me"`
AssignedWorker string `json:"assignedWorker,omitempty"`
Presence any `json:"presence"`
Timestamps Timestamps `json:"timestamps"`
Engine map[string]any `json:"engine,omitempty"`
}
SessionInfo is WAHA's SessionInfo (a session in a list or on its own).
type Timestamps ¶
type Timestamps struct {
Activity *int64 `json:"activity"`
}
Timestamps is SessionInfo.timestamps.