From 736c41a36f4d31b2b31a6f9e2ac1fbc891e614af Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Wed, 2 Jul 2025 20:10:29 +0530 Subject: [PATCH] Only handle task.created event --- app/main.py | 7 ++++++- pyproject.toml | 2 +- tests/test_automa.py | 16 +++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index 7b21943..3a807cb 100644 --- a/app/main.py +++ b/app/main.py @@ -19,7 +19,13 @@ async def health_check(): @app.post("/automa") async def automa_hook(request: Request): signature = request.headers.get("webhook-signature") + payload = (await request.body()).decode("utf-8") + body = json.loads(payload) + + # Skip if not `task.created` event + if "type" not in body or body["type"] != "task.created": + return Response(status_code=204) # Verify request if not verify_webhook(env().automa_webhook_secret, signature, payload): @@ -30,7 +36,6 @@ async def automa_hook(request: Request): return Response(status_code=401) base_url = request.headers.get("x-automa-server-host") - body = json.loads(payload) # Create client with base URL automa = AsyncAutoma(base_url=base_url) diff --git a/pyproject.toml b/pyproject.toml index cacc6f3..93c3dae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ requires-python = ">=3.11" classifiers = ["Private :: Do Not Upload"] dependencies = [ - "automa-bot~=0.2.1", + "automa-bot~=0.2.3", "fastapi-cli~=0.0.7", "fastapi~=0.115.11", "pydantic-settings~=2.8.1", diff --git a/tests/test_automa.py b/tests/test_automa.py index d268119..5e1f5f1 100644 --- a/tests/test_automa.py +++ b/tests/test_automa.py @@ -26,6 +26,20 @@ def call_with_fixture(client, filename): ) +def test_non_task_created(client): + """Test the Automa webhook endpoint with non task created event.""" + + headers = {} + + response = client.post( + "/automa", + content=b'{ "id": "whmsg_1", "timestamp": "2025-05-30T09:30:06.261Z", "type": "proposal.rejected" }', + headers=headers, + ) + + assert response.status_code == 204 + + @pytest.mark.parametrize( "signature", [ @@ -43,7 +57,7 @@ def test_invalid_signature(client, signature): response = client.post( "/automa", - content=b'{ "id": "whmsg_1", "timestamp": "2025-05-30T09:30:06.261Z" }', + content=b'{ "id": "whmsg_1", "timestamp": "2025-05-30T09:30:06.261Z", "type": "task.created" }', headers=headers, )