whatsapp

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnalyzeOggOpus

func AnalyzeOggOpus(data []byte) (uint32, []byte, error)

AnalyzeOggOpus computes duration seconds and a 64-byte waveform for WhatsApp PTT.

func ConvertToOpusOgg

func ConvertToOpusOgg(inputPath string) (string, error)

ConvertToOpusOgg converts an input audio file to .ogg (Opus) using ffmpeg. Returns the output path (temporary next to input) without removing the input.

Types

type Client

type Client struct {
	WA           *whatsmeow.Client
	Store        *store.DB
	Logger       *slog.Logger
	BaseDir      string
	SyncComplete chan struct{} // Signals when history sync is complete
}

Client wraps a WhatsApp client with store integration.

func New

func New(db *store.DB, baseDir string, verbose bool, logger *slog.Logger) (*Client, error)

New creates a new WhatsApp client.

func (*Client) Connect

func (c *Client) Connect() error

Connect connects to WhatsApp without QR (requires existing session).

func (*Client) ConnectWithQR

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

ConnectWithQR connects to WhatsApp, displaying a QR code if needed.

func (*Client) Disconnect

func (c *Client) Disconnect()

Disconnect disconnects from WhatsApp.

func (*Client) DownloadMedia

func (c *Client) DownloadMedia(messageID, chatJID string) (*DownloadMediaResult, error)

DownloadMedia looks up media from DB and downloads via whatsmeow.

func (*Client) ForwardMessage

func (c *Client) ForwardMessage(recipient, messageID, fromChatJID string) (*SendMessageResult, error)

ForwardMessage forwards a message to a recipient.

func (*Client) GetDeviceID

func (c *Client) GetDeviceID() (user string, device uint16)

GetDeviceID returns the device ID if authenticated.

func (*Client) IsAuthenticated

func (c *Client) IsAuthenticated() bool

IsAuthenticated returns true if there's a stored session.

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns true if connected to WhatsApp.

func (*Client) IsLoggedIn

func (c *Client) IsLoggedIn() bool

IsLoggedIn returns true if logged in to WhatsApp.

func (*Client) Logout

func (c *Client) Logout() error

Logout logs out and clears the session.

func (*Client) RequestBackfill

func (c *Client) RequestBackfill(jidStr string, count int) error

RequestBackfill requests historical messages for a chat. Note: WhatsApp controls how much history is sent.

func (*Client) SendMedia

func (c *Client) SendMedia(recipient, path, caption, replyToMessageID string) (*SendMessageResult, error)

SendMedia sends an image/video/document/audio with optional caption. If replyToMessageID is provided, sends as a quoted reply.

func (*Client) SendReaction

func (c *Client) SendReaction(chatJID, messageID, emoji string, remove bool) (*SendMessageResult, error)

SendReaction sends a reaction to a message.

func (*Client) SendText

func (c *Client) SendText(recipient, text, replyToMessageID string) (*SendMessageResult, error)

SendText sends a text message to a JID or phone number string (without +) or group JID. If replyToMessageID is provided, sends as a quoted reply.

type DownloadMediaResult

type DownloadMediaResult struct {
	Success   bool
	MediaType string
	Filename  string
	Path      string
}

DownloadMediaResult represents the result of downloading media from WhatsApp.

type SendMessageResult

type SendMessageResult struct {
	Success   bool
	Message   string
	MessageID string
	ChatJID   string
	Timestamp string
}

SendMessageResult represents the result of sending a WhatsApp message.

Jump to

Keyboard shortcuts

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