Azure Bot无法展示Function App返回的响应问题求助
Azure Bot集成Teams无响应排查问题
我正在搭建一个集成自定义MS Teams应用的Azure Bot,目的是让员工通过Teams和ChatGPT交互。目前已完成以下配置:
- 成功配置OpenAI API密钥
- 创建Azure Bot(名称:InternalChatGPTBot)
- 创建PowerShell Core Function App(名称:TeamsBotHandler)
- 确认Function App可正常调用,输入输出符合要求
- 创建关联该Bot的自定义MS Teams应用
问题现象
尽管执行了大量排查步骤,Azure Bot始终没有任何响应:日志显示Teams应用或Web Chat测试能成功触发TeamsBotHandler,但聊天框里完全看不到回复。另外因为租户配置限制,无法使用Bot Framework Emulator进行调试。
已验证的排查项
- Function App运行状态正常,可正常访问
- 返回的JSON Schema符合要求
- Function App授权级别设置为匿名
- 响应的Content-Type为
application/json - OpenAI API调用成功,能返回有效内容
- 已正确使用
Push-OutputBinding返回结果 - Azure Bot存在,消息端点配置正确
- 应用在Entra中配置了正确的API权限
- MS Teams应用状态健康,可将聊天输入发送至Function App
Function App核心逻辑代码
using namespace System.Net # Input bindings are passed in via param block. param($Request, $TriggerMetadata) # Format Body $body = $Request.Body $userMessage = $body.text $openaiApiKey = "XXXX" #obviously private $payload = @{ model = "gpt-4o" messages = @( @{ role = "user"; content = $userMessage } ) } | ConvertTo-Json -Depth 10 # Call API $response = Invoke-WebRequest -Uri "https://api.openai.com/v1/chat/completions" -Method POST -Headers @{ "Authorization" = "Bearer $openaiApiKey" } -Body $payload -ContentType "application/json" # Process Response $content = $response.content | ConvertFrom-Json -ErrorAction SilentlyContinue $botReply = $content.choices[0].message.content # Clean up Response $botReply = $botReply -replace '[\u201C\u201D]', '"' $botReply = $botReply -replace '[\u2018\u2019]', "'" $botReply = $botReply -replace '\r?\n', "`n" # Build Teams-compatible response $teamsResponse = @{ type = "message" text = $botReply } | ConvertTo-Json -Depth 10 # Push response out Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ StatusCode = 200 Headers = @{ "Content-Type" = "application/json" } Body = $teamsResponse }) return
内容的提问来源于stack exchange,提问作者emiliablueshift
相关产品推荐
相关产品推荐

