Please harden and finalise the /api/lia/nudge endpoint so it matches the safety and logging of /api/lia/outbound and /api/lia/inbound. 1) Locate the nudge implementation - Open app/lia_nudge.py (or whichever file currently implements the nudge logic). - Open app/main.py where the /api/lia/nudge endpoint is defined. 2) Conversation loading and safety checks In the nudge processing function (e.g., process_nudge or similar), make sure it: - Loads the conversation row from dp_conversations by conversation_id. - If no conversation is found → raise an error that becomes HTTP 404 ("Conversation not found"). - If conversation.status = 'dnc' → raise a DNCBlockedError with message "Customer is DNC - no further contact allowed". - If conversation.status = 'paused' → do NOT send a nudge; raise a NudgeBlockedError (or similar) that becomes HTTP 409 with message "Conversation is paused - no nudge sent". - If conversation.defer_until is NOT NULL and defer_until > today → raise a NudgeBlockedError that becomes HTTP 409 with a message like "Conversation is deferred until YYYY-MM-DD - no nudge sent". Reuse any existing DNCBlockedError class from lia_outbound if it already exists. If not, create one and keep it consistent. 3) Nudge generation and message logging - Generate the nudge text using the existing rules / helper (whatever you already have for building a nudge message). - Log the nudge to dp_messages using the same pattern as inbound/outbound: - sender = 'lia' - direction = 'outbound' - channel = conversation.channel - message_body = nudge_text - template_key = the template_key or mode used for the nudge (e.g., "NUDGE_12" or similar) - mode = a sensible string such as "NUDGE_12" or "NUDGE_GENERAL" You can either call existing log_* helpers or insert into dp_messages directly if that’s the current pattern. 4) Update dp_conversations state After sending/logging the nudge: - Keep stage the same (nudges do not change stage). - Keep status as 'active' unless you have a specific reason to change it. - Always update updated_at = NOW(). If your nudge rules need to set a defer_until (for example, if you want to pause follow-ups for a few days after a nudge), you can set defer_until and defer_reason, but don’t invent new behaviour unless there is already a clear rule. 5) Response shape (LiaNudgeReply) Make sure the nudge handler returns a JSON body with this shape: { "conversation_id": "", "status": "", "defer_until": "", "reply": "", "stage": "" } This should be consistent with the existing LiaReply patterns. 6) Error handling in app/main.py In app/main.py, update the /api/lia/nudge FastAPI endpoint to: - Import and catch DNCBlockedError (and any new NudgeBlockedError you add). - Map errors as follows: - DNCBlockedError → HTTP 409 with detail "Customer is DNC - no further contact allowed". - NudgeBlockedError (paused or deferred) → HTTP 409 with the message you set ("Conversation is paused - no nudge sent", or "Conversation is deferred until ..."). - Conversation not found → HTTP 404. - Any obvious validation error → HTTP 400 with detail set to the error message. 7) Restart and test Restart the server and run a couple of tests (you can use curl): - Valid nudge for an active conversation_id → HTTP 200 with the JSON body described above. - Nudge for a DNC conversation → HTTP 409 with DNC error. - Nudge for a paused/deferred conversation → HTTP 409 with the paused/deferred message. - Nudge for a non-existent conversation_id → HTTP 404. Finally, please summarise the final /api/lia/nudge behaviour and show one example JSON response for a successful nudge in your reply.