Skip to content

Commit

Permalink
caronc#202: Add possibility of not passing body
Browse files Browse the repository at this point in the history
  • Loading branch information
phantom committed Jul 11, 2024
1 parent 4fbbd8b commit d8e05be
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions apprise_api/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,9 @@ def post(self, request, key):
# rules
rules = {k[1:]: v for k, v in request.GET.items() if k[0] == ':'}

body_not_required = request.GET.get('body_not_required') == 'true'
title_not_required = request.GET.get('title_not_required') == 'true'

# our content
content = {}
if not json_payload:
Expand Down Expand Up @@ -912,7 +915,7 @@ def post(self, request, key):
content['title'] = request.GET['title']

# Some basic error checking
if not content.get('body') and not attach or \
if (not content.get('body') and not body_not_required and not attach) or \
content.get('type', apprise.NotifyType.INFO) \
not in apprise.NOTIFY_TYPES:

Expand Down Expand Up @@ -1124,12 +1127,15 @@ def post(self, request, key):
if content_type == 'text/html' else \
settings.LOGGING['formatters']['standard']['format']

notif_body = content.get('body') if not body_not_required else apprise.NOT_REQUIRED
notif_title = content.get('title', '') if not title_not_required else apprise.NOT_REQUIRED

# Now specify our format (and over-ride the default):
with apprise.LogCapture(level=level, fmt=fmt) as logs:
# Perform our notification at this point
result = a_obj.notify(
content.get('body'),
title=content.get('title', ''),
notif_body,
title=notif_title,
notify_type=content.get('type', apprise.NotifyType.INFO),
tag=content.get('tag'),
attach=attach,
Expand Down Expand Up @@ -1323,8 +1329,11 @@ def post(self, request):
if not content.get('title') and 'title' in request.GET:
content['title'] = request.GET['title']

body_not_required = request.GET.get('body_not_required') == 'true'
title_not_required = request.GET.get('title_not_required') == 'true'

# Some basic error checking
if not content.get('body') or \
if (not content.get('body') and not body_not_required) or \
content.get('type', apprise.NotifyType.INFO) \
not in apprise.NOTIFY_TYPES:

Expand Down Expand Up @@ -1492,14 +1501,17 @@ def post(self, request):
elif level == 'TRACE':
level = logging.DEBUG - 1

notif_body = content.get('body') if not body_not_required else apprise.NOT_REQUIRED
notif_title = content.get('title', '') if not title_not_required else apprise.NOT_REQUIRED

if settings.APPRISE_WEBHOOK_URL:
esc = '<!!-!ESC!-!!>'
fmt = f'["%(levelname)s","%(asctime)s","{esc}%(message)s{esc}"]'
with apprise.LogCapture(level=level, fmt=fmt) as logs:
# Perform our notification at this point
result = a_obj.notify(
content.get('body'),
title=content.get('title', ''),
notif_body,
title=notif_title,
notify_type=content.get('type', apprise.NotifyType.INFO),
tag='all',
attach=attach,
Expand Down Expand Up @@ -1527,8 +1539,8 @@ def post(self, request):
else:
# Perform our notification at this point
result = a_obj.notify(
content.get('body'),
title=content.get('title', ''),
notif_body,
title=notif_title,
notify_type=content.get('type', apprise.NotifyType.INFO),
tag='all',
attach=attach,
Expand Down

0 comments on commit d8e05be

Please sign in to comment.