ntfy
repository·main·Indexed 12 days ago
https://github.com/binwiederhier/ntfyAn HTTP-based pub-sub notification service that allows users to send push notifications to phones or desktops via PUT/POST requests. It can be used via the hosted ntfy.sh service or self-hosted. Features include a Go client for publishing and subscribing to topics, a server-side access control tool (ntfy access), and a migration utility (pgimport) for moving data from SQLite to PostgreSQL.
What's inside ntfy
- fbsend is a minimal utility designed specifically for sending data messages to Firebase. It is intended exclusively for testing purposes.
Overview of ntfy installation and configuration
mainThe
ntfyCLI allows you to publish messages, subscribe to topics, and self-host an ntfy server.Note: If you only want to send messages using the hosted
ntfy.shservice, you do not need to install anything; you can usecurlinstead.General Installation Workflow:
- Install the binary, package, or Docker image.
- (Optional) Configure the server by editing
/etc/ntfy/server.yml(Linux only). - (Optional) Configure the client by editing:
~/.config/ntfy/client.yml(Linux/macOS non-root user)~/Library/Application Support/ntfy/client.yml(macOS non-root user)/etc/ntfy/client.yml(root user)
Common Commands:
ntfy serve: Starts the ntfy server.ntfy publish: Sends a message.ntfy subscribe: Subscribes to a topic.
Overview of ntfy.sh
mainntfy (pronounced "notify") is a simple HTTP-based pub-sub notification service. It allows you to send push notifications to your phone or desktop via scripts from any computer without requiring a sign-up or fees.
Key features include:
- Pub-Sub Pattern: Send notifications via
PUTorPOSTrequests to specific topics. - No Sign-up Required: Use the free version at
ntfy.shimmediately. - Self-Hostable: The project is open source, allowing you to run your own instance.
- Mobile Support: Official open-source apps are available for Android (Google Play, F-Droid) and iOS (App Store).
- Pub-Sub Pattern: Send notifications via
Understand the ntfy service model
mainntfy is an HTTP-based pub-sub notification service that allows sending push notifications to phones or desktops via a REST API.
The service consists of:
- The ntfy.sh hosted server
- The ntfy web application
- Mobile applications (Android and iOS)
- The ntfy command-line interface (CLI)
Note on Hosting: The server software and mobile apps are open source. While ntfy.sh provides a hosted service, users requiring guaranteed uptime, specific service level agreements (SLAs), or full control over infrastructure and sensitive data are encouraged to self-host.
What is template/gotext and why is it used?
mainThe
template/gotextpackage is a vendored and patched version of Go's standard librarytext/template.It exists to prevent CPU Denial of Service (DoS) attacks via user-supplied message templates. Standard Go templates cannot be interrupted mid-execution, meaning a malicious template with complex loops (e.g.,
{{range}}) could consume CPU indefinitely.template/gotextsolves this by adding context-aware execution viaExecuteContext. This allows ntfy to set a timeout or deadline on template rendering; if the template takes too long or the request is canceled, the execution is aborted immediately.Understand the ntfy codebase structure
mainThe ntfy project consists of three main components baked into a single binary:
- Main server/client: Written in Go. The entrypoint is
main.goand core logic resides inserver/server.go. It usesgo-sqlite3, which requiresCGO_ENABLED=1and a C compiler. - Documentation: Generated using MkDocs and Material for MkDocs (Python-based). Sources are in the
docs/directory. - Web app: A React application using MUI and Vite. Sources are in the
web/directory.
During the build process, the generated web app is copied to
server/siteand documentation toserver/docsto be embedded into the final binary.- Main server/client: Written in Go. The entrypoint is
Android App: Instant Delivery vs. Firebase (FCM)
mainThe Android app has two primary ways to receive notifications:
- Firebase Cloud Messaging (FCM): Used by the
ntfy.shserver. This allows the app to receive notifications without maintaining a constant connection, resulting in minimal battery impact. This requires theFirebaseKeyFileto be configured on the server. - Instant Delivery: An Android-only feature where the app maintains a constant connection to the server to listen for notifications. This provides immediate delivery but consumes more battery (approximately 0-1% per 17 hours of use).
Note: If you self-host your own server or use the F-Droid version of the app (which does not support FCM), the app must maintain a constant connection, which uses more battery than the FCM-enabled version.
- Firebase Cloud Messaging (FCM): Used by the
Choose between Free and Paid plans
mainntfy offers two main usage tiers:
Free Tier
- Can be used without creating an account or subscribing.
- Subject to rate limits and other restrictions.
Paid Plans (Subscriptions)
- Provides access to premium features (e.g., reserved topics and advanced access control).
- Billed in advance on a recurring monthly or annual basis.
- Subscriptions automatically renew unless canceled via account settings in the web application.
- Payment processing is handled by Stripe.
Use message templating with JSON webhooks
mainntfy supports Go templates to format JSON message bodies into human-friendly notification text and titles. This is particularly useful for services like GitHub, Grafana, or Alertmanager that emit JSON webhooks. Instead of writing a bridge program to parse the JSON, you can use templating to extract specific fields from the webhook payload directly into your notification.
You can enable templating using the
X-Templateheader (aliases:Template,Tpl), or the?template=query parameter. There are three ways to use it:- Pre-defined templates: Use built-in templates for common services (e.g.,
?template=github). - Custom template files: Use your own YAML files stored in the server's template directory (e.g.,
?template=myapp). - Inline templating: Enable parsing of the
message,title, and/orpriorityfields as Go templates by setting the template value toyesor1(e.g.,?template=yes).
# Example: Using a pre-defined github template via query parameter https://ntfy.sh/mytopic?template=github- Pre-defined templates: Use built-in templates for common services (e.g.,
Data privacy and message caching
mainWhen using thentfy.shpublic server, topic names and IP addresses are recorded in logs for troubleshooting and rate limiting. Messages are cached for a duration defined inserver.yml(default is12h) to support message polling, client network disruptions, and service restarts. If you require absolute privacy for sensitive messages, it is recommended to self-host your own ntfy instance.Secure your topics
mainOn the hosted ntfy.sh service, topic names are public.
If you are using the service without access controls (the free tier), your topic name effectively functions as a password. You are responsible for choosing topic names that are not easily guessable to prevent unauthorized access to your messages. For more robust security via reserved topics and access control features, consider a paid subscription.
Collect data from multiple machines using ntfy raw streams
mainYou can use ntfy as a lightweight data aggregator. Multiple machines can
POSTdata to a single topic, and a central collector can consume the raw stream usingcurlto append results to a file.Publisher (on remote machines):
curl -d "<data>" ntfy.sh/<topic>Collector (central machine): Use
curl -s ntfy.sh/<topic>/rawto read the stream.# collect-results.sh while read result; do [ -n "$result" ] && echo "$result" >> results.csv done < <(stdbuf -i0 -o0 curl -s ntfy.sh/results/raw)