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) DeleteForEveryone(ctx context.Context, chat types.JID, messageID string) error
- 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) GroupInfo(ctx context.Context, chat types.JID) (Group, error)
- func (c *Client) LoadOlder(ctx context.Context, chat types.JID, count int) (int, 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) SendReaction(ctx context.Context, chat types.JID, messageID, emoji 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 Group
- type Participant
- 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) DeleteForEveryone ¶ added in v0.2.0
DeleteForEveryone revokes one of your own messages for every participant.
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. Media older than a few weeks is gone from WhatsApp's servers: it then asks the phone to upload it again, which needs the phone online.
func (*Client) GroupInfo ¶ added in v0.2.0
GroupInfo fetches a group's subject, description and members from WhatsApp.
func (*Client) LoadOlder ¶ added in v0.2.0
LoadOlder asks the phone for up to count messages older than the oldest archived one in chat, and returns how many new messages were stored. The phone must be online; it can only send what it still has.
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) SendReaction ¶ added in v0.2.0
func (c *Client) SendReaction(ctx context.Context, chat types.JID, messageID, emoji string) (Sent, error)
SendReaction reacts to a stored message with an emoji; an empty emoji removes your reaction.
func (*Client) SendText ¶
func (c *Client) SendText(ctx context.Context, to types.JID, text, replyToID string, mentions []types.JID) (Sent, error)
SendText sends a text message, optionally as a reply to a stored message and mentioning users (the text must then contain "@<their number>").
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.
type Group ¶ added in v0.2.0
type Group struct {
JID string `json:"jid"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Participants []Participant `json:"participants"`
}
Group describes a group chat.
type Participant ¶ added in v0.2.0
type Participant struct {
JID string `json:"jid"`
Name string `json:"name"`
Admin bool `json:"admin,omitempty"`
Owner bool `json:"owner,omitempty"`
}
Participant is a group member.