Bot Framework Test 连接到您的机器人失败,状态代码为 Forbidden

Bot Framework Test connection to your bot fails with status code Forbidden

我的机器人在 Slack、Skype 和模拟器中正常接收和发送消息。

然而,当我点击 bot 门户 (https://dev.botframework.com/) 中的蓝色测试按钮时,它给我错误消息 "Authorization for Microsoft App ID my_id_is_replacedhere failed with status code Forbidden"

完整错误如下。

当我使用端点 https://slack.botframework.com/ 和 Conversations.SendToConversation() 方法向 Slack 发送预定消息时,我也遇到了同样的错误。这曾经有效并且测试按钮曾经成功。

为什么我会收到这条消息?是否有破坏它的 NuGet pkg 更新? 我仔细阅读了故障排除指南,但其他一切似乎都有效。

谢谢

InternalServerError { "message": "An error has occurred.", "exceptionMessage": "Authorization for Microsoft App ID my_id_is_replacedhere failed with status code Forbidden", "exceptionType": "System.UnauthorizedAccessException", "stackTrace": " at Microsoft.Bot.Connector.JwtTokenRefresher.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n at Microsoft.Bot.Connector.Conversations.d__8.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Connector.ConversationsExtensions.d__19.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()\r\n at Grasp.MessagesController.d__0.MoveNext() in C:\Code\Relegraph_Git\GraspThree\Grasp\Controllers\MessagesController.cs:line 55\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Threading.Tasks.TaskHelpersExtensions.d__3`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()" }

我弄清楚了导致错误的原因。显然,机器人门户中的“测试”按钮会向机器人发送 "Ping" 消息。在我的 MessagesController 代码中,我试图用这样的方式回复每条消息:

                        ConnectorClient connector = new ConnectorClient(new Uri(Act.ServiceUrl), appcred);
                        Activity reply = Act.CreateReply(replymsg);
                        connector.Conversations.ReplyToActivity(reply);

但是 - 当我为 Activity (Activity.Type=ActivityTypes.Ping) 的 Ping 类型执行此操作时,我会收到上述错误。当我忽略 Ping 消息时,“测试”按钮会起作用。

当我按计划向 Slack 发送消息时遇到同样的错误(没有要回复的传入消息)时,我仍然遇到了问题。我使用 Slack 的 WebAPI 解决了这个问题:

https://slack.com/api/chat.postMessage?token={0}&channel={1}&text={2}&as_user={3}

尝试使用

MicrosoftAppCredentials.TrustServiceUrl(notify.ServiceUrl, DateTime.MaxValue);

之前

connector.Conversations.SendToConversationAsync(...)