Reputation: 119
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.
The MainDialog class in my case uses both LUIS and Adaptive cards to drive the conversational flow.
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.
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.
However, the LUIS conversational logic works after successful OAuth Authentication from within MS Teams.
MainDialog.BeginDialogAsync(DialogContext outerDc, object options = null, CancellationToken cancellationToken = default(CancellationToken)){....}
As per the sample oAuth Sample code provided at https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/46.teams-auth
Implemented the suggested code in the method TeamsBot.OnTeamsSigninVerifyStateAsync(ITurnContext turnContext, CancellationToken cancellationToken)
Inside the overridden method DialogBot.OnMessageActivityAsync(ITurnContext turnContext, CancellationToken cancellationToken), I replaced "a" with "b"
a. await _dialog.Run(turnContext, _botStateService.DialogStateAccessor, cancellationToken);
b. await _dialog.RunAsync(turnContext, ConversationState.CreateProperty(nameof(DialogState)), cancellationToken);
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
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")
b. await _dialog.RunAsync(turnContext, ConversationState.CreateProperty(nameof(DialogState)), cancellationToken);
c. await _dialog.Run(turnContext, ConversationState.CreateProperty(nameof(DialogState)), cancellationToken);
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.
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.
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
Upvotes: 1
Views: 649
Reputation: 119
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
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:
Upvotes: 0