实现了 Teams 机器人所需的全功能组件,包括: - 基础命令解析与帮助卡片生成 - 租户验证与访问控制 - 自定义 UA 与媒体工具 - 消息分块、批注处理与会话管理 - 防抖、缓存与配置路由能力 - 投票、配对、审计与运行时状态管理 - TTS 语音合成与卡片构建工具 - 群组管理与权限控制逻辑
87 lines
2.3 KiB
Python
87 lines
2.3 KiB
Python
"""Microsoft Teams 欢迎卡片。
|
|
|
|
在 Bot 被添加到个人或群组对话时发送欢迎卡片,支持自定义 prompt starters。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
|
|
def build_personal_welcome_card(
|
|
bot_name: str = "ForcePilot",
|
|
subtitle: str = "你好!我是你的智能助手,可以帮你回答问题、处理数据、管理任务。",
|
|
prompt_starters: list[str] | None = None,
|
|
) -> dict[str, Any]:
|
|
starters = prompt_starters or [
|
|
"你能做什么?",
|
|
"帮我总结今天的要点",
|
|
"查看我的会话上下文",
|
|
]
|
|
|
|
body: list[dict[str, Any]] = [
|
|
{
|
|
"type": "TextBlock",
|
|
"size": "Large",
|
|
"weight": "Bolder",
|
|
"text": f"欢迎使用 {bot_name}",
|
|
},
|
|
{
|
|
"type": "TextBlock",
|
|
"text": subtitle,
|
|
"wrap": True,
|
|
"spacing": "Medium",
|
|
},
|
|
{
|
|
"type": "TextBlock",
|
|
"text": "试试这些:",
|
|
"spacing": "Medium",
|
|
"isSubtle": True,
|
|
},
|
|
]
|
|
|
|
for i, starter in enumerate(starters[:3]):
|
|
body.append(
|
|
{
|
|
"type": "TextBlock",
|
|
"text": f"{i + 1}. {starter}",
|
|
"wrap": True,
|
|
"spacing": "Small",
|
|
}
|
|
)
|
|
|
|
return {
|
|
"type": "AdaptiveCard",
|
|
"version": "1.5",
|
|
"body": body,
|
|
}
|
|
|
|
|
|
def build_group_welcome_message(bot_name: str = "ForcePilot") -> str:
|
|
return (
|
|
f"大家好!我是 **{bot_name}**,已加入此对话。\n\n"
|
|
"你可以 @提及 我或直接向我发送消息来获得帮助。\n\n"
|
|
"发送 `/help` 查看可用命令。"
|
|
)
|
|
|
|
|
|
def build_welcome_response(
|
|
conversation_type: str,
|
|
bot_name: str,
|
|
prompt_starters: list[str] | None = None,
|
|
) -> dict[str, Any]:
|
|
if conversation_type == "personal":
|
|
card = build_personal_welcome_card(
|
|
bot_name=bot_name,
|
|
prompt_starters=prompt_starters,
|
|
)
|
|
return {
|
|
"type": "card",
|
|
"content": f"欢迎使用 {bot_name}",
|
|
"adaptive_card": card,
|
|
}
|
|
return {
|
|
"type": "text",
|
|
"content": build_group_welcome_message(bot_name),
|
|
}
|