| 1 | // Package ntfy provides a notification service for sending push notifications via ntfy.sh. |
| 2 | // |
| 3 | // The ntfy service allows sending notifications to ntfy topics, which can be subscribed to |
| 4 | // by mobile apps, web browsers, and other clients. It supports rich notifications with |
| 5 | // titles, priorities, tags, attachments, actions, and more. ntfy is a simple HTTP-based |
| 6 | // pub-sub notification service that works with any programming language. |
| 7 | // |
| 8 | // # URL Format |
| 9 | // |
| 10 | // The service URL follows the format: |
| 11 | // |
| 12 | // ntfy://[user:password@]host[:port]/topic[?query] |
| 13 | // |
| 14 | // Where: |
| 15 | // - user: optional username for authentication |
| 16 | // - password: optional password for authentication |
| 17 | // - host: ntfy server hostname (default: ntfy.sh) |
| 18 | // - port: optional port number (default: 443 for HTTPS, 80 for HTTP) |
| 19 | // - topic: target topic name (required) |
| 20 | // - query: configuration parameters |
| 21 | // |
| 22 | // # Configuration Options |
| 23 | // |
| 24 | // The following query parameters can be used to configure the service: |
| 25 | // |
| 26 | // - title: notification title |
| 27 | // - priority: message priority (1=min, 2=low, 3=default, 4=high, 5=max/urgent) |
| 28 | // - tags: comma-separated list of tags (may map to emojis) |
| 29 | // - actions: semicolon-separated list of user action buttons |
| 30 | // - click: URL to open when notification is clicked |
| 31 | // - attach: URL of attachment to include |
| 32 | // - filename: filename for attachment |
| 33 | // - delay: timestamp or duration for delayed delivery (e.g., "30m", "1h", "2023-12-25T10:00:00Z") |
| 34 | // - email: email address for email notifications |
| 35 | // - icon: URL to use as notification icon |
| 36 | // - markdown: enable Markdown formatting |
| 37 | // - cache: whether to cache messages (default: yes) |
| 38 | // - firebase: whether to send via Firebase (default: yes) |
| 39 | // - disabletls: set to "yes" to disable TLS verification |
| 40 | // |
| 41 | // # Templates |
| 42 | // |
| 43 | // ntfy does not use templates in the Shoutrrr sense, but supports rich message formatting |
| 44 | // through its native features like titles, tags, priorities, and actions. |
| 45 | // |
| 46 | // # Usage Examples |
| 47 | // |
| 48 | // ## Basic notification |
| 49 | // |
| 50 | // url := "ntfy://mytopic" |
| 51 | // err := shoutrrr.Send(url, "Hello from Shoutrrr!") |
| 52 | // |
| 53 | // ## Notification with title and high priority |
| 54 | // |
| 55 | // url := "ntfy://mytopic?title=Alert&priority=high" |
| 56 | // err := shoutrrr.Send(url, "System is down!") |
| 57 | // |
| 58 | // ## Notification with tags and actions |
| 59 | // |
| 60 | // url := "ntfy://mytopic?tags=warning,server&actions=view,%20View%20logs,%20https://logs.example.com" |
| 61 | // err := shoutrrr.Send(url, "Server error occurred") |
| 62 | // |
| 63 | // ## Notification with attachment |
| 64 | // |
| 65 | // url := "ntfy://mytopic?title=Backup&attach=https://files.example.com/backup.zip&filename=backup.zip" |
| 66 | // err := shoutrrr.Send(url, "Backup completed successfully") |
| 67 | // |
| 68 | // ## Delayed notification |
| 69 | // |
| 70 | // url := "ntfy://mytopic?delay=1h" |
| 71 | // err := shoutrrr.Send(url, "Reminder: Meeting in 1 hour") |
| 72 | // |
| 73 | // ## Notification with authentication |
| 74 | // |
| 75 | // url := "ntfy://user:[email protected]/mytopic" |
| 76 | // err := shoutrrr.Send(url, "Authenticated notification") |
| 77 | // |
| 78 | // # Common Use Cases |
| 79 | // |
| 80 | // ## System Monitoring Alerts |
| 81 | // |
| 82 | // Send alerts from monitoring systems like Nagios, Prometheus, or Zabbix: |
| 83 | // |
| 84 | // url := "ntfy://alerts?priority=high&tags=warning,server" |
| 85 | // err := shoutrrr.Send(url, "Disk space critical: 95% used") |
| 86 | // |
| 87 | // ## CI/CD Pipeline Notifications |
| 88 | // |
| 89 | // Notify about build status from Jenkins, GitHub Actions, or GitLab CI: |
| 90 | // |
| 91 | // url := "ntfy://builds?tags=success,github&title=Build%20Successful" |
| 92 | // err := shoutrrr.Send(url, "Build #123 passed") |
| 93 | // |
| 94 | // ## Home Automation |
| 95 | // |
| 96 | // Integrate with home automation systems like Home Assistant: |
| 97 | // |
| 98 | // url := "ntfy://home?tags=home,security&priority=urgent" |
| 99 | // err := shoutrrr.Send(url, "Motion detected at front door") |
| 100 | // |
| 101 | // ## Backup Completion Notifications |
| 102 | // |
| 103 | // Notify when backups complete: |
| 104 | // |
| 105 | // url := "ntfy://backups?tags=backup,done&title=Backup%20Complete" |
| 106 | // err := shoutrrr.Send(url, "Daily backup finished successfully") |
| 107 | // |
| 108 | // ## Scheduled Reminders |
| 109 | // |
| 110 | // Send delayed notifications for reminders: |
| 111 | // |
| 112 | // url := "ntfy://reminders?delay=9am&title=Morning%20Reminder" |
| 113 | // err := shoutrrr.Send(url, "Don't forget the team meeting!") |
| 114 | // |
| 115 | // # Error Handling |
| 116 | // |
| 117 | // The service returns errors for network failures, HTTP error status codes (4xx/5xx), |
| 118 | // authentication failures, and configuration issues. Always check the returned error: |
| 119 | // |
| 120 | // err := shoutrrr.Send(url, message) |
| 121 | // if err != nil { |
| 122 | // log.Printf("Failed to send ntfy notification: %v", err) |
| 123 | // } |
| 124 | // |
| 125 | // Common error scenarios: |
| 126 | // - Invalid topic name |
| 127 | // - Authentication failure (wrong credentials) |
| 128 | // - Network connectivity issues |
| 129 | // - Server rate limiting |
| 130 | // - Invalid attachment URLs |
| 131 | // |
| 132 | // # Security Considerations |
| 133 | // |
| 134 | // - Use HTTPS whenever possible (default behavior) |
| 135 | // - Store credentials securely, not in URLs if possible |
| 136 | // - Consider topic names as passwords - use unique, hard-to-guess names |
| 137 | // - Be cautious with attachment URLs - ensure they are from trusted sources |
| 138 | // - Use authentication for private topics |
| 139 | // - Consider message content - avoid sending sensitive information in notifications |
| 140 | // - Rate limiting may apply depending on server configuration |
| 141 | // |
| 142 | // # Limitations and Behaviors |
| 143 | // |
| 144 | // - Topic names are case-sensitive |
| 145 | // - Maximum message size depends on server configuration (typically 4KB) |
| 146 | // - Attachments are referenced by URL, not uploaded directly |
| 147 | // - Actions are limited to view, broadcast, and http types |
| 148 | // - Delayed delivery minimum is 10 seconds, maximum is 3 days |
| 149 | // - Messages may be cached on the server for up to 12 hours after delivery |
| 150 | // - Firebase notifications may not work in all regions or for all clients |
| 151 | // - Some features (like actions) are client-dependent and may not work on all platforms |
| 152 | package ntfy |