Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhook backend #208

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ntfy/backends/webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import requests
from ..config import USER_AGENT


def notify(title, message, url, verify=True, retcode=None):

payload = {"text": "*{}*\n{}".format(title, message)}
headers = {'User-Agent': USER_AGENT}

response = requests.post(url, json=payload, headers=headers, verify=verify)
response.raise_for_status()
16 changes: 16 additions & 0 deletions tests/test_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from unittest import TestCase

from mock import patch
from ntfy.backends.webhook import notify
from ntfy.config import USER_AGENT


class TestWebhook(TestCase):
@patch('requests.post')
def test_basic(self, mock_post):
url = 'https://hooks.slack.com/services/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'
notify('title', 'message', url)
mock_post.assert_called_once_with(
url,
json={'text': '*{}*\n{}'.format('title', 'message')},
headers={'User-Agent': USER_AGENT})