Connecting Postduif

Not proven. No real Postduif agent has connected to Karta; the connection is tested against a test double that follows the protocol as written, and the protocol (postduif.v1) is a draft that may still change. It has not run behind the production proxy.

Postduif is a small program that runs on the shop's own computer. It links the shop's WhatsApp number (the shop scans a QR code with the phone, as for any linked device), keeps a durable journal of everything it receives until Karta has confirmed it, and holds one outgoing WebSocket to Karta. Karta tells it what to do (send, check a number, start linking); it performs and reports. It never decides anything itself: the limits, the retries and the fallback are Karta's. The wire protocol between the two is postduif.v1, written down in protocol/postduif-protocol.md of the Karta repository.

WhatsApp's client protocol used by Postduif is unofficial; Meta's terms say it can lead to a number being suspended. The number at stake is the shop's own. Use it for the shop's own conversations and for updates to customers who have a chat; Karta has no bulk features and enforces limits.

Make the connector

In the console under the mail server, Connectors, kind postduif, a name, Make the connector; or POST /messaging/v1/connectors:

curl -sS https://karta.example/messaging/v1/connectors \
  -H "Authorization: Bearer $KARTA_KEY" -H 'Content-Type: application/json' \
  -d '{"plug": "postduif", "name": "Winkel Kralendijk"}'

The answer (and the page) shows the one-time code, pdt_ and 43 characters, once. Karta keeps only its SHA-256; it is valid 24 hours and works once.

Enrol the agent

On the shop's computer, enter Karta's address and the code in Postduif's page. Postduif makes its own Ed25519 key (the private half never leaves the computer) and calls POST /messaging/v1/enrol with the code and the public key. Karta answers with the connector's id, the WebSocket address and the key's fingerprint, SHA256: and the unpadded base64 of the SHA-256 of the raw public key (the way OpenSSH shows a key). Postduif shows the same value: compare it with the one on the connector's page. If they differ, someone else holds the code: revoke the connector.

Postduif connects with wss://karta.example/messaging/v1/connect (subprotocol postduif.v1), proves it holds the key with a signature over a challenge Karta sends, and Karta answers welcome with the contract versions both support and all the settings. The connector turns Connected or Needs link. To link WhatsApp, press Link WhatsApp on the page (or POST /messaging/v1/connectors/:id/link): Postduif shows a QR code on the shop computer (never sent to Karta), the shop scans it from the phone (WhatsApp, Linked devices), and the connector turns Connected. From then on a send through the API reaches the phone and what the customer writes reaches Karta.

What the statuses mean

StatusMeaning
NewMade; nobody has enrolled yet.
EnrolledEnrolled, never connected.
ConnectedThe agent is connected and WhatsApp is linked.
OfflineThe agent is not connected (the computer is off, no network), or WhatsApp is unreachable from it. Messages wait up to their time limit.
Needs linkThe agent is connected, but the number is not linked, or was logged out.
Needs updateThe agent is older than the minimum, or WhatsApp's protocol moved on.
RevokedThe agent's key no longer works.

A connector that goes offline, or needs linking, is announced by a webhook event (messaging.connector.disconnected, .needs_link), so the application can tell the shop.

When the computer is off

WhatsApp keeps messages for a linked device that is switched off and delivers them when it comes back; for how long is WhatsApp's rule, not Karta's. Messages that arrive that way are stored once each, flagged offline. Commands for an agent that is not connected wait in the outbox until their time limit (wait_for_connector_s of the send request, default 120 s), and are then treated as not sent. A message whose outcome the agent cannot tell (it stopped during the send) becomes unknown and is never sent again by Karta; the application decides.

Replacing a computer, a lost agent, revoking

  • New one-time code (the page, or POST /messaging/v1/connectors/:id/enrolment) lets a new installation replace the old agent. Until it enrols, the old one keeps working; afterwards the old key is refused.
  • Revoke disconnects the agent at once (close code 4002) and refuses its key. Commands it never acknowledged expire.
  • Remove deletes the connector with its conversations, messages and files.

Updates

Karta tells the agent in welcome which version is current and the address of the signed update manifest; the agent updates itself. Karta can say this agent is too old (KARTA_MESSAGING_MIN_AGENT_VERSION, close code 4005), and WhatsApp protocol changes surface as Needs update.

What Karta has not been shown against

This version of Karta was tested against a test double of the agent that speaks the protocol, not against the real Postduif. The first real connection is the acceptance test: enrol, compare the fingerprint, link a spare phone, send and receive one message, restart both sides.