wa

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 23 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 wa connects to WhatsApp (as a linked device, through whatsmeow) and mirrors every message it sees into the local store.

Index

Constants

View Source
const MaxUploadSize = 100 << 20

MaxUploadSize bounds files sent with SendFile (WhatsApp's own document limit is 2 GB, but anything this large is almost certainly a mistake when driven by an agent).

Variables

View Source
var ErrNotLoggedIn = errors.New("no WhatsApp account linked: run `wamcp login` first")

ErrNotLoggedIn means no WhatsApp account is linked yet (run `wamcp login`).

Functions

func ParsePhone

func ParsePhone(s string) (types.JID, error)

ParsePhone turns an international phone number ("+33 6 12 34 56 78", "0033612345678", "33612345678") into a user JID. Local numbers without a country code are rejected because they are ambiguous.

Types

type AmbiguousError

type AmbiguousError struct {
	Query      string
	Candidates []Candidate
}

AmbiguousError lists the matches when a name designates several chats.

func (*AmbiguousError) Error

func (e *AmbiguousError) Error() string

type Candidate

type Candidate struct {
	JID  string `json:"jid"`
	Name string `json:"name"`
}

Candidate is a chat or contact matching a name lookup.

type Client

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

Client is a WhatsApp linked device backed by a local message archive.

func Open

func Open(ctx context.Context, sessionPath string, st *store.Store, log waLog.Logger) (*Client, error)

Open loads the session database at sessionPath and wires events into st.

func (*Client) ChatTitle

func (c *Client) ChatTitle(ctx context.Context, ch store.Chat) string

ChatTitle is the exported form of chatTitle.

func (*Client) Close

func (c *Client) Close() error

Close disconnects and releases the session database.

func (*Client) Connect

func (c *Client) Connect() error

Connect opens the connection for an already linked account. Messages start flowing into the store immediately.

func (*Client) Connected

func (c *Client) Connected() bool

Connected reports whether the WebSocket to WhatsApp is up.

func (*Client) DisplayName

func (c *Client) DisplayName(ctx context.Context, jidStr string) string

DisplayName returns a human name for any JID.

func (*Client) Download

func (c *Client) Download(ctx context.Context, chat types.JID, messageID, dir string) (string, store.Message, error)

Download fetches the media of a stored message into dir and returns the file path.

func (*Client) LoggedIn

func (c *Client) LoggedIn() bool

LoggedIn reports whether an account is linked to this device.

func (*Client) Login

func (c *Client) Login(ctx context.Context, phone string, out io.Writer) error

Login links this device to a WhatsApp account. Without phone, a QR code is printed to out; with phone (international format), a pairing code is printed instead, to be typed in WhatsApp > Linked devices > Link with phone number. It returns once the device is paired and connected.

func (*Client) Logout

func (c *Client) Logout(ctx context.Context) error

Logout unlinks the device from the account and wipes the session.

func (*Client) OwnJID

func (c *Client) OwnJID() types.JID

OwnJID is the linked account (zero value when not logged in).

func (*Client) Resolve

func (c *Client) Resolve(ctx context.Context, input string) (types.JID, error)

Resolve turns user input (JID, phone number or chat/contact name) into a JID.

func (*Client) SearchContacts

func (c *Client) SearchContacts(ctx context.Context, query string, limit int) ([]Candidate, error)

SearchContacts finds chats and address-book contacts whose name, phone or JID contains query.

func (*Client) SendFile

func (c *Client) SendFile(ctx context.Context, to types.JID, path, caption string) (Sent, error)

SendFile uploads a local file and sends it as an image, video, audio or document depending on its type.

func (*Client) SendText

func (c *Client) SendText(ctx context.Context, to types.JID, text, replyToID string) (Sent, error)

SendText sends a text message, optionally as a reply to a stored message.

func (*Client) SetFilePolicy

func (c *Client) SetFilePolicy(p FilePolicy)

SetFilePolicy configures send_file restrictions.

func (*Client) Status

func (c *Client) Status(ctx context.Context) (Status, error)

Status reports the current state.

func (*Client) Store

func (c *Client) Store() *store.Store

Store gives read access to the local archive.

func (*Client) WaitAuthenticated

func (c *Client) WaitAuthenticated(ctx context.Context, timeout time.Duration) bool

WaitAuthenticated waits until the connection is logged in, up to timeout.

func (*Client) WaitForHistorySync

func (c *Client) WaitForHistorySync(ctx context.Context, idle, maxWait time.Duration) int

WaitForHistorySync blocks until no history batch arrived for idle, or until maxWait elapses. It returns the number of batches received.

type FilePolicy

type FilePolicy struct {
	Protected string // never readable (the data directory)
	Root      string // if set, only files under this directory are readable
}

FilePolicy restricts which local files send_file may read. Messages the model reads are untrusted input: a prompt injection could ask it to send a sensitive file, so the session keys are always off limits.

type Sent

type Sent struct {
	ID        string
	ChatJID   string
	Timestamp time.Time
}

Sent describes a message that was just sent.

type Status

type Status struct {
	LoggedIn  bool
	Connected bool
	Account   string
	Chats     int
	Messages  int
}

Status summarises the connection and archive.

Jump to

Keyboard shortcuts

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