Skip to content

Commit

Permalink
webhook: Add initial webhook plugin (#39)
Browse files Browse the repository at this point in the history
This initial plugin implementation is very simple. It does a bunch of
simplifying things:
- Assumes `POST`.
- Assumes JSON request and response bodies.
- `body` and return are `Any`, so we won't get much typing help.

This is good enough to be used by a workflow with the description:
> Post a body of the form { "message": "Hello from Lutra and Zapier!"}
to the webhook `https://hooks.zapier.com/hooks/catch/<elided>`. Allow
only the message to be customizable.
  • Loading branch information
jcharum authored Feb 7, 2024
1 parent e962c4a commit 2e4cad1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions webhook/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Any

import httpx


async def webhook_request(url: str, body: Any) -> Any:
"""
Make a POST request to the given URL with the given body and returns the response.
Both the request and response bodies are expected to be JSON and are converted to
and from Python values using the json module.
"""
async with httpx.AsyncClient() as client:
return (await client.post(url, json=body)).raise_for_status().json()
2 changes: 2 additions & 0 deletions webhook/plugin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = "Webhook"
description = "Use external webhooks."

0 comments on commit 2e4cad1

Please sign in to comment.