feat: stuur WhatsApp notificatie na dashcam transfer
This commit is contained in:
parent
caac864241
commit
e0b36a5b9c
2 changed files with 98 additions and 3 deletions
70
docs/superpowers/plans/2026-06-07-whatsapp-notification.md
Normal file
70
docs/superpowers/plans/2026-06-07-whatsapp-notification.md
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
# 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 on Mac Mini via Tailscale) 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://100.97.199.84:3000/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"
|
||||
```
|
||||
Loading…
Reference in a new issue