Add ntfy push notifications with action buttons for meal reminders
CI / test-and-package (push) Successful in 37s
CI / test-and-package (push) Successful in 37s
- ntfy.py: send_meal_reminder() with Home/Out HTTP action buttons, test helper - models.py: new columns ntfy_url, ntfy_token, callback_token on users table - meals.py: /api/ntfy-callback (public, token-authenticated), /ntfy-settings, /ntfy-test - app.py: flask send-reminders CLI command (cron-schedulable) - Dashboard: ntfy config form in Account Settings - i18n: translations for all ntfy strings (en/fr/de) - Dockerfile: include ntfy.py in COPY - tests: 15 new tests covering callback, settings, and auth - docs: updated AGENTS.md and doc/index.md
This commit is contained in:
@@ -32,6 +32,8 @@ A lightweight Flask web application for tracking household meal attendance. Memb
|
||||
├── auth.py # Authentication blueprint (login, register, logout)
|
||||
├── meals.py # Meals blueprint (dashboard, responses, history, admin)
|
||||
├── models.py # Database models and helpers
|
||||
├── i18n.py # Internationalization (en/fr/de)
|
||||
├── ntfy.py # Ntfy notification helpers
|
||||
├── requirements.txt # Python dependencies
|
||||
├── Dockerfile # Container image definition
|
||||
├── docker-compose.yml # Container orchestration
|
||||
@@ -118,6 +120,19 @@ source .env
|
||||
|
||||
## API / Routes
|
||||
|
||||
### Ntfy Callback (public)
|
||||
|
||||
| Method | Path | Description |
|
||||
|--------|------|-------------|
|
||||
| POST | `/api/ntfy-callback` | Receive ntfy action callbacks. Auth via per-user `callback_token`. Body: `{"token":"...", "meal_type":"lunch|dinner", "date":"YYYY-MM-DD", "status":"yes|no"}`. Returns 200 on success, 403 for bad token, 400 for invalid/past data. |
|
||||
|
||||
### Ntfy Settings (authenticated)
|
||||
|
||||
| Method | Path | Description |
|
||||
|--------|------|-------------|
|
||||
| POST | `/ntfy-settings` | Save ntfy topic URL and access token |
|
||||
| POST | `/ntfy-test` | Send a test notification to verify configuration |
|
||||
|
||||
### Authentication
|
||||
|
||||
| Method | Path | Description |
|
||||
@@ -189,3 +204,41 @@ pytest tests/ -v
|
||||
```
|
||||
|
||||
Tests use a temporary in-memory SQLite database (configured per test via `conftest.py`).
|
||||
|
||||
## Ntfy Notifications
|
||||
|
||||
Users can configure [ntfy](https://ntfy.sh) to receive push notifications with action buttons, allowing them to respond to meals directly from their phone without opening the web UI.
|
||||
|
||||
### Setup
|
||||
|
||||
1. Install the ntfy app on your phone and subscribe to a topic (e.g. `your-name-meals`)
|
||||
2. (Optional) Create an access token for authenticated publishing
|
||||
3. In the web UI, open **Account Settings** and enter:
|
||||
- **Ntfy Topic URL**: Your topic (e.g. `https://ntfy.sh/your-name-meals`)
|
||||
- **Access Token**: Your ntfy access token (if using auth)
|
||||
4. Click **Send Test** to verify it works
|
||||
|
||||
### How It Works
|
||||
|
||||
- Reminders are sent via the CLI command: `flask send-reminders`
|
||||
- The notification contains **Home** and **Out** buttons
|
||||
- Pressing a button sends an HTTP callback to the app, recording your response instantly
|
||||
- Tapping the notification itself opens the dashboard
|
||||
|
||||
### Scheduling Reminders
|
||||
|
||||
Add a cron job on the server to send reminders automatically:
|
||||
|
||||
```bash
|
||||
# Lunch reminder at 9:00 AM
|
||||
0 9 * * * cd /path/to/app && docker compose exec meal-tracker flask send-reminders --meal lunch --base-url https://meals.ct.cozytren.ch
|
||||
|
||||
# Dinner reminder at 5:00 PM
|
||||
0 17 * * * cd /path/to/app && docker compose exec meal-tracker flask send-reminders --meal dinner --base-url https://meals.ct.cozytren.ch
|
||||
```
|
||||
|
||||
Or run manually:
|
||||
|
||||
```bash
|
||||
docker compose exec meal-tracker flask send-reminders --date 2026-08-01 --meal both
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user