ForcePilot/backend/package/yuxi/channels/adapters/slack/modals.py
Kris a2aa782b86 feat(slack adapter): 实现完整的Slack频道适配器基础功能
新增Slack适配器全套核心模块,包括消息处理流水线、会话管理、配置适配、权限控制等完整功能:
1. 新增语音、视觉相关的TTS和图像分析导出接口
2. 实现消息预处理、路由、线程上下文处理的完整流水线
3. 新增账号管理、缓存机制、房间上下文提取功能
4. 支持Webhook和Socket Mode两种事件接收方式
5. 实现权限白名单、审批配对、自动状态管理功能
6. 新增配置迁移、作用域校验、重连策略等辅助模块
2026-05-12 00:48:57 +08:00

107 lines
2.7 KiB
Python

from __future__ import annotations
from typing import Any
def build_modal(
title: str,
*blocks: dict[str, Any],
submit_text: str = "提交",
close_text: str = "取消",
callback_id: str = "",
clear_on_close: bool = False,
notify_on_close: bool = False,
external_id: str = "",
) -> dict[str, Any]:
view: dict[str, Any] = {
"type": "modal",
"title": {"type": "plain_text", "text": title},
"blocks": list(blocks),
"submit": {"type": "plain_text", "text": submit_text},
"close": {"type": "plain_text", "text": close_text},
}
if callback_id:
view["callback_id"] = callback_id
if clear_on_close:
view["clear_on_close"] = True
if notify_on_close:
view["notify_on_close"] = True
if external_id:
view["external_id"] = external_id
return view
def build_home_tab(
*blocks: dict[str, Any],
callback_id: str = "",
external_id: str = "",
) -> dict[str, Any]:
view: dict[str, Any] = {
"type": "home",
"blocks": list(blocks),
}
if callback_id:
view["callback_id"] = callback_id
if external_id:
view["external_id"] = external_id
return view
def build_confirmation_dialog(
title: str,
text: str,
confirm_text: str = "确认",
deny_text: str = "取消",
style: str = "",
) -> dict[str, Any]:
dialog: dict[str, Any] = {
"title": {"type": "plain_text", "text": title},
"text": {"type": "mrkdwn", "text": text},
"confirm": {"type": "plain_text", "text": confirm_text},
"deny": {"type": "plain_text", "text": deny_text},
}
if style in ("primary", "danger"):
dialog["style"] = style
return dialog
def build_view_error_section(message: str) -> list[dict[str, Any]]:
return [
{
"type": "section",
"text": {"type": "mrkdwn", "text": f":warning: *错误*\n>{message}"},
},
]
def build_approval_modal(
title: str,
detail: str,
exec_command: str = "",
callback_id: str = "exec_approval",
) -> dict[str, Any]:
blocks = [
{
"type": "section",
"text": {"type": "mrkdwn", "text": f"*{title}*\n\n{detail}"},
},
{"type": "divider"},
]
if exec_command:
blocks.append(
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"```{exec_command}```",
},
}
)
return build_modal(
"Exec 审批",
*blocks,
submit_text="确认执行",
close_text="取消",
callback_id=callback_id,
)