Fix webhook endpoint not receiving data that is not JSON (#2390)

This PR makes sure webhook can take any type of input.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-06-26 22:46:17 +00:00 committed by GitHub
commit 120e4994d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 5 deletions

View file

@ -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

View file

@ -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