feat: add feishu api notification services
This commit is contained in:
55
review_agent/notifications/recipient.py
Normal file
55
review_agent/notifications/recipient.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ResolvedFeishuTarget:
|
||||
ok: bool
|
||||
identifier_type: str
|
||||
identifier_value: str
|
||||
display_name: str
|
||||
masked_identifier: str
|
||||
error_code: str = ""
|
||||
error_message: str = ""
|
||||
|
||||
|
||||
def mask_identifier(value: str) -> str:
|
||||
if not value:
|
||||
return ""
|
||||
if len(value) <= 8:
|
||||
return value[:2] + "***"
|
||||
return f"{value[:4]}***{value[-4:]}"
|
||||
|
||||
|
||||
def resolve_configured_personal_recipient() -> ResolvedFeishuTarget:
|
||||
open_id = getattr(settings, "FEISHU_DEFAULT_USER_OPEN_ID", "")
|
||||
user_id = getattr(settings, "FEISHU_DEFAULT_USER_ID", "")
|
||||
display_name = getattr(settings, "FEISHU_DEFAULT_TARGET_NAME", "默认飞书接收人")
|
||||
if open_id:
|
||||
return ResolvedFeishuTarget(
|
||||
ok=True,
|
||||
identifier_type="open_id",
|
||||
identifier_value=open_id,
|
||||
display_name=display_name,
|
||||
masked_identifier=mask_identifier(open_id),
|
||||
)
|
||||
if user_id:
|
||||
return ResolvedFeishuTarget(
|
||||
ok=True,
|
||||
identifier_type="user_id",
|
||||
identifier_value=user_id,
|
||||
display_name=display_name,
|
||||
masked_identifier=mask_identifier(user_id),
|
||||
)
|
||||
return ResolvedFeishuTarget(
|
||||
ok=False,
|
||||
identifier_type="missing",
|
||||
identifier_value="",
|
||||
display_name=display_name,
|
||||
masked_identifier="",
|
||||
error_code="recipient_missing",
|
||||
error_message="未配置 FEISHU_DEFAULT_USER_OPEN_ID 或 FEISHU_DEFAULT_USER_ID",
|
||||
)
|
||||
Reference in New Issue
Block a user