Spaces:
Sleeping
Sleeping
File size: 1,382 Bytes
7a6bd0d bf1e5bd 7a6bd0d bf1e5bd 7a6bd0d bf1e5bd 7a6bd0d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import os
import logging
import requests
import json
import aiohttp
SLACK_WORKFLOW_URL = os.getenv("SLACK_WORKFLOW_URL", "")
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
async def send_to_workflow(data: dict) -> bool:
if not SLACK_WORKFLOW_URL:
logger.info("No workflow URL configured")
return False
try:
payload = json.dumps(data)
headers = {
'Content-Type': 'application/json'
}
logger.info(f"Sending to workflow: {payload}")
async with aiohttp.ClientSession() as session:
async with session.post(
SLACK_WORKFLOW_URL,
headers=headers,
data=payload,
timeout=aiohttp.ClientTimeout(total=10)
) as response:
response_text = await response.text()
logger.info(f"Workflow response status: {response.status}")
logger.info(f"Workflow response body: {response_text}")
response.raise_for_status()
logger.info("Sent to workflow successfully")
return True
except aiohttp.ClientError as e:
logger.error(f"Workflow HTTP error: {e}")
return False
except Exception as e:
logger.error(f"Workflow error: {e}")
return False |