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

Generic webhook notification #295

Closed
zdwolfe opened this issue Sep 12, 2023 · 6 comments · Fixed by #296
Closed

Generic webhook notification #295

zdwolfe opened this issue Sep 12, 2023 · 6 comments · Fixed by #296
Labels
enhancement New feature or request

Comments

@zdwolfe
Copy link

zdwolfe commented Sep 12, 2023

Is your feature request related to a problem? Please describe.
As the administrator of an application in the local travel space, I want camply to send a webhook (HTTP/POST) to a configuration-specified URL with configuration-specified headers and a JSON representation of the campsite so my application can programmatically handle the notification.

Describe the solution you'd like
When WEBHOOK_URL, WEBHOOK_HEADERS, and --notifications webhook are specified, the notification should be POST'ed to the WEBHOOK_URL with the WEBHOOK_HEADERS. The request body should be JSON with machine-readable fields (example, dates should be epoch timestamps or other common time format).

Something like:

{
  "campsite": {
    "campsite_id": "1234",
    "booking_date": 1694499820,
    "booking_url": "http://blahblah",
    "...": "etc"
  }
}

and

WEBHOOK_URL="http://foobar" \
  WEBHOOK_HEADERS=$(echo '{"Content-Type": "application/json", "x-api-key": "super-secret"}' | base64) \
  camply campsites --rec-area 12345

Describe alternatives you've considered

The open Discord PR is close, as is Slack, but the fields are human friendly or formatted, not generically machine-readable.

Additional context
If this sounds reasonable to you, I am willing to contribute a PR.

@github-actions github-actions bot added the triage This will looked at label Sep 12, 2023
@juftin
Copy link
Owner

juftin commented Sep 12, 2023

Oh this is a great idea. I took a whack at this, let me know your thoughts @zdwolfe : https://github.com/juftin/camply/blob/5c747a1cacfe44ae04f8c6108d81853bcec173ce/docs/command_line_usage.md#send-a-webhook-notification

@juftin juftin added enhancement New feature or request and removed triage This will looked at labels Sep 12, 2023
@juftin
Copy link
Owner

juftin commented Sep 12, 2023

Pydantic made this super easy to dump the camply.containers.AvailableCampsite objects into JSON:

def send_message(
self, message: List[Union[AvailableCampsite, Dict[str, Any]]], **kwargs
) -> requests.Response:
"""
Send a message via Webhook
Parameters
----------
message: str
Returns
-------
requests.Response
"""
json_message = json.dumps(message, default=pydantic_encoder)
resp = self.session.post(url=self.webhook_url, json=json_message)
return resp

@zdwolfe
Copy link
Author

zdwolfe commented Sep 12, 2023

Thanks! I left minor feedback in #296 (review)

@jeff-breece
Copy link

Love this idea!

@juftin
Copy link
Owner

juftin commented Sep 13, 2023

🎉 This issue has been resolved in version 0.30.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@juftin
Copy link
Owner

juftin commented Sep 13, 2023

Here's the relevant documenation: https://juftin.com/camply/command_line_usage/#send-a-webhook-notification

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants