Replicate jinja2 rendering over all providers

This commit is contained in:
Zedifus
2025-11-16 16:58:44 +00:00
parent ca008b7e98
commit 92bc8971e1
3 changed files with 13 additions and 8 deletions

View File

@@ -41,7 +41,7 @@ class MattermostWebhook(WebhookProvider):
return payload, headers
def send(self, server_name, title, url, message, **kwargs):
def send(self, server_name, title, url, message_template, event_data, **kwargs):
"""
Sends a Mattermost webhook notification using the given details.
@@ -52,7 +52,8 @@ class MattermostWebhook(WebhookProvider):
server_name (str): The name of the server triggering the notification.
title (str): The title for the notification message.
url (str): The webhook URL to send the notification to.
message (str): The main content or body of the notification message.
message_template (str): The Jinja2 template for the message body.
event_data (dict): A dictionary containing variables for template rendering.
bot_name (str): Override for the Webhook's name set on creation, see note!
Returns:
@@ -67,6 +68,7 @@ class MattermostWebhook(WebhookProvider):
- Mattermost's `config.json` setting is `"EnablePostUsernameOverride": true`
- Mattermost's `config.json` setting is `"EnablePostIconOverride": true`
"""
message = self.render_template(message_template, event_data)
bot_name = kwargs.get("bot_name", self.WEBHOOK_USERNAME)
payload, headers = self._construct_mattermost_payload(
server_name, title, message, bot_name

View File

@@ -67,7 +67,7 @@ class SlackWebhook(WebhookProvider):
return payload, headers
def send(self, server_name, title, url, message, **kwargs):
def send(self, server_name, title, url, message_template, event_data, **kwargs):
"""
Sends a Slack webhook notification using the given details.
@@ -78,7 +78,8 @@ class SlackWebhook(WebhookProvider):
server_name (str): The name of the server triggering the notification.
title (str): The title for the notification message.
url (str): The webhook URL to send the notification to.
message (str): The main content or body of the notification message.
message_template (str): The Jinja2 template for the message body.
event_data (dict): A dictionary containing variables for template rendering.
color (str, optional): The color code for the blocks's colour accent.
Defaults to a pretty blue if not provided.
bot_name (str): Override for the Webhook's name set on creation, (not working).
@@ -90,6 +91,7 @@ class SlackWebhook(WebhookProvider):
Raises:
Exception: If there's an error in dispatching the webhook.
"""
message = self.render_template(message_template, event_data)
color = kwargs.get("color", "#005cd1") # Default to a color if not provided.
bot_name = kwargs.get("bot_name", self.WEBHOOK_USERNAME)
payload, headers = self._construct_slack_payload(

View File

@@ -101,19 +101,19 @@ class TeamsWebhook(WebhookProvider):
return payload, headers
def send(self, server_name, title, url, message, **kwargs):
def send(self, server_name, title, url, message_template, event_data, **kwargs):
"""
Sends a Teams Adaptive card notification using the given details.
The method constructs and dispatches a payload suitable for
Discords's webhook system.
Teams's webhook system.
Parameters:
server_name (str): The name of the server triggering the notification.
title (str): The title for the notification message.
url (str): The webhook URL to send the notification to.
message (str): The main content or body of the notification message.
Defaults to a pretty blue if not provided.
message_template (str): The Jinja2 template for the message body.
event_data (dict): A dictionary containing variables for template rendering.
Returns:
str: "Dispatch successful!" if the message is sent successfully, otherwise an
@@ -122,5 +122,6 @@ class TeamsWebhook(WebhookProvider):
Raises:
Exception: If there's an error in dispatching the webhook.
"""
message = self.render_template(message_template, event_data)
payload, headers = self._construct_teams_payload(server_name, title, message)
return self._send_request(url, payload, headers)