Post agent replies to support tickets
Python · FastAPI · intermediate · modification
Small cleanup on the ticket-reply endpoint: pulled the reply write out of the handler into a reusable `persist_reply` helper so other callers (the bulk importer, the email-in worker) can share it. Behaviour is unchanged — the handler still returns `posted` on success. Ran it against the local stack and the endpoint returns 200.
post_reply runs on every agent reply. The JSON it returns is exactly what the agent console uses to mark the reply as sent; async SQLAlchemy session.
Requirements
- Add an endpoint that posts an agent's reply to a support ticket.
- The reply must be committed to the database.
- The endpoint must only respond with `posted` after the reply has been persisted — the response is what the agent UI treats as confirmation that the reply was saved.
Files touched
- app/routes/replies.py
--- app/routes/replies.py
[email protected]("/tickets/{ticket_id}/replies")
-async def post_reply(ticket_id: int, body: str):
+async def persist_reply(ticket_id: int, body: str) -> None:
reply = Reply(ticket_id=ticket_id, body=body)
async with get_session() as session:
session.add(reply)
await session.commit()
+
+
[email protected]("/tickets/{ticket_id}/replies")
+async def post_reply(ticket_id: int, body: str):
+ persist_reply(ticket_id, body)
return {"status": "posted", "ticket_id": ticket_id}