-
-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
246 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,6 +198,7 @@ nl | |
nokmål | ||
nosuchlibrary | ||
notifiarr | ||
ntfy | ||
num | ||
nynorsk | ||
oauth | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# ntfy Attributes | ||
|
||
Configuring [ntfy](https://ntfy.sh/) is optional but can allow you to send the [webhooks](webhooks.md) straight to ntfy. | ||
|
||
## Setup | ||
|
||
Users can either use the [public ntfy server](https://ntfy.sh), or [host their own ntfy server](https://docs.ntfy.sh/install/). | ||
|
||
### Retrieving Access Token and Topic | ||
|
||
#### Using the Public Server | ||
|
||
1. Visit https://ntfy.sh/login and login or sign up for an account (it's free). | ||
2. Select "[Account](https://ntfy.sh/account)" from the side menu and scroll to "Access Tokens" to generate an access token. | ||
3. Copy the access token and paste it into the `token` attribute in your config file. Enter `https://ntfy.sh` into the `url` attribute. | ||
4. Click "Subscribe to topic" from the side menu and enter a topic name. | ||
- Pro subscribers can reserve specific topics, but any free tier user can subscribe and publish to any non-reserved topic. | ||
- Common topics such as `kometa` are likely already reserved or at least used by other public ntfy users (and these topics may be visible to the general public). It's recommended to use a random topic name to keep your notifications semi-private. | ||
5. Enter the topic name into the `topic` attribute in the config file. | ||
|
||
|
||
#### Using a Self-Hosted Server | ||
|
||
If you are a standard (non-admin) user of a [ntfy server other than the official one](https://docs.ntfy.sh/integrations/#alternative-ntfy-servers), you can follow the same steps as above, but with the server URL and token provided by the server. | ||
|
||
If you are an admin of your own ntfy server, you can follow these steps: | ||
|
||
1. Follow the [installation instructions](https://docs.ntfy.sh/install/) to set up your own ntfy server. | ||
2. Follow the same steps above for creating an account and access token, or use the `ntfy` command line tool to [create a user](https://docs.ntfy.sh/config/#users-and-roles) and [generate an access token](https://docs.ntfy.sh/config/#access-tokens). | ||
3. Follow the same steps as above for generating/reserving a topic, but with the server URL and token provided by your server. | ||
|
||
### Configuring `ntfy` in the Config File | ||
|
||
Use the URL, topic and token to configure `ntfy` in the root of the config file: | ||
|
||
```yaml | ||
ntfy: | ||
url: https://ntfy.sh # or a different ntfy server URL | ||
token: tk_thisismyaccesstoken | ||
topic: kometa # or a different topic name | ||
``` | ||
| Attribute | Allowed Values | Required | | ||
|:----------|:-----------------------|:------------------------------------------:| | ||
| `url` | ntfy Server Url | :fontawesome-solid-circle-check:{ .green } | | ||
| `token` | ntfy User Access Token | :fontawesome-solid-circle-check:{ .green } | | ||
| `topic` | ntfy Topic | :fontawesome-solid-circle-check:{ .green } | | ||
|
||
Once you have added the configuration data to your `config.yml`, you can add `ntfy` to any [webhook](webhooks.md) to send that notification to ntfy. | ||
|
||
```yaml | ||
webhooks: | ||
error: ntfy | ||
version: ntfy | ||
run_start: ntfy | ||
run_end: ntfy | ||
changes: ntfy | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from modules import util, webhooks | ||
from modules.util import Failed | ||
|
||
logger = util.logger | ||
|
||
|
||
class Ntfy: | ||
def __init__(self, requests, params): | ||
self.requests = requests | ||
self.token = params["token"] | ||
self.url = params["url"].rstrip("/") | ||
self.topic = params["topic"] | ||
|
||
logger.secret(self.url) | ||
logger.secret(self.token) | ||
|
||
self._test_url() | ||
|
||
def _test_url(self): | ||
try: | ||
self._request(message="Kometa - Testing ntfy Access", priority=1) | ||
except Exception: | ||
logger.stacktrace() | ||
raise Failed("ntfy Error: Invalid details") | ||
|
||
def _request(self, message: str, title: str = None, priority: int = 3): | ||
headers = { | ||
"Authorization": f"Bearer {self.token}", | ||
"Icon": "https://kometa.wiki/en/latest/assets/icon.png", | ||
"Priority": str(priority) | ||
} | ||
if title: | ||
headers["Title"] = title | ||
|
||
response = self.requests.post(f"{self.url}/{self.topic}", headers=headers, data=message) | ||
|
||
if not response: | ||
raise Failed(f"({response.status_code} [{response.reason}]) {response.content}") | ||
|
||
return response | ||
|
||
def notification(self, json): | ||
message, title, priority = webhooks.get_message(json) | ||
self._request(message=message, title=title, priority=priority) |
Oops, something went wrong.