luciemgrt1 commited on
Commit
33d47e0
·
verified ·
1 Parent(s): 85f91b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -244,7 +244,6 @@ def refresh_dashboard():
244
  default_df,
245
  )
246
 
247
-
248
  def call_n8n(payload):
249
  if not N8N_WEBHOOK_URL:
250
  return "N8N_WEBHOOK_URL is not set in Space variables."
@@ -252,14 +251,19 @@ def call_n8n(payload):
252
  try:
253
  response = requests.post(N8N_WEBHOOK_URL, json=payload, timeout=30)
254
  response.raise_for_status()
255
- data = response.json()
256
 
257
- if isinstance(data, dict):
258
- for key in ["result", "answer", "response", "output"]:
259
- if key in data and data[key]:
260
- return str(data[key])
 
 
 
 
 
 
 
261
 
262
- return json.dumps(data, indent=2)
263
  except Exception as e:
264
  return f"Webhook error: {e}"
265
 
 
244
  default_df,
245
  )
246
 
 
247
  def call_n8n(payload):
248
  if not N8N_WEBHOOK_URL:
249
  return "N8N_WEBHOOK_URL is not set in Space variables."
 
251
  try:
252
  response = requests.post(N8N_WEBHOOK_URL, json=payload, timeout=30)
253
  response.raise_for_status()
 
254
 
255
+ content_type = response.headers.get("content-type", "").lower()
256
+
257
+ if "application/json" in content_type:
258
+ data = response.json()
259
+ if isinstance(data, dict):
260
+ for key in ["result", "answer", "response", "output"]:
261
+ if key in data and data[key]:
262
+ return str(data[key])
263
+ return json.dumps(data, indent=2)
264
+
265
+ return response.text.strip() or "No response returned from webhook."
266
 
 
267
  except Exception as e:
268
  return f"Webhook error: {e}"
269