diff --git a/CHANGELOG.md b/CHANGELOG.md index 93bb7f20..56bcc8ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format mostly follows [Keep a Changelog](http://keepachangelog.com/en/1.0.0/ - Added tags to jobs and the ability to select them at the command line (#789 by jamstah) - New filter `re.findall` (Requested in #804 by f0sh, contributed in #805 by jamstah) - Added tags to jobs and the ability to select them at the command line (#789, #824 by jamstah) +- New reporter: `gotify` (#823 by franco-righetti) ### Changed diff --git a/docs/source/reporters.rst b/docs/source/reporters.rst index 198620f6..684057b9 100644 --- a/docs/source/reporters.rst +++ b/docs/source/reporters.rst @@ -62,6 +62,7 @@ At the moment, the following reporters are built-in: - **discord**: Send a message to a Discord channel - **email**: Send summary via e-mail / SMTP / sendmail +- **gotify**: Send a message to a gotify server - **ifttt**: Send summary via IFTTT - **mailgun**: Send e-mail via the Mailgun service - **matrix**: Send a message to a room using the Matrix protocol @@ -210,6 +211,32 @@ Embedded content might be easier to read and identify individual reports. Subjec When `colored` is true reports will be embedded in code section (with diff syntax) to enable colors. +Gotify +------ + +[Gotify](https://gotify.net/) is a server for sending and receiving messages in real-time through WebSockets. + +To push notifications to a gotify server you need an application token. + +You can create one for urlwatch like so: + +1. Log into your gotify server's Web-UI. +2. Navigate to the “APPS” tab. +3. Click on the “CREATE APPLICATION” button. +4. Fill out the fields and press “CREATE”. +6. Click on the eye icon of the newly created entry and copy the token. + +Here is a sample configuration: + +.. code:: yaml + + gotify: + enabled: true + priority: 4 + server_url: "http://127.0.0.1:8090" + title: null + token: "Aa1yyikLFjEm35A" + IFTTT ----- diff --git a/lib/urlwatch/reporters.py b/lib/urlwatch/reporters.py index 2fc67a33..60d1c749 100644 --- a/lib/urlwatch/reporters.py +++ b/lib/urlwatch/reporters.py @@ -1134,3 +1134,33 @@ def submit(self): exitcode = process.wait() if exitcode != 0: logger.error('Shell reporter {} exited with {}'.format(cmd, exitcode)) + + +class GotifyReporter(MarkdownReporter): + """Send a message to a gotify server""" + MAX_LENGTH = 16 * 1024 + + __kind__ = 'gotify' + + def submit(self): + body_markdown = '\n'.join(super().submit(self.MAX_LENGTH)) + if not body_markdown: + logger.debug('Not sending message to gotify server (no changes)') + return + + server_url = self.config['server_url'] + url = f'{server_url}/message' + + token = self.config['token'] + headers = {'Authorization': f'Bearer {token}'} + + requests.post(url, headers=headers, json={ + "extras": { + "client::display": { + "contentType": "text/markdown", + }, + }, + 'message': body_markdown, + 'priority': self.config['priority'], + 'title': self.config['title'], + }) diff --git a/lib/urlwatch/storage.py b/lib/urlwatch/storage.py index 04245061..eaa0ddaf 100644 --- a/lib/urlwatch/storage.py +++ b/lib/urlwatch/storage.py @@ -152,6 +152,13 @@ 'webhook_url': '', 'max_message_length': 2000, }, + 'gotify': { + 'enabled': False, + 'priority': 0, + 'server_url': '', + 'title': None, + 'token': '', + }, 'matrix': { 'enabled': False, 'homeserver': '',