gateway: add simplex-address helper for onboarding
The daemon does not print its contact address; query /_show_address over the WebSocket API. scripts/simplex-address.py reads ws_url from config.json and prints the bot's short/full contact link so a human can add it in their SimpleX app. bootstrap.sh points at it in the next-steps hint.
This commit is contained in:
1 parent
5df560a922
commit
756d4b47b7
3 files changed
+84
-2
No files matched your search
@@ -578,6 +578,10 @@ unit tests (24) + box integration tests (2).
|
|||||||
logout/reboot. The gateway is its own process — the REPL and the gateway are
|
logout/reboot. The gateway is its own process — the REPL and the gateway are
|
||||||
independent front ends onto the same on-disk logs/registry (do not run two
|
independent front ends onto the same on-disk logs/registry (do not run two
|
||||||
scheduler processes over one skill store concurrently).
|
scheduler processes over one skill store concurrently).
|
||||||
|
- **Bot address.** `python scripts/simplex-address.py` queries the running
|
||||||
|
daemon for the bot's contact link (`/_show_address <userId>`), which a human
|
||||||
|
adds in their SimpleX app to start a DM. `bootstrap.sh` prints this hint; the
|
||||||
|
address is created automatically on the daemon's first `--headless` run.
|
||||||
- **Transport contract** (`gateway/base.py`): `GatewayAdapter.run(on_inbound,
|
- **Transport contract** (`gateway/base.py`): `GatewayAdapter.run(on_inbound,
|
||||||
outbound_queue)` blocks, delivering `InboundMessage`s and draining a stdlib
|
outbound_queue)` blocks, delivering `InboundMessage`s and draining a stdlib
|
||||||
`queue.Queue[OutboundMessage | None]`. Scheduler work is synchronous and can
|
`queue.Queue[OutboundMessage | None]`. Scheduler work is synchronous and can
|
||||||
|
|||||||
@@ -369,8 +369,9 @@ SimpleX gateway:
|
|||||||
'semif-gateway' (agent). Check them with:
|
'semif-gateway' (agent). Check them with:
|
||||||
systemctl --user status semif-simplex semif-gateway
|
systemctl --user status semif-simplex semif-gateway
|
||||||
journalctl --user -u semif-gateway -f
|
journalctl --user -u semif-gateway -f
|
||||||
- Add this bot as a contact in your SimpleX app (its address is printed by the
|
- Show the bot's contact address (add it as a contact in your SimpleX app):
|
||||||
daemon), then put your contactId/display name in config.json
|
"$PYTHON" scripts/simplex-address.py
|
||||||
|
- Then put your contactId/display name in config.json
|
||||||
gateway.simplex.allowed_users (discover the id from a 'gateway_denied' trace
|
gateway.simplex.allowed_users (discover the id from a 'gateway_denied' trace
|
||||||
event or the daemon's /contacts) and reply. With an empty allowlist the
|
event or the daemon's /contacts) and reply. With an empty allowlist the
|
||||||
gateway rejects everyone — that is the safe default.
|
gateway rejects everyone — that is the safe default.
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Print the SimpleX bot's contact address from the running gateway daemon.
|
||||||
|
|
||||||
|
The gateway talks to a local `simplex-chat` daemon (see simplex_chat in
|
||||||
|
config.json). To connect a phone/client to the bot you need the bot's contact
|
||||||
|
address; this queries it over the daemon's WebSocket API and prints the short
|
||||||
|
link (and full link). Requires the daemon to be running.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
.runtime/venv/bin/python scripts/simplex-address.py [--config config.json]
|
||||||
|
[--ws-url ws://...]
|
||||||
|
[--user-id 1]
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import asyncio
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def _ws_url(config_path: str) -> str:
|
||||||
|
try:
|
||||||
|
with open(config_path) as fh:
|
||||||
|
cfg = json.load(fh)
|
||||||
|
except (OSError, ValueError):
|
||||||
|
return "ws://127.0.0.1:5226"
|
||||||
|
return str(cfg.get("gateway", {}).get("simplex", {}).get("ws_url") or "ws://127.0.0.1:5226")
|
||||||
|
|
||||||
|
|
||||||
|
async def _show(ws_url: str, user_id: int) -> dict:
|
||||||
|
try:
|
||||||
|
import websockets
|
||||||
|
except ImportError:
|
||||||
|
raise SystemExit("the `websockets` package is required (pip install websockets)")
|
||||||
|
async with websockets.connect(ws_url, max_size=None) as ws:
|
||||||
|
await ws.send(json.dumps({"corrId": "addr", "cmd": f"/_show_address {user_id}"}))
|
||||||
|
raw = await asyncio.wait_for(ws.recv(), timeout=10)
|
||||||
|
resp = json.loads(raw).get("resp", {}) or {}
|
||||||
|
if resp.get("type") != "userContactLink":
|
||||||
|
raise SystemExit(f"could not read address: {json.dumps(resp)[:300]}")
|
||||||
|
return resp.get("contactLink", {}) or {}
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
ap = argparse.ArgumentParser(description=__doc__)
|
||||||
|
ap.add_argument("--config", default="config.json")
|
||||||
|
ap.add_argument("--ws-url", default=None)
|
||||||
|
ap.add_argument("--user-id", type=int, default=1)
|
||||||
|
args = ap.parse_args()
|
||||||
|
|
||||||
|
ws_url = args.ws_url or _ws_url(args.config)
|
||||||
|
try:
|
||||||
|
link = asyncio.run(_show(ws_url, args.user_id))
|
||||||
|
except OSError as exc:
|
||||||
|
print(f"cannot reach simplex-chat at {ws_url}: {exc}", file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
print(f"simplex-chat at {ws_url} did not answer", file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
conn = link.get("connLinkContact", {}) or {}
|
||||||
|
short = conn.get("connShortLink")
|
||||||
|
full = conn.get("connFullLink")
|
||||||
|
if short:
|
||||||
|
print(short)
|
||||||
|
if full:
|
||||||
|
print(full)
|
||||||
|
if not (short or full):
|
||||||
|
print("no contact address found", file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
raise SystemExit(main())
|
||||||
Reference in new issue
Block a user