Use custom webhook bodies as is (instead of as a sub-field in webhook)

This commit is contained in:
Jim Ladd
2019-08-22 15:49:21 -07:00
parent 774a310e10
commit a10ad58c75
2 changed files with 32 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
# Copyright (c) 2016 Ansible, Inc.
# All Rights Reserved.
import json
import logging
import requests
@@ -37,6 +38,15 @@ class WebhookBackend(AWXBaseEmailBackend):
super(WebhookBackend, self).__init__(fail_silently=fail_silently)
def format_body(self, body):
# If `body` has body field, attempt to use this as the main body,
# otherwise, leave it as a sub-field
if isinstance(body, dict) and 'body' in body and isinstance(body['body'], str):
try:
potential_body = json.loads(body['body'])
if isinstance(potential_body, dict):
body = potential_body
except json.JSONDecodeError:
pass
return body
def send_messages(self, messages):