fix: polish feishu login prompts

maintainer edit: make the Feishu QR login output read like a user flow instead of development logs.
This commit is contained in:
chengyongru
2026-06-18 22:38:06 +08:00
committed by Xubin Ren
parent 08a5f4cbbb
commit 04777bf6f1
+16 -19
View File
@@ -401,7 +401,7 @@ def _poll_registration(
poll_count += 1 poll_count += 1
if poll_count == 1: if poll_count == 1:
print("Fetching configuration results...", end="", flush=True) print("Waiting for authorization", end="", flush=True)
elif poll_count % 6 == 0: elif poll_count % 6 == 0:
print(".", end="", flush=True) print(".", end="", flush=True)
@@ -414,7 +414,7 @@ def _poll_registration(
# Success # Success
if res.get("client_id") and res.get("client_secret"): if res.get("client_id") and res.get("client_secret"):
if poll_count > 0: if poll_count > 0:
print() print(" done.")
return { return {
"app_id": res["client_id"], "app_id": res["client_id"],
"app_secret": res["client_secret"], "app_secret": res["client_secret"],
@@ -435,8 +435,9 @@ def _poll_registration(
time.sleep(interval) time.sleep(interval)
if poll_count > 0: if poll_count > 0:
print() print(" timed out.")
print(f"[Warning] Poll timed out after {expire_in}s") else:
print("Login timed out.")
return None return None
@@ -470,13 +471,15 @@ def _print_qr_code(url: str) -> None:
try: try:
import qrcode as qr_lib import qrcode as qr_lib
print("\nScan this QR code with Feishu or Lark on your phone:\n")
qr = qr_lib.QRCode(border=1) qr = qr_lib.QRCode(border=1)
qr.add_data(url) qr.add_data(url)
qr.make(fit=True) qr.make(fit=True)
qr.print_ascii(invert=True) qr.print_ascii(invert=True)
print("Scan the QR code with Feishu / Lark on your phone to authorize.\n") print()
except ImportError: except ImportError:
print(f"\nLogin URL: {url}\n") print("\nOpen this link with Feishu or Lark on your phone:")
print(f"{url}\n")
def _qr_register_inner( def _qr_register_inner(
@@ -484,10 +487,9 @@ def _qr_register_inner(
initial_domain: str, initial_domain: str,
) -> dict | None: ) -> dict | None:
"""Run init → begin → poll. Raises on network/protocol errors.""" """Run init → begin → poll. Raises on network/protocol errors."""
print("Connecting to Feishu / Lark...", end="", flush=True) print("Preparing Feishu/Lark login...")
_init_registration(initial_domain) _init_registration(initial_domain)
begin = _begin_registration(initial_domain) begin = _begin_registration(initial_domain)
print(" done.")
_print_qr_code(begin["qr_url"]) _print_qr_code(begin["qr_url"])
@@ -578,25 +580,18 @@ class FeishuChannel(BaseChannel):
print() print()
return True return True
print("--- Feishu / Lark QR Login ---") print("Authorize with the mobile app. nanobot will save the new bot credentials.")
print("Open the URL below in Feishu / Lark on your phone to authorize.") print()
print("The platform will create a new bot application automatically.")
result = qr_register(initial_domain=self.config.domain or "feishu") result = qr_register(initial_domain=self.config.domain or "feishu")
if not result: if not result:
self.logger.error( print("Login was not completed. Run 'nanobot channels login feishu --force' to retry.")
"QR registration failed. "
"Run 'nanobot channels login feishu --force' to retry."
)
return False return False
self.config.app_id = result["app_id"] self.config.app_id = result["app_id"]
self.config.app_secret = result["app_secret"] self.config.app_secret = result["app_secret"]
self.config.domain = result.get("domain", "feishu") self.config.domain = result.get("domain", "feishu")
print(f"App ID: {result['app_id']}")
print(f"Domain: {self.config.domain}")
# Write credentials back to config.json # Write credentials back to config.json
from nanobot.config.loader import load_config, save_config from nanobot.config.loader import load_config, save_config
@@ -610,7 +605,9 @@ class FeishuChannel(BaseChannel):
setattr(full_config.channels, "feishu", feishu_cfg) setattr(full_config.channels, "feishu", feishu_cfg)
save_config(full_config) save_config(full_config)
print("Login successful!") print("\nFeishu/Lark login complete.")
print(f"App ID: {result['app_id']}")
print(f"Domain: {self.config.domain}")
return True return True
@staticmethod @staticmethod