WhatsApp channel (coach)
The WhatsApp coach lets a clinician complete an incomplete note from a conversation. The coach names the missing required fields. It receives the values from the clinician. It writes nothing before an explicit confirmation. The coach does not submit to the registry. It never writes a value on its own.
The coach adds to intake and extraction and completeness review. It is not a separate path.
Status of this page
Section titled “Status of this page”The coach is merged to main (monorepo #94). It runs in production behind the BIOBADAMEX_WHATSAPP_COACH_ENABLED flag. The same flag controls the proactive coach opening. With the flag off, the channel goes back exactly to the file drop and milestone behavior.
The coach runs as a pilot. Two items stay in the backlog: the coach language (the coach is the decision-support system that speaks) and the G1–G3 safety refinements. To read from the logs what happened to a note, see observability & events.
| Term | Meaning |
|---|---|
| Coach | The conversation logic in RheumAI that asks for the missing fields and reads back the values. |
| Draft | The record that the monorepo makes from a note. A draft with missing required fields has the state review_pending. |
| Bridge | The thin link between the monorepo and the coach. It relays one inbound message and returns one coach reply. |
| Readback | The structured summary of the captured values that the coach sends before it saves. |
| CONFIRMO / CORRIGE | The two replies to a readback. CONFIRMO saves the values. CORRIGE asks for the values again. |
| Pseudonym | A salted hash of the phone number. It identifies the clinician in place of the phone number. |
| Milestone | A status message that the monorepo sends to the clinician, for example “review in console”. |
| Proactive opening | The first coach turn that the extraction worker starts for an incomplete WhatsApp draft. It replaces the draft_ready milestone. |
| Whitelist | The list of phone numbers per environment that can use the WhatsApp channel. |
Overview
Section titled “Overview”The clinician sends a file over WhatsApp. The monorepo receives the file at its front door. The monorepo does intake and extraction, and makes a draft. If the draft has no missing fields, the monorepo sends the milestone “review in console”. If the draft has missing fields and the coach flag is on, the worker opens the coach with the proactive opening.
The clinician can also open the coach with a text. Then the bridge relays the text to the coach in RheumAI. The coach names the missing fields. The clinician replies with values. The coach reads back the captured values. CORRIGE returns the clinician to the field request. CONFIRMO applies the values and re-grades through the monorepo audit.
If the draft is complete, the coach calls /approve for the owner. It never calls /submit. If the draft is not complete, the coach asks for the remaining fields. The coach keeps an encrypted transcript in Supabase.
Split of responsibilities
Section titled “Split of responsibilities”The coach runs in RheumAI and uses the RheumAI chat again. The monorepo stays the WhatsApp front door. The monorepo also owns the grader and the registry. One thin bridge connects the two services.
The split is deliberate, not incidental. The grader, the draft and the registry submission stay in the monorepo. This is the “RheumAI never proposes clinical values” moat.
- Monorepo: Meta transport, signature verification, whitelist, fail-closed clinician authentication, exactly-once receipt, consent, salted pseudonym, intake → extraction → draft, and the
/auditand/approveroutes. - RheumAI: the coach state machine, the completion re-grade, and the encrypted conversation transcript.
- Bridge: one message in, one reply out. A conversation id links the two. The bridge derives this id from the pseudonym.
When the coach opens
Section titled “When the coach opens”The coach opens in two ways: the proactive opening and a text from the clinician.
Proactive opening. The extraction worker opens the coach when it makes a draft and all of these conditions are true:
- The
BIOBADAMEX_WHATSAPP_COACH_ENABLEDflag is on (isCoachEnabled()). - The draft comes from WhatsApp: it has an intake receipt. The intake already applied the consent and the whitelist.
- The extractor reports at least one missing required field.
- The receipt gives a pseudonym (
readReceiptPseudonyminwhatsapp-coach-draft-lookup.ts).
The worker relays an opening turn to the coach in RheumAI. The coach reply names the missing fields. The worker sends this reply over WhatsApp in place of the draft_ready milestone. The worker claims the key coach_opening:<draftId> in the milestone outbox before the relay. Thus the opening occurs exactly one time per draft, also when the job runs again. If the coach already has a session for this conversation, the coach returns the current field request. It does not change the state or the transcript.
If the opening fails at any step, the worker sends draft_ready. A complete draft, or a draft with the flag off, gets draft_ready with no change. Thus the clinician always gets a message.
Clinician text. The coach also opens when a clinician sends a text message and these conditions are true:
- The clinician has consent and is on the whitelist.
- The clinician has a
review_pendingdraft with missing required fields.
The route decides between the coach and the guidance on one fact: does this clinician have an open incomplete draft? A database read gives this fact to the decision. The decision never calculates the fact itself.
State machine
Section titled “State machine”The coach does these steps. The numbers in Figure 2 are the numbers in this list.
- Name the missing fields. The monorepo opens the coach with the proactive opening or with the clinician text. The coach sends “I received your note. It’s missing: [list]. Can you share these?” The list comes from the monorepo grade (
requiredFieldsForand the missing fields per disease). It does not come from a flat bar. - Capture over turns. The clinician replies with values in one or more turns.
- Readback. The coach returns a structured summary of only the captured values. Then it waits: “Reply CONFIRMO to save it or CORRIGE to adjust.”
- CONFIRMO. The coach applies the confirmed values. It re-grades through the monorepo
/audit. If the draft is complete, the coach marks itapprovedthrough/approve. If the draft is not complete, the coach asks only for the remaining fields. - Always available. The clinician corrects the note and sends the file again (the existing file drop).
The firewall holds
Section titled “The firewall holds”These properties are the reason for the split. They are not an implementation detail.
- CONFIRMO is the human-authoring gate. No value goes into the draft without
CONFIRMO. The coach never adds free conversation text to the record. - CONFIRMO reaches only
/approve. Registry submission stays owner-only, behind a flag, and reviewed in the console (registry submission).CONFIRMOnever calls/submit. - Exactly-once at system level. A message that arrives again does not apply a value two times. It does not move the state two times. The monorepo receipt stops repeated deliveries before they reach the coach. The RheumAI transcript is an append-only audit log.
- Medico-legal transcript. Every turn persists encrypted at rest: the clinician text, the coach text, the readback and the
CONFIRMO. The web chat uses the same mechanism. The clinician pseudonym links the turns, never a raw phone number. - Bounded scope. The pilot does gap-fill and confirmation only. It has no open-ended clinical Q&A.
Consent and access
Section titled “Consent and access”A number without consent receives the consent notice (ACEPTO / BAJA). This copies the flow of the patient triage inbox. The notice states that the system processes clinical notes over WhatsApp.
No coach turn runs without a consented clinician. The environment whitelist stays the onboarding and security boundary. There is no self-service enrollment.
Out of scope
Section titled “Out of scope”- Registry submission from WhatsApp. It stays owner-only, behind a flag, and reviewed in the console.
- Open-ended clinical Q&A. The pilot does gap-fill and confirmation only.
- Native WhatsApp transport in RheumAI. The team rejected it. It would write again thousands of lines that already have a review. It removes no seam between the services.
Proposed work (not built)
Section titled “Proposed work (not built)”- Note identity in the coach. The coach could name the receipt code when several drafts are open. Then the clinician knows which draft the coach completes. Today the bridge already sends the
receiptCodeto the coach, but the coach replies do not use it. - Final-validator role (monitor). This role is not built. It would review the
approvedWhatsApp drafts of all clinicians. It would decide which drafts go to the registry. Today the flow stops atapproved, and/submitis owner-only. A central validator would change the submission gate. It would not be a new extraction path.
Evidence in code
Section titled “Evidence in code”Paths on main (the coach since monorepo #94):
- Monorepo:
apps/api/src/services/whatsapp-study-channel.ts(routing between the coach and the guidance) - Monorepo:
apps/api/src/services/whatsapp-coach-draft-lookup.ts(incomplete-draft read, read-only, andreadReceiptPseudonym) - Monorepo:
apps/api/src/services/biobadamex-jobs.ts(proactive opening:attemptCoachOpeningand the fallback todraft_ready) - Monorepo:
apps/api/src/services/whatsapp-coach-bridge.ts(relay to the coach) andwhatsapp-coach-copy.ts(outcome copy) - Monorepo:
apps/api/src/routes/biobadamex-drafts.ts(/approve;/submitnot changed) - RheumAI:
apps/bioagent/src/routes/coach.ts(coach endpoint, persistence and opening turn) andapps/bioagent/src/lib/coach-state.ts(state machine, reads) - Monorepo:
packages/biobadamex-registry/src/completeness.tsandrecord.ts(the missing-field list, used again)