diff --git a/Makefile b/Makefile index ba8168617..99a633c0b 100644 --- a/Makefile +++ b/Makefile @@ -87,6 +87,14 @@ build: generate @echo "Build complete: $(BINARY_PATH)" @ln -sf $(BINARY_NAME)-$(PLATFORM)-$(ARCH) $(BUILD_DIR)/$(BINARY_NAME) +## build-whatsapp-native: Build with WhatsApp native (whatsmeow) support; larger binary +build-whatsapp-native: generate + @echo "Building $(BINARY_NAME) with WhatsApp native for $(PLATFORM)/$(ARCH)..." + @mkdir -p $(BUILD_DIR) + @$(GO) build $(GOFLAGS) -tags whatsapp_native $(LDFLAGS) -o $(BINARY_PATH) ./$(CMD_DIR) + @echo "Build complete: $(BINARY_PATH)" + @ln -sf $(BINARY_NAME)-$(PLATFORM)-$(ARCH) $(BUILD_DIR)/$(BINARY_NAME) + ## build-linux-arm: Build for Linux ARMv7 (e.g. Raspberry Pi Zero 2 W 32-bit) build-linux-arm: generate @echo "Building for linux/arm (GOARM=7)..." diff --git a/README.md b/README.md index 35c62434f..31495176a 100644 --- a/README.md +++ b/README.md @@ -391,7 +391,7 @@ picoclaw gateway PicoClaw can connect to WhatsApp in two ways: -- **Native (recommended):** In-process using [whatsmeow](https://github.com/tulir/whatsmeow). No separate bridge. Set `"use_native": true` and leave `bridge_url` empty. On first run, scan the QR code with WhatsApp (Linked Devices). Session is stored under your workspace (e.g. `workspace/whatsapp/`). +- **Native (recommended):** In-process using [whatsmeow](https://github.com/tulir/whatsmeow). No separate bridge. Set `"use_native": true` and leave `bridge_url` empty. On first run, scan the QR code with WhatsApp (Linked Devices). Session is stored under your workspace (e.g. `workspace/whatsapp/`). The native channel is **optional** to keep the default binary small; build with `-tags whatsapp_native` (e.g. `make build-whatsapp-native` or `go build -tags whatsapp_native ./cmd/...`). - **Bridge:** Connect to an external WebSocket bridge. Set `bridge_url` (e.g. `ws://localhost:3001`) and keep `use_native` false. **Configure (native)** diff --git a/pkg/channels/whatsapp_native.go b/pkg/channels/whatsapp_native.go index cbd02561f..3099afdcc 100644 --- a/pkg/channels/whatsapp_native.go +++ b/pkg/channels/whatsapp_native.go @@ -1,3 +1,5 @@ +//go:build whatsapp_native + // PicoClaw - Ultra-lightweight personal AI agent // License: MIT // @@ -58,16 +60,17 @@ type WhatsAppNativeChannel struct { // NewWhatsAppNativeChannel creates a WhatsApp channel that uses whatsmeow for connection. // storePath is the directory for the SQLite session store (e.g. workspace/whatsapp). -func NewWhatsAppNativeChannel(cfg config.WhatsAppConfig, bus *bus.MessageBus, storePath string) (*WhatsAppNativeChannel, error) { +func NewWhatsAppNativeChannel(cfg config.WhatsAppConfig, bus *bus.MessageBus, storePath string) (Channel, error) { base := NewBaseChannel("whatsapp", cfg, bus, cfg.AllowFrom) if storePath == "" { storePath = "whatsapp" } - return &WhatsAppNativeChannel{ + c := &WhatsAppNativeChannel{ BaseChannel: base, config: cfg, storePath: storePath, - }, nil + } + return c, nil } func (c *WhatsAppNativeChannel) Start(ctx context.Context) error { diff --git a/pkg/channels/whatsapp_native_stub.go b/pkg/channels/whatsapp_native_stub.go new file mode 100644 index 000000000..b4a826fa4 --- /dev/null +++ b/pkg/channels/whatsapp_native_stub.go @@ -0,0 +1,16 @@ +//go:build !whatsapp_native + +package channels + +import ( + "fmt" + + "github.com/sipeed/picoclaw/pkg/bus" + "github.com/sipeed/picoclaw/pkg/config" +) + +// NewWhatsAppNativeChannel returns an error when the binary was not built with -tags whatsapp_native. +// Build with: go build -tags whatsapp_native ./cmd/... +func NewWhatsAppNativeChannel(cfg config.WhatsAppConfig, bus *bus.MessageBus, storePath string) (Channel, error) { + return nil, fmt.Errorf("whatsapp native not compiled in; build with -tags whatsapp_native") +}