Add the optional messaging module: connectors, API, agent connection, console #91

Merged
calvin merged 10 commits from messaging into master 2026-11-13 06:21:16 +00:00
Owner

What

An optional messaging module (/messaging/v1, KARTA_MESSAGING=1, off by default) for conversations over WhatsApp and SMS: connectors, conversations, messages and files; an HTTP API (send with an idempotency key, read, check a recipient, upload files, connectors, settings); signed webhook events; the remote-connector WebSocket for Postduif (postduif.v1: one-time code enrolment, Ed25519 proof on connect, commands with acknowledgements, events with cursors applied exactly once, resume, several replicas with or without KARTA_CLUSTER); console pages (connectors, an archive of conversations searched by number, settings); retention (default 730 days, per organisation; sign-in codes 7 days at most); messages encrypted at rest; metrics; guides.

This is milestone 3 of the plan. The Bird SMS plug (M4) and fallback routing with the guard rails (M5) follow in their own pull requests.

Off means off

With the module off Karta behaves as before: every /messaging/v1 path and every messaging page answers as an unknown route, no menu entries, no new API key scope, no webhook event choices, no Oban queue or cron job, no PromEx plugin, no process. The migration only adds new tables (nothing existing is altered). Tested in test/karta_web/messaging/off_test.exs.

Webhooks

Messaging events are a separate list (Catalogue.messaging_types/0). A webhook with no event list receives no messaging event; it must name them. Tested in webhook_events_test.exs. The v2 webhook OpenAPI enum now lists the messaging types (accepted by POST/PATCH /api/v2/webhooks).

Protocol

The contract is postduif-protocol.md (copy in protocol/). I implemented it exactly and appended a dated "Proposed change 1" (12 clarifications: fingerprint algorithm, key encoding, host in the proof, what is resent on resume, ack over gaps, bye before close, ...) to the original, without a version bump.

Tests

154 tests and 3 properties in the messaging suites: a real WebSocket test double of the agent (test/support/messaging/test_agent.ex) covers enrol, connect, inbound events (redelivery, out-of-order cursors, history), send, acknowledgements, statuses, a connection that drops mid-command and resumes, replacement, revocation, heartbeats, back-pressure; plus the API, tenancy, retention (blob before row), console, OpenAPI and off-state suites. mix format, mix credo --strict, mix compile --warnings-as-errors and mix docs are clean.

Not proven

No real Postduif has connected (the test double speaks the contract as written). WebSocket behind Traefik is standard Bandit WebSock and was not run here. The notes for enabling it on live are in docs/suite/release-1.0/karta-messaging.md.

🤖 Generated with Claude Code

## What An optional **messaging module** (`/messaging/v1`, `KARTA_MESSAGING=1`, off by default) for conversations over WhatsApp and SMS: connectors, conversations, messages and files; an HTTP API (send with an idempotency key, read, check a recipient, upload files, connectors, settings); signed webhook events; the **remote-connector WebSocket** for Postduif (`postduif.v1`: one-time code enrolment, Ed25519 proof on connect, commands with acknowledgements, events with cursors applied exactly once, resume, several replicas with or without `KARTA_CLUSTER`); console pages (connectors, an archive of conversations searched by number, settings); retention (default 730 days, per organisation; sign-in codes 7 days at most); messages encrypted at rest; metrics; guides. This is milestone 3 of the plan. The Bird SMS plug (M4) and fallback routing with the guard rails (M5) follow in their own pull requests. ## Off means off With the module off Karta behaves as before: every `/messaging/v1` path and every messaging page answers as an unknown route, no menu entries, no new API key scope, no webhook event choices, no Oban queue or cron job, no PromEx plugin, no process. The migration only adds new tables (nothing existing is altered). Tested in `test/karta_web/messaging/off_test.exs`. ## Webhooks Messaging events are a separate list (`Catalogue.messaging_types/0`). A webhook with no event list receives **no** messaging event; it must name them. Tested in `webhook_events_test.exs`. The v2 webhook OpenAPI enum now lists the messaging types (accepted by `POST/PATCH /api/v2/webhooks`). ## Protocol The contract is `postduif-protocol.md` (copy in `protocol/`). I implemented it exactly and appended a dated "Proposed change 1" (12 clarifications: fingerprint algorithm, key encoding, host in the proof, what is resent on resume, ack over gaps, `bye` before close, ...) to the original, without a version bump. ## Tests 154 tests and 3 properties in the messaging suites: a real WebSocket test double of the agent (`test/support/messaging/test_agent.ex`) covers enrol, connect, inbound events (redelivery, out-of-order cursors, history), send, acknowledgements, statuses, a connection that drops mid-command and resumes, replacement, revocation, heartbeats, back-pressure; plus the API, tenancy, retention (blob before row), console, OpenAPI and off-state suites. `mix format`, `mix credo --strict`, `mix compile --warnings-as-errors` and `mix docs` are clean. ## Not proven No real Postduif has connected (the test double speaks the contract as written). WebSocket behind Traefik is standard Bandit WebSock and was not run here. The notes for enabling it on live are in `docs/suite/release-1.0/karta-messaging.md`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
An optional module (KARTA_MESSAGING) with connectors, conversations,
messages and media, the remote-connector WebSocket (postduif.v1), the
HTTP API and the webhook events, with a test double of the agent.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Merge remote-tracking branch 'origin/master' into messaging
Some checks failed
ci/woodpecker/pr/woodpecker Pipeline failed
113ffb33ff
Format the messaging connect test
Some checks failed
ci/woodpecker/pr/woodpecker Pipeline failed
c339aab79a
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Mark the media downloads for sobelow, with the reason
Some checks failed
ci/woodpecker/pr/woodpecker Pipeline failed
bfbdf14e45
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Keep the sobelow notes within credo's line length
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
cbe1baa69f
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Fix the review findings in the messaging module (S1, S7, S8, S9 and the notes)
Some checks failed
ci/woodpecker/pr/woodpecker Pipeline was canceled
68de389b7d
The messaging event names are not accepted or listed while the module is off;
the text stays out of the webhook events by default; the large body limit is
for the media route only; the protocol copy is the whole document; resume never
pushes more than 100 commands; a late answer to an expired command flags a
possible duplicate; retention goes on past a file it cannot delete; a file is
attached once, by its own connector; the agent's bye reason is kept.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Copy the whole protocol document, with the answer to change 2
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
a5389eac61
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
calvin merged commit 5fd5cdb94a into master 2026-11-13 06:21:16 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
external/karta!91
No description provided.