Metadata-Version: 2.4
Name: fastpluggy-plugin-ntfy-tools
Version: 0.5.1
Summary: Ntfy notification tools plugin for Fastpluggy
Author: FastPluggy Team
License-Expression: MIT
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: FastPluggy>=0.10.1
Requires-Dist: aiohttp
Requires-Dist: loguru
Provides-Extra: tests
Requires-Dist: pytest>=7.0; extra == "tests"
Requires-Dist: pytest-asyncio>=0.21; extra == "tests"
Requires-Dist: pytest-cov>=4.0; extra == "tests"
Requires-Dist: testcontainers>=4.0; extra == "tests"
Requires-Dist: httpx; extra == "tests"
Provides-Extra: e2e
Requires-Dist: playwright; extra == "e2e"
Provides-Extra: dev
Requires-Dist: fastpluggy-plugin-ntfy-tools[tests]; extra == "dev"
Dynamic: license-file

# fastpluggy-ntfy-tools

![Ntfy Tools](https://img.shields.io/badge/FastPluggy-Ntfy%20Tools-blue)
[![Release](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/ntfy_tools/-/badges/release.svg)](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/ntfy_tools/-/releases)
[![Pipeline Status](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/ntfy_tools/badges/main/pipeline.svg?key_text=CI)](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/ntfy_tools/-/pipelines?ignore_skipped=true)
[![Coverage](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/ntfy_tools/badges/main/coverage.svg)](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/ntfy_tools/-/pipelines)

Ntfy notification gateway for FastPluggy: the `ntfy` channel of notification_center (its rules choose which events reach which [ntfy](https://ntfy.sh) topic), a service to send from code, and a dashboard of the last notifications.

## Installation

```bash
pip install fastpluggy-plugin-ntfy-tools
```

## Configuration

Settings are loaded via `NtfySettings` (Pydantic `BaseSettings` subclass). Configure through environment variables or the FastPluggy settings UI.

| Setting | Default | Description |
|---------|---------|-------------|
| `internal_server_url` | `http://127.0.0.1:8086` | URL of the ntfy server (used for sending) |
| `external_app_url` | `http://127.0.0.1:8086` | Public URL used in notification action links |
| `ntfy_auth_token` | `""` | Bearer token for ntfy server authentication |
| `ntfy_default_topic` | `""` | Topic used when a rule's `ntfy` destination names none |

## Usage

### Sending notifications programmatically

The plugin registers an `NtfyService` instance in the `GlobalRegistry` on load:

```python
from fastpluggy.core.global_registry import GlobalRegistry

ntfy_service = GlobalRegistry.get_global("ntfy_service")
await ntfy_service.send("tasks", "Task completed", detail_link="/plugin/tasks/1")
```

### notification_center channel

The plugin registers an `ntfy` delivery channel for the `notification_center` plugin: a notification goes to the topic given as the recipient (`send(..., to="<topic>")`), or to `ntfy_default_topic` when none is given, as `title: message`, with a *View details* action when the notification carries `data["url"]`. The channel's `send()` is `async`; it needs **notification_center >= 0.2.4**, which runs it to completion in a background thread (older versions call it without awaiting it, so nothing is sent).

### Low-level controller

For direct sends without tracking:

```python
from fastpluggy_plugin.ntfy_tools.controller import send_ntfy

await send_ntfy("my-topic", "Hello from FastPluggy")
```

## Dashboard

The plugin provides a web dashboard at `/plugin/ntfy_tools/` (CI) or `/plugin-pkg/ntfy_tools/` (local dev) showing:

- Notification history (last 100 entries, dates in UTC, statuses with the core's `status_badge`; hover a *failed* status for the error), one card per notification on a phone
- Sent/failed totals (per topic in the metrics)
- The default topic, and where the routing lives (notification_center's rules)
- Quick-send form for testing

The page's script is a static file (`static/js/dashboard.js`), so it runs under the core's Content-Security-Policy.

## Running ntfy server (Docker)

For local development or self-hosted deployment:

```bash
# Quick start
docker run -d --name ntfy \
  -p 8080:80 \
  -v ntfy-cache:/var/cache/ntfy \
  -v ntfy-etc:/etc/ntfy \
  binwiederhier/ntfy serve

# Verify
curl http://localhost:8080/health

# Send a test notification
curl -d "Hello from FastPluggy" http://localhost:8080/fastpluggy-test

# View in browser
# Open http://localhost:8080/fastpluggy-test
```

### Plugin configuration

Set these in the plugin settings or environment:

| Setting | Default | Description |
|---------|---------|-------------|
| `internal_server_url` | `http://127.0.0.1:8086` | ntfy server URL (use `http://localhost:8080` for local Docker) |
| `ntfy_default_topic` | `""` | Topic for notification_center deliveries that name none |

### Docker Compose example

```yaml
services:
  ntfy:
    image: binwiederhier/ntfy
    command: serve
    ports:
      - "8080:80"
    volumes:
      - ntfy-cache:/var/cache/ntfy
      - ntfy-etc:/etc/ntfy

volumes:
  ntfy-cache:
  ntfy-etc:
```

## Upgrade Notes

### 0.5.0

The `ntfy_topics` setting (event pattern → topic) is removed, with its event-bus subscriptions, the `/api/topics` route and the *Topic Mappings* cards: notification_center's rules route the events now. notification_center 0.4.0 turned each stored `ntfy_topics` entry into a rule (`ntfy` destination, the topic as recipient) and deleted the setting; take it before or with this version. A value given by the `NTFY_TOPICS` environment variable is not converted: write its rules by hand on notification_center's *Rules* page, then drop the variable (it is ignored).
