本文介绍了MS Team和MSBotframeworkV4 Chatbot中的OAuth实施导致自适应卡提交故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

链接的帖子网址: 登录按钮提示输入凭据并成功进行身份验证,但不会登录-在用户中

使用以下Git Hub代码示例作为OAuth代码的基础,并改型为我现有的ChatBot:"> https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/46.teams-auth

Used the following Git Hub Code Sample as a basis for the OAuth code and retrofitted to my existing ChatBot: https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/46.teams-auth

问题

在我的案例中, MainDialog 类同时使用LUIS和Adaptive卡来驱动对话流程.

Issue

The MainDialog class in my case uses both LUIS and Adaptive cards to drive the conversational flow.

由于DialogBot类的以下更改, MainDialog .BeginDialogAsync覆盖 方法中的选项" 参数现在变为 NULL 值,而不是更改前以前使用的正确值.

Due to the following change in the DialogBot class, the "options" paramater in MainDialog .BeginDialogAsync overridden method now gets NULL value instead of a proper value it used to previously get before the change.

由于 MainDialog .BeginDialogAsync被覆盖 方法在选项" 参数中具有用于检测自适应卡返回值的所有代码,现在,它以 null 返回,自适应卡不起作用.

As the MainDialog .BeginDialogAsync overridden method has all the code to detect returned value by the Adaptive Card in the "options" paramater, now that, it is being returned as null, the adaptive cards don't work.

但是,在MS Teams中成功进行OAuth身份验证后,LUIS对话逻辑才能工作.

However, the LUIS conversational logic works after successful OAuth Authentication from within MS Teams.

根据在 https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/46.teams-auth

  1. 我从 TeamsActivityHandler 继承了 DialogBot .
  2. 在方法 TeamsBot.OnTeamsSigninVerifyStateAsync 中实现了建议的代码(ITurnContext turnContext,CancellationToken cancelledToken)

  1. I inherited DialogBot from TeamsActivityHandler.
  2. Implemented the suggested code in the method TeamsBot.OnTeamsSigninVerifyStateAsync(ITurnContext turnContext, CancellationToken cancellationToken)

在覆盖的方法 DialogBot.OnMessageActivityAsync (ITurnContext turnContext,CancellationToken cancelleToken)内部, 我将"a"替换为"b"

Inside the overridden method DialogBot.OnMessageActivityAsync(ITurnContext turnContext, CancellationToken cancellationToken), I replaced "a" with "b"

b.等待_dialog.RunAsync(turnContext,ConversationState.CreateProperty(nameof(DialogState)),cancelledToken);

b. await _dialog.RunAsync(turnContext, ConversationState.CreateProperty(nameof(DialogState)), cancellationToken);

简单地将.Run(....)更改为.RunAsync(....),可能会由于任务"Options" 而使值丢失,并使自适应卡代码无法正常工作 > MainDialog.BeginDialogAsync(..)方法中的参数值

The simple change of .Run(....) to .RunAsync(....) probably misses the value and makes the Adaptive Card code non-functionl due to the mission "Options" parameter value in MainDialog.BeginDialogAsync(..) method

DialogBot.OnMessageActivityAsync(...)中,当我将 b替换为c 时,会出现"options" 中的参数.BeginDialogAsync(...) 开始获取使自适应卡代码起作用的必要值,但是仅当用户为已被OAuth身份验证,即不需要单击登录按钮.(但是会出现当它不起作用时"部分中提到的另一个问题)

In the DialogBot.OnMessageActivityAsync(...) , when I replace b with c then, the "options" parameter in MainDialog .BeginDialogAsync(...) starts getting the requisite value to make the Adaptive card code work but, only if the user is already OAuth Authenticated i.e. when clicking sign-in button is not required.(But brings up another issue mentioned in "When It Doesn't Work section")

c.等待_dialog.Run(turnContext,ConversationState.CreateProperty(nameof(DialogState)),cancelledToken);

c. await _dialog.Run(turnContext, ConversationState.CreateProperty(nameof(DialogState)), cancellationToken);

当它不起作用时

进行当它起作用" 部分中提到的更改后,如果用户键入诸如"Hi"之类的任何字词,则会在DialogBot.OnTurnAsync(....)中引起异常.方法.然后,每次都会出现此错误,并且无法继续进行Bot对话.

When It Doesn't Work

After making the change mentioned in the "When It Works" section if, the user types any utterance like "Hi", it causes an exception in the DialogBot.OnTurnAsync(....) method. This error then keeps coming every time and am not able to proceed with the Bot conversation.

  • 当用户键入任何语音时,即用户尚未签名时,则为异常
  • 出现上述异常时,Bot Emulator屏幕截图

在这种情况下,在MS Teams中进行OAuth身份验证时,可以肯定的是,我在状态管理中与应如何处理自适应卡提交"点击(即,检索用户提供的值)协调一致.

In this scenario of OAuth Authentication in MS Teams, It's definite that I am messing up in state management in coordination with how Adaptive Card Submit click should be handled i.e. to retrieve user-provided values.

更多信息

  • 基于自适应卡和LUIS的对话流程非常正常直到完成上述用于在MS Teams中修复OAuth身份验证的更改为止.
  • 我正在使用我的Phone HotSpot进行Internet连接,而两者之间没有代理.
  • More Information

    • The Adaptive Cards and LUIS based dialog flow was perfectly workinguntil the Above changes for fixing OAuth Authentication in MS Teams were done.
    • Am using my Phone HotSpot for internet with no Proxy in between.
    • 推荐答案

      发现,当我们调用 await对话框时,DialDialogBot中的RunAsync(...._) >类,则可从 outerDc.Context.Activity.Value 获得Adaptive Card Submit Json值,而不是 options > MainDialog

      Figured out that, when we invoke await dialog.RunAsync(....)_ in DiallogBot class then, the Adaptive Card Submit Json value is available from outerDc.Context.Activity.Value instead of options parameter in the public override Task BeginDialogAsync(....) event of MainDialog

      这篇关于MS Team和MSBotframeworkV4 Chatbot中的OAuth实施导致自适应卡提交故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 09:02