3030from groundlight_openapi_client .model .status_enum import StatusEnum
3131from groundlight_openapi_client .model .verb_enum import VerbEnum
3232from groundlight_openapi_client .model .webhook_action_request import WebhookActionRequest
33+ from groundlight_openapi_client .model .payload_template_request import PayloadTemplateRequest
3334from model import (
3435 ROI ,
3536 Action ,
4344 PaginatedRuleList ,
4445 Rule ,
4546 WebhookAction ,
47+ PayloadTemplate ,
4648)
4749
4850from groundlight .images import parse_supported_image_types
@@ -163,7 +165,7 @@ def make_action(
163165 include_image = include_image ,
164166 )
165167
166- def make_webhook_action (self , url : str , include_image : bool ) -> WebhookAction :
168+ def make_webhook_action (self , url : str , include_image : bool , payload_template : Optional [ str ] = None ) -> WebhookAction :
167169 """
168170 Creates a WebhookAction object for use in creating alerts
169171 This function serves as a convenience method; WebhookAction objects can also be created directly.
@@ -173,10 +175,14 @@ def make_webhook_action(self, url: str, include_image: bool) -> WebhookAction:
173175 action = gl.make_webhook_action("https://example.com/webhook", include_image=True)
174176 :param url: The URL to send the webhook to
175177 :param include_image: Whether to include the triggering image in the webhook payload
178+ :param payload_template: Optional custom template for the webhook payload. The template will be rendered with
179+ the alert data. The template must be a valid Jinja2 template which produces valid JSON when rendered. If no
180+ template is provided, the default template designed for Slack will be used.
176181 """
177182 return WebhookAction (
178183 url = str (url ),
179184 include_image = include_image ,
185+ payload_template = PayloadTemplate (template = payload_template ),
180186 )
181187
182188 def create_alert ( # pylint: disable=too-many-locals, too-many-arguments # noqa: PLR0913
@@ -266,6 +272,7 @@ def create_alert( # pylint: disable=too-many-locals, too-many-arguments # noqa
266272 WebhookActionRequest (
267273 url = str (webhook_action .url ),
268274 include_image = webhook_action .include_image ,
275+ payload_template = PayloadTemplateRequest (template = webhook_action .payload_template ) if webhook_action .payload_template else None ,
269276 )
270277 for webhook_action in webhook_actions
271278 ]
0 commit comments