- WHATSAPP_API gebruikte 100.97.199.84:3000 (Mac Mini Tailscale IP, verkeerde poort) - Gewijzigd naar localhost:3001 (wwebjs-api container op nextcloud zelf) - Comment toegevoegd om verwarring te voorkomen - README herschreven met WhatsApp notificatie sectie en correcte architectuur - Verouderd plan geüpdatet met juiste URL
70 lines
2.4 KiB
Markdown
70 lines
2.4 KiB
Markdown
# WhatsApp Notification Implementation Plan
|
|
|
|
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
|
|
|
**Goal:** Add a WhatsApp notification to the dashcam transfer script that sends a summary to admin Eddy after each transfer.
|
|
|
|
**Architecture:** A single `send_whatsapp_notification()` function is added to `dashcam-transfer.py`. It POSTs to the local wwebjs-api (running as Docker container on nextcloud, port 3001) using stdlib `urllib.request`. Failures are logged but never crash the script.
|
|
|
|
**Tech Stack:** Python 3 stdlib (`urllib.request`, `json`), wwebjs-api REST API
|
|
|
|
---
|
|
|
|
### Task 1: Add WhatsApp notification to dashcam-transfer.py
|
|
|
|
**Files:**
|
|
- Modify: `dashcam-transfer.py:3` (add imports)
|
|
- Modify: `dashcam-transfer.py:189-191` (add notification call)
|
|
|
|
- [ ] **Step 1: Add imports**
|
|
|
|
Add `import json` and `import urllib.request` after the existing stdlib imports.
|
|
|
|
- [ ] **Step 2: Add `send_whatsapp_notification()` function**
|
|
|
|
Insert before `parse_args()` (after `ensure_free_space`):
|
|
|
|
```python
|
|
WHATSAPP_API = "http://localhost:3001/client/sendMessage/EdGpt"
|
|
WHATSAPP_CHAT = "31620248011@c.us"
|
|
|
|
|
|
def send_whatsapp_notification(ok, errors):
|
|
status = "geen fouten" if errors == 0 else f"{errors} fout(en)"
|
|
body = f"Dashcam transfer voltooid: {ok} bestanden overgezet, {status}"
|
|
payload = {"chatId": WHATSAPP_CHAT, "content": body, "contentType": "string"}
|
|
try:
|
|
data = json.dumps(payload).encode()
|
|
req = urllib.request.Request(WHATSAPP_API, data=data, headers={"Content-Type": "application/json"})
|
|
urllib.request.urlopen(req, timeout=10)
|
|
logging.info("WhatsApp notificatie verstuurd")
|
|
except Exception as e:
|
|
logging.warning("WhatsApp notificatie mislukt: %s", e)
|
|
```
|
|
|
|
- [ ] **Step 3: Call notification at end of `main()`**
|
|
|
|
Replace:
|
|
```python
|
|
logging.info(
|
|
"Transfer voltooid: %d ok, %d fouten", ok, errors
|
|
)
|
|
```
|
|
|
|
With:
|
|
```python
|
|
logging.info("Transfer voltooid: %d ok, %d fouten", ok, errors)
|
|
send_whatsapp_notification(ok, errors)
|
|
```
|
|
|
|
- [ ] **Step 4: Verify the script parses correctly**
|
|
|
|
Run: `python3 -c "import ast; ast.parse(open('dashcam-transfer.py').read()); print('OK')"`
|
|
Expected: `OK`
|
|
|
|
- [ ] **Step 5: Commit**
|
|
|
|
```bash
|
|
git add dashcam-transfer.py
|
|
git commit -m "feat: stuur WhatsApp notificatie na dashcam transfer"
|
|
```
|