Usage

The mail services of KLK006 publish and consume this model: klok-postmark-ingress maps inbound mail to KlokMailInboundV1, klok-postmark-egress sends KlokMailOutboundV1 and answers with KlokMailSendResultV1, and klok-api-mail routes Klok AI's mail to mailboxes, sends replies and notices and writes Klok Svar's drafts (KlokMailDraftV1). This page says how each role gets and uses the model.

For a developer of a client application

A client is a Klok application that wants to send or receive mail. It publishes KlokMailOutboundV1 and consumes KlokMailSendResultV1 and KlokMailInboundV1 on its account's topics.

Java

Take the artifact through the dependency catalog, never with a typed version. Refresh the project's copy of the catalog, commit gradle/klok-libs.versions.toml, and use the alias:

./gradlew updateKlokLibsToml
dependencies {
    implementation klokLibs.klokMailV1
}

The classes are in dev.klok.klok.datamodel.public_.klok_mail_v1.

Python

Every release is also a Python package, klok-datamodel-klok-mail-v1, in this project's GitLab PyPI registry (the tenant's group index aggregates it). Install it with --index-url, not --extra-index-url, and pin the version, as described in the Gradle plugin's Python datamodel packages.

TypeScript

The npm package @klok-integration/datamodel-klok-mail-v1 is staged on every release but cannot be installed until a person has published its first version (#2).

What the client must do

  • Give every mail a unique sendKey and write it down before publishing, so a retry is recognised as the same mail.
  • Expect exactly one KlokMailSendResultV1 per sendKey, possibly more than once; deduplicate on sendKey.
  • Deduplicate received mail on providerMessageId.
  • Send from one of the sender addresses or domains configured for the account; anything else comes back REJECTED with SENDER_NOT_ALLOWED.
  • Read htmlBodyOmitted before relying on htmlBody.

Topics

Every topic is tenant klok's and listed in its Pulsar file (pulsar_tenant_klok.yml in klok/environment/klok-environment-setup), with its _DLQ.

Topic Producer Consumer
persistent://klok[_<env>]/mail/KlokMailInboundV1_klokai klok-postmark-ingress KLK006P1 klok-api-mail's routers KLK006P2, KLK006P3, KLK006P4
persistent://klok[_<env>]/mailbox/KlokMailInboundV1_secure klok-api-mail KLK006P2 klok-api-mail's notice KLK006P5; no AI leg
persistent://klok[_<env>]/mailbox/KlokMailInboundV1_svar klok-api-mail KLK006P3 klok-api-mail's notice KLK006P6
persistent://klok[_<env>]/mailbox/KlokMailInboundV1_kollega klok-api-mail KLK006P4 (off until Klok Kollega reads it) Klok Kollega (klok/application/klok-kollega#9)
persistent://klok[_<env>]/mailbox/KlokMailOutboundV1 klok-api-mail KLK006A7, KLK006P5, KLK006P6 klok-postmark-egress KLK006E7
persistent://klok[_<env>]/mail/KlokMailSendResultV1_klokai klok-postmark-egress KLK006E7 klok-api-mail KLK006E8
persistent://klok[_<env>]/mailbox/KlokMailDraftV1_svar klok-api-mail KLK006A13 none yet; open to any klok service

In klok/mail the purpose is the account (the Postmark server); in klok/mailbox it is the reader the mail belongs to. A tenant that follows a mailbox gets consume on its own KlokMailInboundV1_<tenant> when the first one asks (design-mail.md §10).

For the developer of the mail services

klok-postmark-ingress maps Postmark's inbound webhook to KlokMailInboundV1; klok-postmark-egress maps KlokMailOutboundV1 to Postmark's /email request and answers with KlokMailSendResultV1. Postmark's JSON stays inside those two projects. The services must keep the promises this model makes: one result per request, the account taken from the topic, the sender checked against the account, attachments by claim check, and htmlBodyOmitted set when the HTML was dropped. The routes, patterns and configuration are designed in KLK006 section 6.

A Klok Kollega's mail (KLK021)

A mailbox in mode answer or fill lets klok-mail-api send by itself. A reader that shows or audits mail:

  • treats origin KOLLEGA with aiGenerated true as a mail no person read before it went, and shows it as such (the app: Skickat av {name});
  • treats a missing origin as PERSON and a missing aiGenerated as false, which is what every earlier mail means;
  • shows a draft with status ESCALATED first, with its escalationReason (the app: Kollegan behöver dig); a person then sends or drops it as any READY draft, and escalated stays true;
  • treats a value of origin, kollegaMode, mode or escalationReason it does not know as one it does not handle, never as an error.

Producers and consumers

Project Role Record
klok/integration/global/klok-postmark-ingress producer KlokMailInboundV1
klok/integration/global/klok-postmark-egress consumer, producer KlokMailOutboundV1, KlokMailSendResultV1
klok/integration/global/klok-api-mail consumer, producer KlokMailInboundV1 (with mailbox and threadId), KlokMailOutboundV1, KlokMailSendResultV1, KlokMailDraftV1