juftin / camply

camply, the campsite finder ⛺️ - a tool to find campsites at sold out campgrounds through sites like recreation.gov
https://juftin.com/camply/
MIT License
464 stars 89 forks source link

Generic webhook notification #295

Closed zdwolfe closed 11 months ago

zdwolfe commented 11 months ago

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.

juftin commented 11 months ago

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 commented 11 months ago

Pydantic made this super easy to dump the camply.containers.AvailableCampsite objects into JSON: https://github.com/juftin/camply/blob/5c747a1cacfe44ae04f8c6108d81853bcec173ce/camply/notifications/webhook.py#L43-L59

zdwolfe commented 11 months ago

Thanks! I left minor feedback in https://github.com/juftin/camply/pull/296#pullrequestreview-1623326944

jeff-breece commented 11 months ago

Love this idea!

juftin commented 11 months ago

:tada: This issue has been resolved in version 0.30.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

juftin commented 11 months ago

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