Skip to content

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.

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.

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.

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.

Split of responsibilities: the monorepo is the front door and owns the draft, the coach in RheumAI asks for the missing fieldsWhatsAppClinicianfile or textMonorepoMeta · signature · whitelistWhatsApp front doorauth, receipt, consent, pseudonymIntake → extraction → draftreview_pending if fields are missingMilestonereview in consoleno openingRheumAIsrc/lib/coach-state.tsCoachstate machine + re-gradebridgemessagereplyopeningSupabaseEncrypted transcriptappend-only, by pseudonymevery turngrader/audit · /approvenever /submit from the coachRheumAI never proposes clinical values.
Figure 1. Split of responsibilities. Solid arrows are calls or writes. The 'opening' arrow is the proactive opening of an incomplete draft. Dashed arrows are replies. Dotted frames are 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 /audit and /approve routes.
  • 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.

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_ENABLED flag 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 (readReceiptPseudonym in whatsapp-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_pending draft 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.

The coach does these steps. The numbers in Figure 2 are the numbers in this list.

Coach sequence across the clinician, the monorepo, the coach and the transcriptWhatsAppClinicianapi + bridgeMonorepoRheumAICoachSupabaseTranscriptA WhatsApp draft is incomplete1 · opening or clinician text1 · name the missing fields2 · values, in one or more turns2 · append each turn (encrypted)3 · readback: CONFIRMO or CORRIGE4 · CONFIRMO4 · apply and re-grade (/audit)4 · grade4 · complete: /approve only5 · or re-send the file
Figure 2. Coach sequence. Time goes down. Dashed arrows are replies. Messages between the clinician and the coach go through the monorepo and the bridge. Step 5 is the alternative path.
  1. 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 (requiredFieldsFor and the missing fields per disease). It does not come from a flat bar.
  2. Capture over turns. The clinician replies with values in one or more turns.
  3. Readback. The coach returns a structured summary of only the captured values. Then it waits: “Reply CONFIRMO to save it or CORRIGE to adjust.”
  4. CONFIRMO. The coach applies the confirmed values. It re-grades through the monorepo /audit. If the draft is complete, the coach marks it approved through /approve. If the draft is not complete, the coach asks only for the remaining fields.
  5. Always available. The clinician corrects the note and sends the file again (the existing file drop).

These properties are the reason for the split. They are not an implementation detail.

  1. CONFIRMO is the human-authoring gate. No value goes into the draft without CONFIRMO. The coach never adds free conversation text to the record.
  2. CONFIRMO reaches only /approve. Registry submission stays owner-only, behind a flag, and reviewed in the console (registry submission). CONFIRMO never calls /submit.
  3. 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.
  4. 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.
  5. Bounded scope. The pilot does gap-fill and confirmation only. It has no open-ended clinical Q&A.

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.

  • 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.
  • 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 receiptCode to the coach, but the coach replies do not use it.
  • Final-validator role (monitor). This role is not built. It would review the approved WhatsApp drafts of all clinicians. It would decide which drafts go to the registry. Today the flow stops at approved, and /submit is owner-only. A central validator would change the submission gate. It would not be a new extraction path.

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, and readReceiptPseudonym)
  • Monorepo: apps/api/src/services/biobadamex-jobs.ts (proactive opening: attemptCoachOpening and the fallback to draft_ready)
  • Monorepo: apps/api/src/services/whatsapp-coach-bridge.ts (relay to the coach) and whatsapp-coach-copy.ts (outcome copy)
  • Monorepo: apps/api/src/routes/biobadamex-drafts.ts (/approve; /submit not changed)
  • RheumAI: apps/bioagent/src/routes/coach.ts (coach endpoint, persistence and opening turn) and apps/bioagent/src/lib/coach-state.ts (state machine, reads)
  • Monorepo: packages/biobadamex-registry/src/completeness.ts and record.ts (the missing-field list, used again)