gateway: run simplex-chat in bot mode, not relay/headless

In v7 --headless means "chat relay" (requires --relay) and yields a relay
address, not a user contact address, so the bot could not be added as a
contact. Run bot mode instead (-p PORT --create-bot-display-name), which needs
no TTY and is restart-safe. simplex-address.py now creates the user contact
address on first run (/_address + /_show_address), and bootstrap invokes it
after the services start and prints the link.
This commit is contained in:
Denton Social committed 2026-09-26 18:33:57 -05:00
1 parent 5ee3905aec
commit 6059bec1e4
4 files changed
+67 -29

No files matched your search

+24 -14
View File
@@ -1,10 +1,12 @@
#!/usr/bin/env python3
"""Print the SimpleX bot's contact address from the running gateway daemon.
"""Print (creating if needed) the SimpleX bot's contact address.
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.
The gateway talks to a local `simplex-chat` daemon running as a bot
(`--create-bot-display-name`, see simplex_chat in config.json). To connect a
phone/client to the bot you need the bot's *user* contact address, not a chat
relay address; this queries the daemon's WebSocket API, creating the address on
first run, 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]
@@ -29,18 +31,26 @@ def _ws_url(config_path: str) -> str:
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:
async def _resolve(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 {}
async def cmd(command: str) -> dict:
await ws.send(json.dumps({"corrId": "addr", "cmd": command}))
raw = await asyncio.wait_for(ws.recv(), timeout=20)
return json.loads(raw).get("resp", {}) or {}
resp = await cmd(f"/_show_address {user_id}")
if resp.get("type") == "userContactLink":
return resp.get("contactLink", {}) or {}
# No address yet -> create one (APICreateMyAddress).
resp = await cmd(f"/_address {user_id}")
if resp.get("type") == "userContactLinkCreated":
return {"connLinkContact": resp.get("connLinkContact", {}) or {}}
raise SystemExit(f"could not read or create address: {json.dumps(resp)[:300]}")
def main() -> int:
@@ -52,7 +62,7 @@ def main() -> int:
ws_url = args.ws_url or _ws_url(args.config)
try:
link = asyncio.run(_show(ws_url, args.user_id))
link = asyncio.run(_resolve(ws_url, args.user_id))
except OSError as exc:
print(f"cannot reach simplex-chat at {ws_url}: {exc}", file=sys.stderr)
return 1
@@ -60,7 +70,7 @@ def main() -> int:
print(f"simplex-chat at {ws_url} did not answer", file=sys.stderr)
return 1
conn = link.get("connLinkContact", {}) or {}
conn = link.get("connLinkContact", {}) or link
short = conn.get("connShortLink")
full = conn.get("connFullLink")
if short: