Skip to content

Conversation

@f-wright
Copy link
Contributor

@f-wright f-wright commented Feb 12, 2025

This PR adds the ability to provide custom payloads for webhook alerts. It will be included in the 0.22.0 SDK release.

Copy link
Collaborator

@brandon-wada brandon-wada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rambled a bunch in my comments, but things look good as is

payload_template=payload_template,
)

def make_payload_template(self, template: str) -> PayloadTemplate:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left bad example code for you, but I appreciate that you followed the pattern

We shouldn't lean too hard into the make_* format. Most of the classes exist and it shouldn't be strange for a user to construct a payload as PayloadTemplate(template='mytr'). These generated classes are what we return via our custom SDK functions, so they shouldn't be strange to users. We do have make_* commands for alerts (specifically actions and conditions) because they have these horribly undiscoverable set of parameters, and the make_* commands give a convenient docstring for discovering those parameters.

The real fix is to make those parameters well defined and discoverable, but that's way down my priority stack.

This is all my ramblings, I don't actually have any requests from this comment, just that you know the background


def make_webhook_action(self, url: str, include_image: bool) -> WebhookAction:
def make_webhook_action(
self, url: str, include_image: bool, payload_template: Optional[PayloadTemplate] = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, if reasonable I think the payload_template should be allowed to be a string here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to make that change -- currently payload_template only has one text field, but I think we might be adding more soon. Specifically, we might be adding a separate header template for auth or a field indicating what kind of payload template it is (we currently only support json).

@f-wright f-wright marked this pull request as ready for review February 20, 2025 21:23
@f-wright f-wright merged commit 0fa6244 into main Feb 22, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants