跳到主要内容

Microsoft Teams

Microsoft Teams Channels 让 Mastra Agent 能够接收来自 Teams 的提及和对话事件。Mastra 负责 Agent 接线和 webhook 路由;Chat SDK Teams 适配器文档则介绍 Teams 应用设置、身份验证和权限。

安装适配器
安装适配器的直接链接

从 Chat SDK 安装 Teams 适配器:

npm install @chat-adapter/teams

Agent 配置
Agent 配置的直接链接

createTeamsAdapter() 添加到 Agent 的 channels.adapters 对象:

src/mastra/agents/teams-agent.ts
import { Agent } from '@mastra/core/agent'
import { createTeamsAdapter } from '@chat-adapter/teams'

export const teamsAgent = new Agent({
id: 'teams-agent',
name: 'Teams Agent',
instructions: 'Answer questions and help with tasks in Microsoft Teams.',
model: 'openai/gpt-5.6-sol',
channels: {
adapters: {
teams: createTeamsAdapter({
appType: 'SingleTenant',
}),
},
},
})

在 Mastra 实例上注册该 Agent:

src/mastra/index.ts
import { Mastra } from '@mastra/core'
import { teamsAgent } from './agents/teams-agent'

export const mastra = new Mastra({
agents: { teamsAgent },
})

适配器设置
适配器设置的直接链接

按照 Chat SDK Teams 适配器文档完成 Teams 专用设置,包括 Azure 机器人注册、Teams CLI 用法、身份验证选项和所需权限。

适配器从以下环境变量中读取 Teams 凭据:

.env
TEAMS_APP_ID=your-azure-bot-app-id
TEAMS_APP_PASSWORD=your-azure-bot-app-password
TEAMS_APP_TENANT_ID=your-azure-tenant-id

Webhook URL
Webhook URL的直接链接

Mastra 根据 Agent ID 和适配器键生成 Teams webhook 路由:

/api/agents/teams-agent/channels/teams/webhook

使用公开的 Mastra Server URL 作为基础 URL:

https://your-app.example.com/api/agents/teams-agent/channels/teams/webhook

在 Teams 适配器文档要求填写机器人端点或 webhook URL 的任何位置使用此 URL。本地开发时,请通过隧道公开 Mastra 开发 Server,并使用隧道 URL 作为基础 URL。