Teams Bot无法接收Teams内消息的问题排查咨询
Teams Bot部署后无响应问题排查
问题描述
我正在为Teams开发一款Bot,部署在Azure Web App中。Azure Bot注册页面的「Test in Web Chat」中Bot功能正常,Post控制器日志能捕获对话记录;Teams通道已注册且显示「Healthy」。但通过应用清单部署到Teams后,发送消息无响应,消息显示发送成功,但端点从未收到调用,In PostAsync日志无记录。
相关配置信息
应用清单
{ "$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.16/MicrosoftTeams.schema.json", "manifestVersion": "1.16", "version": "1.0.4", "id": "cbb5c179-99bc-4e95-a718-61c204eebc20", "packageName": "com.abc.def", "developer": { "name": "test", "websiteUrl": "https://www.test.com", "privacyUrl": "https://www.teams.com/privacy", "termsOfUseUrl": "https://www.teams.com/termsofuser" }, "icons": { "outline": "icon-outline.png", "color": "icon-color.png" }, "name": { "short": "BotTest", "full": "Test Bot" }, "description": { "short": "tbd...", "full": "tbd..." }, "accentColor": "#FFFFFF", "bots": [ { "botId": "7f7910a8-2910-4145-814f-630f344223be", "scopes": [ "personal" ], "isNotificationOnly": false, "supportsCalling": false, "supportsVideo": false, "supportsFiles": false, "commandLists": [ { "scopes": [ "personal" ], "commands": [] } ] } ], "webApplicationInfo": { "id": "7f7910a8-2910-4145-814f-630f344223be", "resource": "api://ph0jaaa4-7063.use.devtunnels.ms/7f7910a8-2910-4145-814f-630f344223be" }, "permissions": [ "identity" ], "validDomains": [ "token.botframework.com", "ph0jhmk4-7063.use.devtunnels.ms" ], "devicePermissions": [ "notifications", "openExternal" ] }
C# Bot控制器
using Microsoft.AspNetCore.Mvc; using Microsoft.Bot.Builder; using Microsoft.Bot.Builder.Integration.AspNet.Core; using Microsoft.Extensions.Logging; using System; using System.Threading.Tasks; namespace MyBot.WebApp.Controllers; [Route("api/MyEndpoint")] [ApiController] public class BotController : ControllerBase { private readonly IBotFrameworkHttpAdapter _adapter; private readonly IBot _bot; private readonly ILogger<BotController> _logger; public BotController(IBotFrameworkHttpAdapter adapter, IBot bot, ILoggerFactory loggerFactory = null) { _adapter = adapter; _bot = bot; if (loggerFactory != null) { _logger = loggerFactory.CreateLogger<BotController>(); } } [HttpPost] public async Task PostAsync() { _logger?.LogInformation(@"In PostAsync"); try { await _adapter.ProcessAsync(Request, Response, _bot); } catch (Exception ex) { _logger?.LogCritical(@"Exception: " + ex); } } }
Bicep部署模板
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "name": { "type": "string", "defaultValue": "[resourceGroup().name]" }, "displayName": { "type": "string", "defaultValue": "[resourceGroup().name]" }, "kind": { "type": "string", "defaultValue": "azurebot" }, "region": { "type": "string", "defaultValue": "global" }, "sku": { "type": "object", "defaultValue": { "name": "F0" } }, "appType": { "type": "string", "defaultValue": "UserAssignedMSI", "allowedValues": [ "MultiTenant", "SingleTenant", "UserAssignedMSI" ] }, "endpoint": { "type": "string", "defaultValue": "" }, "msaAppId": { "type": "string", "defaultValue": "" }, "msaAppTenantId": { "type": "string", "defaultValue": "" }, "msaAppMSIResourceId": { "type": "string", "defaultValue": "" }, "developerAppInsightKey": { "type": "string", "defaultValue": "" }, "tags": { "type": "object", "defaultValue": {}, "metadata": { "description": "By default the resources will be tagged with the resource group tags. Specify override values or new tags here if needs tags that are different than those of the resource group." } } }, "variables": { "resourceTags": "[union(resourceGroup().tags, parameters('tags'))]" }, "resources": [ { "type": "Microsoft.BotService/botServices", "name": "[parameters('name')]", "kind": "[parameters('kind')]", "apiVersion": "2018-07-12", "location": "[parameters('region')]", "sku": "[parameters('sku')]", "tags": "[variables('resourceTags')]", "properties": { "displayName": "[parameters('displayName')]", "msaAppType": "[parameters('appType')]", "msaAppId": "[parameters('msaAppId')]", "msaAppTenantId": "[parameters('msaAppTenantId')]", "msaAppMSIResourceId": "[parameters('msaAppMSIResourceId')]", "endpoint": "[parameters('endpoint')]", "developerAppInsightKey": "[parameters('developerAppInsightKey')]" } }, { "type": "Microsoft.BotService/botServices/channels", "apiVersion": "2021-05-01-preview", "name": "[concat(parameters('name'), '/MsTeamsChannel')]", "location": "global", "dependsOn": [ "[resourceId('Microsoft.BotService/botServices', parameters('name'))]" ], "properties": { "isEnabled": true, "acceptedTerms": true, "enableCalling": false, "deploymentEnvironment": "CommercialDeployment", "location": "global", "channelName": "MsTeamsChannel" } } ] }
可能原因与排查方向
1. 应用清单与Bot注册ID一致性检查
- 确认应用清单中
bots[0].botId是否与Azure Bot注册的MSA App ID完全匹配,当前清单中botId为7f7910a8-2910-4145-814f-630f344223be,需核对Azure门户中的Bot App ID。 - 检查顶层
id是否为Azure AD应用的ID,确保与Bot注册关联的AD应用ID一致。 - 若使用用户分配MSI,
webApplicationInfo.id需与Bot的App ID一致,resource路径需正确指向Bot端点的授权资源。
2. Teams通道深层配置验证
- 进入Azure Bot注册的Teams通道详情页,确认租户ID配置正确(单租户场景下需指定租户ID)。
- 检查通道是否完成授权流程,虽然Bicep模板中
acceptedTerms设为true,但需确认实际是否在门户中完成了条款同意。
3. 端点与网络连通性排查
- 确认Azure Bot注册中的
endpoint是否为完整的URL:https://<你的Web App域名>/api/MyEndpoint,与控制器路由完全匹配。 - 检查Web App的防火墙规则,是否允许Bot Framework服务的IP段访问(可在Azure门户Web App的「网络」>「访问限制」中配置允许的IP)。
- 若使用Dev Tunnel,确认隧道处于活跃状态,且公网可访问(可通过浏览器访问端点URL测试连通性)。
4. Bicep模板兼容性与参数校验
- Bot注册使用的API版本
2018-07-12较旧,建议升级到2021-05-01-preview或更高版本,避免配置兼容性问题。 - 检查部署时
msaAppMSIResourceId参数是否正确传入用户分配MSI的资源ID,空值会导致Bot无法正确认证Teams请求。 - 确认
endpoint参数在部署时已传入完整的Bot端点URL,空值会导致Bot无法接收消息。
5. 权限与认证问题
- 应用清单中
permissions仅配置了identity,若Bot需要接收用户消息,需添加对应的权限(如ChatMessage.Read等),并完成管理员同意(租户级部署场景)。 - 验证Web App是否正确配置了用户分配MSI,且MSI拥有访问Bot Framework服务的权限。
6. 日志与监控分析
- 启用Azure Bot注册的Application Insights,配置
developerAppInsightKey后,查看是否有Teams消息的路由错误日志。 - 检查Web App的「诊断日志」,查看是否有请求被拦截或返回错误的记录。
- 使用Bot Framework Emulator连接到Bot端点,模拟Teams环境的消息,验证端点是否能正常接收请求。
内容的提问来源于stack exchange,提问作者Hilton Giesenow
相关产品推荐
相关产品推荐

