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
- Variables
- func ParsePhone(s string) (types.JID, error)
- type AmbiguousError
- type Candidate
- type Client
- func (c *Client) ChatTitle(ctx context.Context, ch store.Chat) string
- func (c *Client) Close() error
- func (c *Client) Connect() error
- func (c *Client) Connected() bool
- func (c *Client) DisplayName(ctx context.Context, jidStr string) string
- func (c *Client) Download(ctx context.Context, chat types.JID, messageID, dir string) (string, store.Message, error)
- func (c *Client) LoggedIn() bool
- func (c *Client) Login(ctx context.Context, phone string, out io.Writer) error
- func (c *Client) Logout(ctx context.Context) error
- func (c *Client) OwnJID() types.JID
- func (c *Client) Resolve(ctx context.Context, input string) (types.JID, error)
- func (c *Client) SearchContacts(ctx context.Context, query string, limit int) ([]Candidate, error)
- func (c *Client) SendFile(ctx context.Context, to types.JID, path, caption string) (Sent, error)
- func (c *Client) SendText(ctx context.Context, to types.JID, text, replyToID string) (Sent, error)
- func (c *Client) SetFilePolicy(p FilePolicy)
- func (c *Client) Status(ctx context.Context) (Status, error)
- func (c *Client) Store() *store.Store
- func (c *Client) WaitAuthenticated(ctx context.Context, timeout time.Duration) bool
- func (c *Client) WaitForHistorySync(ctx context.Context, idle, maxWait time.Duration) int
- type FilePolicy
- type Sent
- type Status
Constants ¶
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 ¶
var ErrNotLoggedIn = errors.New("no WhatsApp account linked: run `wamcp login` first")
ErrNotLoggedIn means no WhatsApp account is linked yet (run `wamcp login`).
Functions ¶
Types ¶
type AmbiguousError ¶
AmbiguousError lists the matches when a name designates several chats.
func (*AmbiguousError) Error ¶
func (e *AmbiguousError) Error() string
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) Connect ¶
Connect opens the connection for an already linked account. Messages start flowing into the store immediately.
func (*Client) DisplayName ¶
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) Login ¶
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) Resolve ¶
Resolve turns user input (JID, phone number or chat/contact name) into a JID.
func (*Client) SearchContacts ¶
SearchContacts finds chats and address-book contacts whose name, phone or JID contains query.
func (*Client) SendFile ¶
SendFile uploads a local file and sends it as an image, video, audio or document depending on its type.
func (*Client) SetFilePolicy ¶
func (c *Client) SetFilePolicy(p FilePolicy)
SetFilePolicy configures send_file restrictions.
func (*Client) WaitAuthenticated ¶
WaitAuthenticated waits until the connection is logged in, up to timeout.
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.