mirror of
https://github.com/marcogll/talia_bot.git
synced 2026-01-13 13:25:19 +00:00
refactor: Migrate bot core and modules from talia_bot to bot directory, update start_bot.sh and Dockerfile, and modify README.md.
This commit is contained in:
33
bot/webhook_client.py
Normal file
33
bot/webhook_client.py
Normal file
@@ -0,0 +1,33 @@
|
||||
# app/webhook_client.py
|
||||
# Este script se encarga de enviar datos a servicios externos usando "webhooks".
|
||||
# En este caso, se comunica con n8n.
|
||||
|
||||
import requests
|
||||
from bot.config import N8N_WEBHOOK_URL, N8N_TEST_WEBHOOK_URL
|
||||
|
||||
def send_webhook(event_data):
|
||||
"""
|
||||
Envía datos de un evento al servicio n8n.
|
||||
Usa el webhook normal y, si falla o no existe, usa el de test como fallback.
|
||||
"""
|
||||
# Intentar con el webhook principal
|
||||
if N8N_WEBHOOK_URL:
|
||||
try:
|
||||
print(f"Intentando enviar a webhook principal: {N8N_WEBHOOK_URL}")
|
||||
response = requests.post(N8N_WEBHOOK_URL, json=event_data)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
except Exception as e:
|
||||
print(f"Fallo en webhook principal: {e}")
|
||||
|
||||
# Fallback al webhook de test
|
||||
if N8N_TEST_WEBHOOK_URL:
|
||||
try:
|
||||
print(f"Intentando enviar a webhook de fallback (test): {N8N_TEST_WEBHOOK_URL}")
|
||||
response = requests.post(N8N_TEST_WEBHOOK_URL, json=event_data)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
except Exception as e:
|
||||
print(f"Fallo en webhook de fallback: {e}")
|
||||
|
||||
return None
|
||||
Reference in New Issue
Block a user