Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/routers/github.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fastapi.routing import APIRouter
from ..core.models import GitHubPayload, TelexWebhookPayload
from ..config.config import settings
from ..utils.telex_utils import send_payload_to_telex
from ..utils.telex_utils import send_payload
from fastapi.responses import JSONResponse
from fastapi import status, HTTPException
import json
Expand All @@ -23,7 +23,7 @@ async def github_webhook(telex_channel_id: str, payload: GitHubPayload):
telex_url = f"{settings.telex_webhook_url}/{telex_channel_id}"

try:
response = await send_payload_to_telex(telex_payload, telex_url)
response = await send_payload(telex_payload, telex_url)
response_data = json.loads(response.decode().strip())
except Exception as e:
raise HTTPException(
Expand Down
14 changes: 10 additions & 4 deletions src/routers/telex.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from fastapi import status, HTTPException, Query
from typing import Annotated
import ast
import httpx
from ..utils.telex_utils import send_payload
import json


router = APIRouter(prefix="/telex")
Expand Down Expand Up @@ -41,9 +42,14 @@ async def telex_webhook(
if is_test == "true":
all_messages.append(output_message["text"])
else:
async with httpx.AsyncClient() as client:
await client.post(slack_url, json={"text": output_message})

try:
await send_payload(json.dumps(output_message), slack_url)
except Exception as e:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=f"Telex payload sending failed: {str(e)}",
)

if is_test == "true":
return JSONResponse(
content=all_messages,
Expand Down
6 changes: 3 additions & 3 deletions src/utils/telex_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
from fastapi import HTTPException, status


async def send_payload_to_telex(telex_payload: str, telex_url: str):
async def send_payload(payload: str, url: str):
"""Sends payload through an asynchronous curl subprocess."""
curl_command = [
settings.curl_command,
"-X",
"POST",
telex_url,
url,
"-H",
"Accept: application/json",
"-H",
"Content-Type: application/json",
"-d",
telex_payload,
payload,
]
process = await asyncio.create_subprocess_exec(
*curl_command, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
Expand Down