Files
nanobot/nanobot/channels/matrix/validation.py
T
chengyongru e8a29a0087 feat(webui): improve setup flows across chat channels (NAN-112) (#5356)
* feat(webui): improve channel setup flows

* fix(webui): refine channel setup interactions (NAN-112)

* fix(webui): keep email setup sections channel-owned

* fix(webui): remove concrete channel details from shared components

* refactor(webui): remove unused channel setup resources

* fix(webui): finish channel-owned setup boundaries

* fix(webui): update channel switches optimistically

* test(channels): remove obsolete absence assertions

* fix(webui): flatten channel instance settings disclosure

* fix(webui): complete channel setup and connection flows

* fix(whatsapp): wait for session database release

* fix(webui): preserve scrolling channel controls

* fix(webui): stage channel connection checks

* fix(channels): align verification actions

* fix(email): expose connection checks

* fix(webui): align channel field actions

* fix(email): verify account credentials

* fix(wecom): bypass system proxy for websocket

* fix(channels): stabilize async connection cleanup

* fix(webui): autosave channel credentials

* fix(email): make provider presets non-destructive

* test(weixin): isolate persisted QR credentials
2026-09-11 15:22:14 +08:00

47 lines
1.6 KiB
Python

"""Matrix setup validation owned by the channel package."""
from typing import Any
from nanobot.channels.contracts import ChannelValidationContext
from nanobot.channels.validation import check, required_checks, status_from_checks, string_value
def validate(values: dict[str, Any], _context: ChannelValidationContext) -> dict[str, Any]:
checks, missing = required_checks("matrix", values)
password = string_value(values.get("password"))
access_token = string_value(values.get("accessToken"))
device_id = string_value(values.get("deviceId"))
if password:
checks.append(check("login", "Login credentials", "pass", "Password login is configured."))
elif access_token and device_id:
checks.append(
check(
"login",
"Login credentials",
"pass",
"Access token login is configured with its device ID.",
)
)
else:
if not password and not access_token:
missing.append("password")
message = "Add a password, or an access token with its device ID."
else:
missing.append("deviceId")
message = "A device ID is required with an access token."
checks.append(check("login", "Login credentials", "fail", message))
checks.append(
check(
"manual_review",
"Matrix account",
"skipped",
"Room access is verified when the channel starts.",
)
)
return status_from_checks("matrix", checks, list(dict.fromkeys(missing)))
__all__ = ["validate"]