1
votes

Linked To

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.

Issue

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

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

  3. 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

When It Works

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);

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.

  • Exception when the user types any utterance i.e. when the user hasn't yet signed it

enter image description here

  • Bot Emulator screenshot when the above exception comes up

enter image description here

What the Issue seems

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

More Information

  • The Adaptive Cards and LUIS based dialog flow was perfectly working until the Above changes for fixing OAuth Authentication in MS Teams were done.
  • Am using my Phone HotSpot for internet with no Proxy in between.
1
Could you please try this piece of code " protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken) { // Run the Dialog with the new message Activity. await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>(nameof(DialogState)), cancellationToken); //await Dialog.Run(turnContext, ConversationState.CreateProperty<DialogState>(nameof(DialogState)), cancellationToken); }"Trinetra-MSFT
figured out that, when we invoke__ await dialog.RunAsync(....)_ in DiallogBot class then, the Adaptive Card Submit is available from *outerDc.Context.Activity.Value* instead of options parameter in the public override *Task<DialogTurnResult> BeginDialogAsync* eventGaurav Anand

1 Answers

0
votes

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:

enter image description here