orka-gateway-imessage connects Apple Messages to Orka Agents. It implements Orka's orka.gateway.v1 protocol outside Orka core and runs on a Mac that is signed in to Messages.
iPhone ──iMessage──▶ Messages.app ◀── imsg rpc (stdio) ◀── orka-gateway-imessage ──HTTPS──▶ Orka
(chat.db) ▲
└── HTTPS tunnel ◀── Orka deliveries
The adapter starts imsg rpc as a child process, the same bridge OpenClaw uses. imsg watches ~/Library/Messages/chat.db for new messages and sends replies through Messages' AppleScript interface. The adapter adds Orka's protocol, durable state, and a fail-closed allowlist.
A Mac's Messages account is usually a personal account, so the adapter is deliberately narrow:
- Allowlisted senders only.
IMESSAGE_ALLOWED_SENDERSis required. Messages from anyone else are never forwarded to Orka, so Orka never sees them and cannot send a denial reply. - Replies only where you spoke first. A delivery is sent only to a direct chat that produced an admitted inbound message and whose handle is still allowlisted. Group chats are never forwarded or answered, because a group reply reaches every member.
- No history replay. The first start records the newest existing message and begins after it. Every later start resumes from the last processed row, so messages that arrive while the adapter is down are processed and none are skipped. Messages older than 24 hours, Orka's event expiry, are never forwarded.
- No duplicate sends. Deliveries are idempotent in SQLite. A send whose outcome
imsgcannot prove is recorded as unknown and is never retried, even after a restart. - No reply loops. Outgoing messages, including the adapter's own replies, are never forwarded. An inbound message whose text matches an adapter reply to the same chat within two minutes is dropped as an echo.
- Text only. Attachments, reactions, polls, edits, and unsends are not forwarded. Threads are not advertised.
- macOS 14 or later, signed in to Messages with iMessage working.
imsg0.19.0 or later:brew install steipete/tap/imsg.- Permissions for the process that runs the adapter (your terminal app, or the adapter binary under launchd):
- Full Disk Access to read
chat.db. - Automation → Messages to send. Approve it before the first reply; see Run the adapter.
- Full Disk Access to read
- An Orka installation with gateways enabled (the default) and an Agent runtime.
- A public HTTPS URL that forwards to the adapter, such as a Cloudflare Tunnel. Orka delivers only to public HTTPS endpoints.
- Go 1.26 or later to build.
Use a dedicated account: you text it from your phone, and its replies come from that account.
- Create an Apple Account with an email address you control. iMessage works with an email address alone; a phone number works only as the number of an iPhone.
- Add a separate macOS user on the Mac (System Settings → Users & Groups) so your own Messages stay signed in to your account. Log in as that user, open Messages, sign in with the new account, and turn on iMessage for its email address.
- Keep that user logged in (fast user switching is enough) and follow the rest of this guide as that user.
imsgreads that user'schat.dband drives that user's Messages, and the Automation approval is per user. - Allowlist your own handle, and text the new account's email address from your phone.
make check # vet, race tests, script checks
make build # bin/orka-gateway-imessage
make test-orka-compatibility ORKA_DIR=/path/to/orkaThe compatibility test runs Orka's conformance CLI against the adapter twice, before and after a restart, with scripts/fake-imsg standing in for Messages. Nothing is sent.
With Full Disk Access granted to your terminal:
imsg chats --limit 10 --json | jq '{guid, participants, service}'Pick the direct chat you will use; with a dedicated account, text it once first so the chat exists. Its guid (for example iMessage;-;+14155551212, or any;-;+14155551212 on recent macOS) is the Orka contextId, and its handle is the sender. Handles are E.164 phone numbers (+14155551212) or lowercase email addresses.
Run these in one shell, replacing the example values:
export KUBE_CONTEXT=my-cluster
export NAMESPACE=orka-system # the controller's watched namespace
export IMESSAGE_ACCOUNT_ID=my-mac-messages # any stable name for this Messages account
export IMESSAGE_SENDER_ID=+14155551212 # your handle
export IMESSAGE_CHAT_GUID='iMessage;-;+14155551212' # the chat guid from imsg chats
export AGENT_MODEL=your-provider-supported-codex-model
kc() { kubectl --context "${KUBE_CONTEXT}" --namespace "${NAMESPACE}" "$@"; }Create the two bearer tokens in owner-only files outside the repository:
export SECRET_DIR="${HOME}/.config/orka-gateway-imessage"
umask 077
mkdir -p "${SECRET_DIR}"
for direction in inbound outbound; do
file="${SECRET_DIR}/orka-gateway-${direction}-token"
[[ -e "${file}" ]] || openssl rand -hex 32 >"${file}"
kc create secret generic "imessage-gateway-${direction}" --from-file=token="${file}" \
--dry-run=client --output=yaml | kc apply -f -
kc label secret "imessage-gateway-${direction}" "gateway.orka.ai/${direction}-auth=true" \
gateway.orka.ai/gateway-name=imessage --overwrite
kc annotate secret "imessage-gateway-${direction}" gateway.orka.ai/gateway-name=imessage --overwrite
doneExpose the adapter's loopback listener over HTTPS. For a quick test, a Quick Tunnel works; its hostname changes on every restart, so annotate the Secret below again after each one:
cloudflared tunnel --url http://127.0.0.1:8787
export ADAPTER_URL=https://replace-with-generated-host.trycloudflare.comThe adapter posts events to Orka's API. When the API is not public, forward it to loopback; plaintext HTTP is accepted only for loopback. The API Service is orka-api in a kustomize install and orka in a Helm install:
kc port-forward service/orka-api 8081:8080 & # or service/orka for HelmApprove Automation before Orka sends anything. A send waits on the macOS prompt, and a send that outlasts SEND_TIMEOUT is recorded as unknown and never retried, so a reply that runs into the prompt is lost. In the terminal app that will run the adapter, run this and click Allow; it then prints a number:
osascript -e 'tell application "Messages" to get count of accounts'Start the adapter in another shell with the same variables:
make build
IMESSAGE_ALLOWED_SENDERS="${IMESSAGE_SENDER_ID}" \
ORKA_GATEWAY_INGRESS_URL="http://127.0.0.1:8081/api/v1/gateways/${NAMESPACE}/imessage/events" \
ORKA_GATEWAY_INBOUND_TOKEN_FILE="${SECRET_DIR}/orka-gateway-inbound-token" \
ORKA_GATEWAY_OUTBOUND_TOKEN_FILE="${SECRET_DIR}/orka-gateway-outbound-token" \
./bin/orka-gateway-imessageThen point Orka at the tunnel and bind the chat to an Agent:
kc apply -f deploy/cluster/gatewayclass.yaml # cluster-scoped; reuse if already installed
kc annotate secret imessage-gateway-outbound \
gateway.orka.ai/adapter-endpoint="${ADAPTER_URL}" --overwrite
./scripts/render-routing.sh | kc apply -f -render-routing.sh creates Agent/imessage-ai (a Codex orka.harness.v2 Agent), Gateway/imessage, and GatewayBinding/imessage-ai. The binding admits only IMESSAGE_SENDER_ID in IMESSAGE_CHAT_GUID and queues messages while a turn runs. It validates every value before rendering.
Use fully qualified resource names: on clusters with the Kubernetes Gateway API installed, gatewayclass and gateway resolve to that API instead of Orka's.
kc get gatewayclasses.gateway.orka.ai imessage-chat
kc get gateways.gateway.orka.ai/imessage gatewaybindings.gateway.orka.ai/imessage-aiBoth should report ready once Orka reaches the adapter through the tunnel. Then send a message to the Mac from the allowlisted handle. The adapter logs forwarded iMessage to Orka, the Agent runs, and the reply arrives in the same chat:
kc get gatewaybindings.gateway.orka.ai/imessage-ai \
-o 'jsonpath={.status.lastInboundActivity}{" -> "}{.status.lastOutboundActivity}{"\n"}'Run with LOG_LEVEL=debug to see why a message was skipped. Logs never contain message text.
| Variable | Default | Purpose |
|---|---|---|
IMESSAGE_ACCOUNT_ID |
required | Orka accountId for this Messages account |
IMESSAGE_ALLOWED_SENDERS |
required | Comma-separated handles allowed to reach Orka and receive replies |
IMESSAGE_CONFORMANCE_CHAT_GUID |
empty | Allowlisted direct chat that receives Orka conformance probe sends |
ORKA_GATEWAY_INGRESS_URL |
required | .../api/v1/gateways/<namespace>/imessage/events |
ORKA_GATEWAY_INBOUND_TOKEN[_FILE] |
required | Token the adapter sends to Orka |
ORKA_GATEWAY_OUTBOUND_TOKEN[_FILE] |
required | Token Orka sends to the adapter; must differ from the inbound token |
LISTEN_ADDRESS |
127.0.0.1:8787 |
Adapter listener for the tunnel |
DATABASE_PATH |
~/Library/Application Support/orka-gateway-imessage/adapter.db |
Durable cursor, reply chats, and deliveries |
IMSG_PATH |
imsg |
imsg executable |
IMSG_DB_PATH |
empty | Alternate Messages database passed to imsg rpc --db |
SEND_TIMEOUT |
60s |
Upper bound for one imsg send |
REQUEST_TIMEOUT |
15s |
Orka ingress request timeout |
SHUTDOWN_TIMEOUT |
20s |
Graceful shutdown deadline |
LOG_LEVEL |
info |
debug, info, warn, or error |
The adapter serves GET /healthz and GET /readyz without authentication, and the protocol routes GET /v1/health, GET /v1/capabilities, and POST /v1/deliveries with the outbound token. It advertises interim delivery, so Agents can post progress updates with reply_in_conversation.
The ROWID cursor belongs to one Messages database. If chat.db is replaced or restored, stop the adapter and delete its database before restarting so it records the newest message again. Delivery records are not pruned.
- Build and install the binary somewhere stable, for example
~/.local/bin/orka-gateway-imessage. - Copy
deploy/launchd/ai.orka.gateway-imessage.plistto~/Library/LaunchAgents/and replace everyREPLACE_WITH_*value. - Grant Full Disk Access to the installed adapter binary. Under launchd it, not your terminal, is the process macOS checks for
imsg. - Under launchd the adapter binary needs its own Automation approval, which macOS requests on its first send, so text it once while you are at the Mac and click Allow promptly. If the prompt outlasts
SEND_TIMEOUT, that reply is recorded as unknown and never retried. To load it:
launchctl bootstrap "gui/$(id -u)" ~/Library/LaunchAgents/ai.orka.gateway-imessage.plist
launchctl kickstart -k "gui/$(id -u)/ai.orka.gateway-imessage"Keep the tunnel running too, for example as a cloudflared service with a named tunnel, and keep the Mac awake.
launchctl bootout "gui/$(id -u)/ai.orka.gateway-imessage" 2>/dev/null || true
kc delete gatewaybindings.gateway.orka.ai/imessage-ai gateways.gateway.orka.ai/imessage \
agents.core.orka.ai/imessage-ai --ignore-not-found
kc delete secret/imessage-gateway-inbound secret/imessage-gateway-outbound --ignore-not-foundThis keeps the shared GatewayClass/imessage-chat. Stop cloudflared and the port-forward too. To remove local state, delete the adapter's database directory (the default DATABASE_PATH location) and the token files:
rm -rf "${HOME}/Library/Application Support/orka-gateway-imessage" "${SECRET_DIR}"