MS Teams 和 MSBotframeworkV4 Chatbot 中的 OAuth 实施导致自适应卡片提交出现故障
OAuth Implementation in MS Teams and MSBotframeworkV4 Chatbot causing Adaptive Card Submit to Malfunction
链接到
This issue is linked to my previous post related to an issue with MS Bot framework oAuth Authentication in MS Teams Chanel.
The OAuth Authentication has started working but, am facing this issue as a result of the suggested code changes to enable OAuth Authentication.
Linked Post URL: Sign-in button prompts for Credentials and successfully authenticates but, doesn't log-in the user
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
- The Class hierarchy mention in the question is similar to the above code sample.
问题
在我的案例中,MainDialogclass 使用 LUIS 和自适应卡片来驱动对话流。
由于 DialogBot class 中的以下更改,"options" 参数 MainDialog .BeginDialogAsync重写的 方法现在获取 NULL 值,而不是之前更改前获取的正确值。
由于 MainDialog .BeginDialogAsync 被覆盖 方法具有检测自适应卡返回值的所有代码 "options" 参数,现在返回为 null,自适应卡不起作用。
但是,在 MS Teams 中成功进行 OAuth 身份验证后,LUIS 对话逻辑会起作用。
MainDialog.BeginDialogAsync(DialogContext outerDc, object options = null, CancellationToken cancellationToken = default(CancellationToken)){....}
根据 https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/46.teams-auth
处提供的示例 oAuth 示例代码
- 我从 TeamsActivityHandler.
继承了 DialogBot
在方法中实现了建议的代码TeamsBot.OnTeamsSigninVerifyStateAsync(ITurnContext turnContext, CancellationToken cancellationToken)
在覆盖的方法中DialogBot.OnMessageActivityAsync(ITurnContext turnContext, CancellationToken cancellationToken), 我替换了"a" 和 "b"
a. await _dialog.Run(turnContext, _botStateService.DialogStateAccessor, cancellationToken);
b. await _dialog.RunAsync(turnContext, ConversationState.CreateProperty(nameof(DialogState)), cancellationToken);
.运行(....) 到 .运行Async(....) 的简单更改可能会丢失值并使自适应卡代码 non-functionl由于任务 "Options" MainDialog.BeginDialogAsync(..) 方法
中的参数值
何时有效
在 DialogBot.OnMessageActivityAsync(...) 中,当我将 b 替换为 c 然后, "options" 参数在 MainDialog .BeginDialogAsync(...) 开始获取使自适应卡代码工作所需的值,但是 仅当用户已经通过 OAuth 身份验证时,即不需要单击 sign-in 按钮时。(但会引发另一个问题"When It Doesn't Work section")
b. await _dialog.RunAsync(turnContext, ConversationState.CreateProperty(nameof(DialogState)), cancellationToken);
c. await _dialog.Run(turnContext, ConversationState.CreateProperty(nameof(DialogState)), cancellationToken);
当它不起作用时
在 "When It Works" 部分中提到的更改之后,如果用户键入任何像 "Hi" 这样的语句,它会在 DialogBot.OnTurnAsync(....) 方法。然后每次都会出现此错误,我无法继续进行 Bot 对话。
- 当用户键入任何话语时出现异常,即当用户尚未签名时
- 出现上述异常时的 Bot Emulator 屏幕截图
似乎是什么问题
在 MS Teams 中的 OAuth 身份验证的这种情况下,可以肯定的是,我在状态管理方面搞砸了,与处理自适应卡提交点击的方式相协调,即检索 user-provided 值。
Would need inputs to handle this scenario where MS Teams OAuth Authentication is involved with a chatbot catering to both LUIS NLP based conversation and Adaptive Cards based dialog flow
更多信息
- 自适应卡片和基于 LUIS 的对话流程运行良好
直到完成上述用于修复 MS Teams 中的 OAuth 身份验证的更改。
- 我正在使用我的 Phone 互联网热点,中间没有代理。
发现,当我们调用 await dialog.RunAsync(....)_ in DiallogBot class 然后,自适应卡提交 Json 值可从 outerDc.Context.Activity.Value 而不是 options public 中的参数覆盖 Task BeginDialogAsync(....) MainDialog
事件
Therefore the only code change I did to make adaptive Card submit feature work i.e. after implementing the OAuth Authentication to the ChatBot is the following:
链接到
This issue is linked to my previous post related to an issue with MS Bot framework oAuth Authentication in MS Teams Chanel. The OAuth Authentication has started working but, am facing this issue as a result of the suggested code changes to enable OAuth Authentication.
Linked Post URL: Sign-in button prompts for Credentials and successfully authenticates but, doesn't log-in the user
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
- The Class hierarchy mention in the question is similar to the above code sample.
问题
在我的案例中,MainDialogclass 使用 LUIS 和自适应卡片来驱动对话流。
由于 DialogBot class 中的以下更改,"options" 参数 MainDialog .BeginDialogAsync重写的 方法现在获取 NULL 值,而不是之前更改前获取的正确值。
由于 MainDialog .BeginDialogAsync 被覆盖 方法具有检测自适应卡返回值的所有代码 "options" 参数,现在返回为 null,自适应卡不起作用。
但是,在 MS Teams 中成功进行 OAuth 身份验证后,LUIS 对话逻辑会起作用。
MainDialog.BeginDialogAsync(DialogContext outerDc, object options = null, CancellationToken cancellationToken = default(CancellationToken)){....}
根据 https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/46.teams-auth
处提供的示例 oAuth 示例代码- 我从 TeamsActivityHandler. 继承了 DialogBot
在方法中实现了建议的代码TeamsBot.OnTeamsSigninVerifyStateAsync(ITurnContext turnContext, CancellationToken cancellationToken)
在覆盖的方法中DialogBot.OnMessageActivityAsync(ITurnContext turnContext, CancellationToken cancellationToken), 我替换了"a" 和 "b"
a. await _dialog.Run(turnContext, _botStateService.DialogStateAccessor, cancellationToken);
b. await _dialog.RunAsync(turnContext, ConversationState.CreateProperty(nameof(DialogState)), cancellationToken);
.运行(....) 到 .运行Async(....) 的简单更改可能会丢失值并使自适应卡代码 non-functionl由于任务 "Options" MainDialog.BeginDialogAsync(..) 方法
中的参数值何时有效
在 DialogBot.OnMessageActivityAsync(...) 中,当我将 b 替换为 c 然后, "options" 参数在 MainDialog .BeginDialogAsync(...) 开始获取使自适应卡代码工作所需的值,但是 仅当用户已经通过 OAuth 身份验证时,即不需要单击 sign-in 按钮时。(但会引发另一个问题"When It Doesn't Work section")
b. await _dialog.RunAsync(turnContext, ConversationState.CreateProperty(nameof(DialogState)), cancellationToken);
c. await _dialog.Run(turnContext, ConversationState.CreateProperty(nameof(DialogState)), cancellationToken);
当它不起作用时
在 "When It Works" 部分中提到的更改之后,如果用户键入任何像 "Hi" 这样的语句,它会在 DialogBot.OnTurnAsync(....) 方法。然后每次都会出现此错误,我无法继续进行 Bot 对话。
- 当用户键入任何话语时出现异常,即当用户尚未签名时
- 出现上述异常时的 Bot Emulator 屏幕截图
似乎是什么问题
在 MS Teams 中的 OAuth 身份验证的这种情况下,可以肯定的是,我在状态管理方面搞砸了,与处理自适应卡提交点击的方式相协调,即检索 user-provided 值。
Would need inputs to handle this scenario where MS Teams OAuth Authentication is involved with a chatbot catering to both LUIS NLP based conversation and Adaptive Cards based dialog flow
更多信息
- 自适应卡片和基于 LUIS 的对话流程运行良好 直到完成上述用于修复 MS Teams 中的 OAuth 身份验证的更改。
- 我正在使用我的 Phone 互联网热点,中间没有代理。
发现,当我们调用 await dialog.RunAsync(....)_ in DiallogBot class 然后,自适应卡提交 Json 值可从 outerDc.Context.Activity.Value 而不是 options public 中的参数覆盖 Task BeginDialogAsync(....) MainDialog
事件Therefore the only code change I did to make adaptive Card submit feature work i.e. after implementing the OAuth Authentication to the ChatBot is the following: