c# - 如何测试对话机器人本地主机

标签 c# azure botframework azure-bot-service

我目前正在关注Teams Conversation Bot样本。据我所知,我已经严格遵守了。

什么有效。

当我通过 WebView 与机器人交谈时

enter image description here

我可以看到它击中了我的本地主机上的代码。

 protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            turnContext.Activity.RemoveRecipientMention();

            switch (turnContext.Activity.Text.Trim())
            {
                case "MentionMe":
                    await MentionActivityAsync(turnContext, cancellationToken);
                    break;

                case "UpdateCardAction":
                    await UpdateCardActivityAsync(turnContext, cancellationToken);
                    break;

                case "Delete":
                    await DeleteCardActivityAsync(turnContext, cancellationToken);
                    break;

                case "MessageAllMembers":
                    await MessageAllMembersAsync(turnContext, cancellationToken);
                    break;

                default:
                    var value = new JObject { { "count", 0 } };

                    var card = new HeroCard
                    {
                        Title = "Welcome Card",
                        Text = "Click the buttons below to update this card",
                        Buttons = new List<CardAction>
                        {
                            new CardAction
                            {
                                Type= ActionTypes.MessageBack,
                                Title = "Update Card",
                                Text = "UpdateCardAction",
                                Value = value
                            },
                            new CardAction
                            {
                                Type = ActionTypes.MessageBack,
                                Title = "Message all members",
                                Text = "MessageAllMembers"
                            }
                        }
                    };

                    await turnContext.SendActivityAsync(MessageFactory.Attachment(card.ToAttachment()));
                    break;
            }
        }

什么不起作用

它似乎发送回响应,但响应窗口中没有显示任何内容。如果没有显示响应,我该如何测试?

Ngrok 错误

经过更多挖掘后,我可以看到 ngrok 正在返回某种错误,它是一个网页,我设法从中找出以下错误。

AggregateException: Failed to acquire token for client credentials. (AADSTS700016: Application with identifier '9e0d71-7665-4f24-8898-f82f9bebba56' was not found in the directory 'botframework.com'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.
Trace ID: 4bf53bae-84dc-4b16-98e8-e99b322dc200
Correlation ID: 3c249469-d177-49dd-989f-80044a3b9faa
Timestamp: 2019-11-12 08:41:56Z) (AADSTS700016: Application with identifier 'e0d71-7665-4f24-8898-f82f9bebba56' was not found in the directory 'botframework.com'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.

我已经检查了机器人和应用程序本身的设置。它们具有相同的 key 和应用程序客户端 ID。

enter image description here

botframework.com 似乎包含在 azure 上创建的机器人列表。

我尝试过的。

  • Visual Studio 正在以管理员身份运行。
  • 已检查 botframework.com我的机器人已列出。

  • 用户有权在 AD 中创建应用程序,无论如何我目前是唯一的用户。

enter image description here

  • 开发工具日志显示其身份验证。
  • Edge 和 Chrome

enter image description here

网络聊天错误

我可以在机器人中看到其网络聊天记录错误

enter image description here

问题是机器人正在响应。

模拟器

运行模拟器确实有效。问题出在托管时。

交叉发布

问题编号 1974

最佳答案

我意识到这是一个旧线程,但我今天才被这个问题击中。经过一番痛苦之后,我们的情况得到了解决:

  1. 转到 Azure 门户 > Azure Active Directory
  2. 点击“应用注册”
  3. 找到相关机器人应用的注册信息并点击它。
  4. 在“管理”下,选择“身份验证”。
  5. 将“支持的帐户类型”更改为“任何组织目录中的帐户”。

回想起来:尝试通过 Microsoft.Bot.Builder.Teams.TeamsInfo.GetMemberAsync() 获取机器人正在聊天的人员的详细信息时,引发了 AADSTS700016 错误。由于我们在应用程序注册中的“支持的帐户类型”受到限制,因此当机器人在与我们的 Azure AD 租户不同的 Teams Office365 租户中运行时,Azure AD 会说“不”。翻转此操作后,GetMemberAsync() 能够对 Teams Office365 租户进行身份验证,以获取请求的用户信息。耶!

关于c# - 如何测试对话机器人本地主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58814879/

相关文章:

c# - 将新所有者分配给约会。 "There should be only one owner party for an activity"

Azure Rest API 配置详细信息

Azure Web角色回收,无法加载ChallengeResult.cs中的入口点 "ExecuteAsync()"

ios - 带有 iphone 的 Bot Framework SMS channel - 短信不起作用

node.js 错误消息 events.js :183 throw er;//Unhandled 'error' event

c# - 改变音量确实会移动 slider ,但不会移动音频输出

c# - 使用带有类型参数的工厂方法创建带有参数化构造函数的派生类

c# - 打开页面新标签并刷新当前页面

powershell - Azure Powershell 脚本返回 "SubscriptionRequestsThrottled"错误消息

.net - 在一对一聊天中向租户中的用户发送通知