Skip to content

feat(direct-send): send-email --follows sends a follow-up in an earlier direct email's thread - #42

Merged
ArtemKosolap merged 1 commit into
mainfrom
dev/REPLY-55044-follows
Nov 24, 2026
Merged

ArtemKosolap merged 1 commit into
mainfrom
dev/REPLY-55044-follows

Conversation

@ArtemKosolap

Copy link
Copy Markdown
Contributor

What

reply contact send-email takes --follows <reference>. With it, the email goes as a follow-up in the thread of an earlier direct email, through Reply's POST /v3/contacts/{id}/send-direct-email-follow-up instead of send-direct-email. reply direct-send get (and direct-send cancel, which prints the same record) adds Reply's follows to the send it prints.

Why

A second direct email to the same person should read as part of the first conversation: an answer in the first email's thread, under its subject, rather than a new thread. Reply's new follow-up route sends exactly that, and this change gives the CLI a way to call it.

The design makes sure an older version on either side can never turn a follow-up into a plain new-thread email:

  • An older reply-cli refuses --follows by itself, as an unknown option (error: unknown option '--follows', exit 2), before it calls Reply. This was checked against a build of main.
  • An older Reply has no follow-up route, and answers it with a 404 that carries no code of Reply's own. The CLI reads that as follows.not_available (exit 1, nothing sent) and calls nothing else after it, a plain send included. A 404 that does carry a code (contact.notFound, contact.followedSendNotFound, contact.scheduleNotFound) is Reply's own answer and maps as such.

How it works

  • --follows takes the earlier send's reference as Reply spells it and as direct-send get takes it: email-<n>, n from 1, no leading zero, at most ten digits. Anything else is usage.reference (exit 2), refused before stdin is read or any call is made.
  • The follow-up goes under its thread's subject, so its message on stdin (--message -) is {body} alone. A message carrying subject is usage.message (exit 2) with a sentence saying why, and nothing is sent. read_stdin_object gains an optional refused map for this, so the refusal does not read as a generic unknown field.
  • The request body is {emailAccountId, body, follows} plus the usual optional fields. --email-account-id, --send-after, --schedule-id, --idempotency-key (sent as a header), --track-links, --track-opens and the time-zone flags work as they do on a plain send. The contact is found or imported the same way, and the result has the same shape (reference, state, send_after, message_id, plus the rendered text when Reply sends the email within the request).
  • Reply's refusals of the email the follow-up names are read only on the follow-up route and only under the status Reply publishes each with. A plain send that answers one of these codes falls to the usual mapping. Every other refusal (limits, blacklist, idempotency key, schedule, template, contact not found, unknown outcome) maps exactly as on a plain send-email. As on every CLI refusal, reply_code keeps Reply's code.
  • direct-send get/cancel add follows (a string, or null for a send that follows none) only when Reply gives it in that shape. The CLI does the same for every field added to that record after its first ones (estimated_send_at, the rendered text, the bounce members), so an older Reply's answer prints exactly as before. Reply's three new failure codes for a follow-up (contact.followedSendNotSent, contact.followedSendNeverSent, contact.followUpNotPlaced) pass through failure_code untranslated, as every failure code does.
  • The command's --help gains the flag, an example and the new codes in its code list. The README and the reply-api skill (1.6.0) describe the flag in a few sentences.

Codes

Each one sends nothing.

Status Reply's code CLI code
404 contact.followedSendNotFound follows.not_found
403 contact.followedSendNotOwned follows.not_owned
400 contact.followedSendOtherContact follows.other_contact
400 contact.followedSendOtherMailbox follows.other_mailbox
409 contact.followedSendNeverSent follows.never_sent
409 contact.followedSendNotSent follows.not_sent
409 contact.followUpBeforeFollowedSend follows.too_early
409 contact.followUpNotPlaced follows.not_placed
404 none (no code) follows.not_available

The new flag and output field are additive, so this is a minor release (feat:).

How it was verified

  • npm test: 66 files, 1088 passed, 5 skipped. The 5 skips are the existing platform-specific ones (POSIX file modes, case-sensitive filesystems). The suite is offline, as always, with fetch stubbed. New tests cover:
    • every row of the table above, including each code read under another status or on a plain send
    • the code-less 404 in four forms (empty, problem without a code, HTML, plain text), asserting that exactly one request was made
    • every other refusal mapping as on a plain send
    • the outcome-unknown answers
    • the usage errors: 17 malformed references, and a subject (including an empty or null one) both alone and in the {contact, message} stdin pair
    • the request body sent: no subject, follows present, plus the other flags and the Idempotency-Key header
    • a contact given by its fields
    • direct-send get/cancel printing follows, and leaving it out when Reply gives no such field or one of another shape
    • the three follow-up failure codes passing through
    • the help text
    • two runs of the whole program through commander
  • npm run build (tsc) is clean, and commitlint passes on the commit.
  • Reply's follow-up route is not deployed yet, so none of this has been run against a live Reply.

…er direct email's thread

contact send-email --follows <reference> sends the email through Reply's
send-direct-email-follow-up route instead of send-direct-email, as a
follow-up in the thread of the earlier direct email the reference names.

- The reference is checked before any call: email-<n>, n from 1 with no
  leading zero and at most ten digits, as Reply spells it and as
  direct-send get takes it. Anything else is usage.reference, exit 2.
- The message is {body} alone, since the follow-up goes under its
  thread's subject. A message carrying a subject is usage.message,
  exit 2, and says why; nothing is sent.
- The other flags, the way the contact is found or imported, and the
  result are those of a plain send-email.
- Reply's refusals of the email it follows map to follows.not_found,
  not_owned, other_contact, other_mailbox, never_sent, not_sent,
  too_early and not_placed, each read only under the status Reply
  publishes it with and only on this route. Every other refusal maps as
  on a plain send, and reply_code keeps Reply's code.
- A 404 with no code of Reply's is follows.not_available: that Reply has
  no follow-up route. Nothing was sent, and nothing else is called.

direct-send get and cancel add Reply's follows, the reference of the
email a follow-up went in the thread of, or null, only when Reply gives
it, so an older Reply prints as before. The failure codes a follow-up
can end with are passed on as given, like every failure_code.

The README and the reply-api skill say how to send a follow-up and what
follows.not_available means.
@ArtemKosolap
ArtemKosolap merged commit b117370 into main Nov 24, 2026
6 checks passed
@ArtemKosolap
ArtemKosolap deleted the dev/REPLY-55044-follows branch November 24, 2026 04:59
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