Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom payloads for webhook alerts #314

Merged
merged 15 commits into from
Feb 22, 2025
Merged

Custom payloads for webhook alerts #314

merged 15 commits into from
Feb 22, 2025

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-groundlight brandon-groundlight 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

)

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

@@ -163,7 +165,9 @@ def make_action(
include_image=include_image,
)

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.

2 participants