# 02 - M1.9 Revision Sheet & Interview Q&A

Short revision summary for **Milestone 1.9**.

---

## 1. Quick Summary

- **What We Built:** Implemented `POST /api/v1/message` endpoint in `app/routers/message.py`, `MessageRequest`/`MessageResponse` Pydantic schemas, and client input/send button event handlers.
- **End-to-End Flow:** User types a message $\rightarrow$ Widget posts to `/message` $\rightarrow$ Backend validates `sessionId` $\rightarrow$ Returns `"Echo: <text>"` $\rightarrow$ Widget renders bot bubble.
- **Status Codes:** `200 OK` (success), `404 Not Found` (unknown session), `422 Unprocessable Entity` (empty message).

---

## 2. 5 Key Interview Q&As

#### Q1: Why does M1.9 use an echo response instead of AI or LLM integrations?
**Answer:** M1.9 validates the end-to-end messaging pipe (Widget $\rightarrow$ REST API $\rightarrow$ Database validation $\rightarrow$ Response rendering) without introducing LLM complexity or costs prematurely.

#### Q2: How does the backend validate that a message comes from a valid visitor?
**Answer:** The endpoint checks `sessionId` against the MongoDB `sessions` collection using `get_session_by_id`. Unknown session IDs return a `404 Not Found` error.

#### Q3: How are user and bot messages styled differently inside the Shadow DOM?
**Answer:** User messages use `.user-msg` (right-aligned, blue `#2563eb`), while bot responses use `.bot-msg` (left-aligned, gray `#e2e8f0`).

#### Q4: How does the widget handle auto-scrolling when new messages are added?
**Answer:** After appending a message bubble, the widget sets `chatBody.scrollTop = chatBody.scrollHeight` to automatically scroll the container to the latest message.

#### Q5: Did M1.9 introduce any breaking changes to existing endpoints?
**Answer:** No. All 13 backend unit tests (CORS, Tenant, Session Init, and Message Echo) pass 100%.
