From e71bc6453978add234ba93d1c53177838cc7934d Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 26 Jun 2024 19:30:31 -0300 Subject: [PATCH 1/2] feat: Add test for webhook with random payload --- tests/test_webhook.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_webhook.py b/tests/test_webhook.py index c8d75c9cc58..edba88168c8 100644 --- a/tests/test_webhook.py +++ b/tests/test_webhook.py @@ -26,3 +26,15 @@ def test_webhook_endpoint(client, added_webhook_test): response = client.post(endpoint, json=payload) assert response.status_code == 202 assert not file_path.exists() + + +def test_webhook_with_random_payload(client, added_webhook_test): + endpoint_name = added_webhook_test["endpoint_name"] + endpoint = f"api/v1/webhook/{endpoint_name}" + # Just test that "Random Payload" returns 202 + # returns 202 + response = client.post( + endpoint, + json="Random Payload", + ) + assert response.status_code == 202 From 1ce9872e988ad1a91ad5d7c7276533ce7b07d6b1 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 26 Jun 2024 19:31:16 -0300 Subject: [PATCH 2/2] fix: webhook endpoint passes webhook input as is --- src/backend/base/langflow/api/v1/endpoints.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/backend/base/langflow/api/v1/endpoints.py b/src/backend/base/langflow/api/v1/endpoints.py index 92358111a82..35a8f66375f 100644 --- a/src/backend/base/langflow/api/v1/endpoints.py +++ b/src/backend/base/langflow/api/v1/endpoints.py @@ -276,15 +276,15 @@ async def webhook_run_flow( # get all webhook components in the flow webhook_components = get_all_webhook_components_in_flow(flow.data) tweaks = {} - data_dict = await request.json() + for component in webhook_components: tweaks[component["id"]] = {"data": data.decode() if isinstance(data, bytes) else data} input_request = SimplifiedAPIRequest( - input_value=data_dict.get("input_value", ""), - input_type=data_dict.get("input_type", "chat"), - output_type=data_dict.get("output_type", "chat"), + input_value="", + input_type="chat", + output_type="chat", tweaks=tweaks, - session_id=data_dict.get("session_id"), + session_id=None, ) logger.debug("Starting background task") background_tasks.add_task( # type: ignore