Skip to content

Send an HTML reply when a transformer returns message_html - #34

Merged
brocla merged 1 commit into
mainfrom
html-reply
Nov 17, 2026
Merged

brocla merged 1 commit into
mainfrom
html-reply

Conversation

@brocla

@brocla brocla commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Why

The new check_temple_schedule transformer emails back a report with several sections and a per-block count table. As plain text it's hard to scan, and the table only lines up in a fixed-width font, which phones don't use. It already writes an HTML version of the report as message_html in result.json. This PR makes FileMill send it.

The plan is in doc/HTML-REPLY-PLAN.md, revised after review.

What changes

  • Contract: result.json gains an optional message_html. The change is additive, so contract_version stays "1", and an older FileMill ignores the field.

  • Store: a new jobs.message_html column, NOT NULL DEFAULT '', added by migration on existing databases. Thanks to the default, the rollback binary can still insert jobs into a migrated database; a test covers this. The existing files_deleted_at migration is now a general addJobsColumn helper.

  • App:

    • Only a succeeded job's HTML is kept; a failed job's reply stays plain text.
    • filemill.log now records only the first line of a job's message. A real schedule report is 52–55 lines and was being logged as one long escaped line per job.
  • Delivery: when a succeeded job has HTML, the reply is sent as text plus HTML through Mailgun's html field. The HTML part contains:

    • a small caption naming the file and report;
    • the fragment, inserted exactly as the transformer wrote it;
    • the sheet links as real links;
    • the support line as a mailto: link.

    Everything FileMill inserts itself is escaped. The link and support wording are shared with the text reply, so both say the same thing. A reply with no HTML job is unchanged, byte for byte. Alerts stay plain text.

  • README: documents result.json, including the rules for message_html (a fragment, email-safe, escaped by the transformer, under 100 KB). The uppercase example now sets a one-line message_html.

Testing

  • New tests:
    • contract: decoding with and without message_html;
    • store: the HTML survives the round trip through PendingEmails, migrating an old database keeps its rows, and an old-style insert still works;
    • app: HTML stored on success and dropped on failure, plus first-line logging;
    • delivery: no HTML field when no job has HTML, the HTML part's contents, a failed job, escaping, links in both parts, and alerts.
  • The fake Mailgun now reads each form field in full instead of only its first 4 KB.
  • go vet ./... and go test ./... pass. The delivery and HTML tests also pass 20 runs in a row.
  • On the real sample PDFs, check_temple_schedule produces 21–25 KB of HTML, well under Gmail's ~102 KB clipping limit.

After merge

  1. Deploy with Deploy-FileMill.ps1.
  2. Register check_temple_schedule on a plain email route, not sheets-link. It outputs no files, and sheets-link fails when no publisher is configured.
  3. Send a real schedule and check the reply in Gmail on a phone and on desktop, in light and dark mode.

🤖 Generated with Claude Code

A transformer may now add an optional message_html to result.json: an
email-safe HTML fragment of the same report. When a succeeded job has
one, the reply goes out as both text and HTML (Mailgun's html field
beside text); a reply whose jobs sent none is byte-for-byte as before.
The first user is check_temple_schedule, whose report of sections and a
per-block count table is hard to read as plain text on a phone.

- contract: Result.MessageHTML (json message_html, omitempty). Additive;
  contract_version stays "1".
- store: jobs.message_html TEXT NOT NULL DEFAULT '', added by migration
  on existing databases. The default keeps the rollback binary, which
  inserts jobs without naming the column, working. The files_deleted_at
  migration is generalized into addJobsColumn. Complete takes the HTML;
  PendingEmails and Get read it.
- app: only a succeeded job's HTML is stored. finish now logs only the
  first line of a job's message: a report runs to 50+ lines, which %q
  turned into one long escaped log line per job.
- mailgun: deliver builds an HTML document from each job's fragment
  under an escaped caption naming the file and report, then the sheet
  links as anchors and the support line as a mailto link. The link and
  support wording each live in one helper shared with the text reply.
  Everything FileMill inserts is escaped; the fragment goes in verbatim,
  as transformers are trusted code. Alerts stay plain text.
- README documents result.json, including message_html's rules, and the
  uppercase example sets a one-line message_html.

doc/HTML-REPLY-PLAN.md is the plan, revised after review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@brocla
brocla merged commit 0d751ad into main Nov 17, 2026
1 check passed
@brocla
brocla deleted the html-reply branch November 17, 2026 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant