mirror of
https://github.com/kuhyx/signal-bot.git
synced 2026-11-10 18:17:02 +01:00
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
# Copyright (c) 2026 Krzysztof Rudnicki. MIT licence.
|
|
"""A protocol-faithful fake of signal-cli-rest-api.
|
|
|
|
Serves the exact surface the bot uses, so the unmodified bot connects to it
|
|
by pointing API_BASE_URL at this process. A real local Signal server is not
|
|
achievable -- signal-cli compiles its endpoints and trust store in, and
|
|
Signal-Server needs FoundationDB, DynamoDB and Redis -- so faking this
|
|
boundary is the only way to exercise every feature without a real account.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
from fastapi import FastAPI
|
|
|
|
from fake_signal.routes_account import build_account_router
|
|
from fake_signal.routes_api import build_api_router
|
|
from fake_signal.routes_control import build_control_router
|
|
from fake_signal.routes_fixtures import build_fixture_router
|
|
from fake_signal.routes_groups import build_group_router
|
|
from fake_signal.state import State
|
|
|
|
|
|
def create_app(state: State | None = None) -> FastAPI:
|
|
"""Build the fake server, optionally sharing an existing State."""
|
|
app = FastAPI(title="fake-signal-cli-rest-api")
|
|
app.state.fake = state if state is not None else State()
|
|
app.include_router(build_api_router())
|
|
app.include_router(build_account_router())
|
|
app.include_router(build_group_router())
|
|
app.include_router(build_fixture_router())
|
|
app.include_router(build_control_router())
|
|
return app
|
|
|
|
|
|
def default_state() -> State:
|
|
"""State whose self-URL matches the port the e2e script binds."""
|
|
host = os.getenv("FAKE_HOST", "127.0.0.1")
|
|
port = os.getenv("FAKE_PORT", "8099")
|
|
return State(base_url=f"http://{host}:{port}")
|
|
|
|
|
|
app = create_app(default_state())
|