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

+22 -2
View File
@@ -319,6 +319,25 @@ if command -v systemctl >/dev/null 2>&1; then
fi
fi
# --- stage 8b: SimpleX bot contact address -------------------------------------------
SIMPLEX_ADDRESS=""
if command -v systemctl >/dev/null 2>&1; then
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
if systemctl --user is-active --quiet semif-simplex.service 2>/dev/null; then
echo "== ensuring the SimpleX bot contact address exists"
for _ in 1 2 3 4 5 6 7 8 9 10; do
if SIMPLEX_ADDRESS="$("$PYTHON" "$REPO_ROOT/scripts/simplex-address.py" 2>/dev/null)"; then
printf '%s\n' "$SIMPLEX_ADDRESS" | sed 's/^/ /'
break
fi
sleep 2
done
if [[ -z "$SIMPLEX_ADDRESS" ]]; then
echo "WARN: bot address not ready; run: $PYTHON scripts/simplex-address.py" >&2
fi
fi
fi
# --- stage 9: optional data copy -----------------------------------------------------
if [[ -n "$COPY_DATA" ]]; then
echo "== rsync data from $COPY_DATA"
@@ -365,12 +384,13 @@ Done. Next steps:
HF_HOME="$HF_CACHE" "$PYTHON" -m semif_agent.cli dashboard --port 8765
SimpleX gateway:
- The bot runs as systemd user services 'semif-simplex' (daemon, port $SIMPLEX_PORT) and
- The bot runs as systemd user services 'semif-simplex' (bot daemon, port $SIMPLEX_PORT) and
'semif-gateway' (agent). Check them with:
systemctl --user status semif-simplex semif-gateway
journalctl --user -u semif-gateway -f
- Show the bot's contact address (add it as a contact in your SimpleX app):
- Its user contact address is printed above; re-print (creating if needed) with:
"$PYTHON" scripts/simplex-address.py
Add that address as a contact in your SimpleX app.
- Then put your contactId/display name in config.json
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
+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:
+5 -2
View File
@@ -1,11 +1,14 @@
[Unit]
Description=SemIf agent SimpleX Chat daemon
Description=SemIf agent SimpleX Chat bot daemon
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
ExecStart=@REPO@/.runtime/bin/simplex-chat -p @PORT@ -d @REPO@/.runtime/simplex/simplex_v1 -k "" --relay --headless --user-display-name "@DISPLAY_NAME@"
# Bot mode: a local WebSocket chat server with a bot user. Do NOT add
# --headless here — in SimpleX Chat v7 --headless means "chat relay" and
# requires --relay, which yields a relay address, not a user contact address.
ExecStart=@REPO@/.runtime/bin/simplex-chat -p @PORT@ -d @REPO@/.runtime/simplex/simplex_v1 -k "" --create-bot-display-name "@DISPLAY_NAME@"
Restart=always
RestartSec=10
StandardOutput=journal