# Myristica WhatsApp Bridge

Tracked copy of the live Oracle VM bridge used by BOT Ruiz.

## What it does

- connects to WhatsApp with Baileys
- forwards inbound messages to the Next.js webhook
- sends text, button fallbacks, media, and presence updates
- downloads inbound media for OCR flows
- stores uploaded media files and serves them publicly

## Environment variables

```bash
WEBHOOK_URL=https://myristica-eight.vercel.app/api/webhook/whatsapp
API_KEY=myristica-evo-2026
PUBLIC_BASE_URL=https://miopenclaw-vnic.tail9799d2.ts.net
PORT=8080
```

## Local or VM setup

```bash
cd bridge
npm install
npm start
```

The first login creates `auth_state/`. Do not commit that folder.

## systemd example

Use `wa-bridge.service` as a template, then:

```bash
sudo cp wa-bridge.service /etc/systemd/system/wa-bridge.service
sudo systemctl daemon-reload
sudo systemctl enable --now wa-bridge
```

## Main endpoints

- `GET /` - health check
- `GET /status` - connection status
- `GET /qr` - QR payload for relinking
- `POST /media/upload` - save base64 file and return public URL
- `DELETE /media/:filename` - delete media file
- `POST /message/sendText/myristica`
- `POST /message/sendButtons/myristica`
- `POST /message/sendMedia/myristica`
- `POST /chat/sendPresence/myristica`
- `POST /chat/getBase64FromMediaMessage/myristica`
- `GET /group/fetchAllGroups/myristica`

## Notes

- the live VM bridge should be kept in sync with `bridge/index.js`
- `media/` and `auth_state/` are runtime-only
- button sending intentionally falls back to numbered text because native WhatsApp buttons are unreliable in this setup
