-2

I am running botframework v4 code and testing it using chatbot emulator . Curently i am unable to reach the code flow where the luis intent code is present in [MainDialog.cs][1] .

Below is the line in MainDialog.cs file:

 var luisResult = await _luisRecognizer.RecognizeAsync<FlightBooking>(stepContext.Context, cancellationToken);

But ,when i enter some message in ChatBot ,every time flow ends at [FlightBookingRecognizer.cs][2] and below is the line where i am expecting luis intent to be matched/fetched.

public virtual async Task<RecognizerResult> RecognizeAsync(ITurnContext turnContext, CancellationToken cancellationToken)
    => await _recognizer.RecognizeAsync(turnContext, cancellationToken);

public virtual async Task<T> RecognizeAsync<T>(ITurnContext turnContext, CancellationToken cancellationToken)
     where T : IRecognizerConvert, new()
    => await _recognizer.RecognizeAsync<T>(turnContext, cancellationToken);

turnContext has the message which we enter in chatbot. And i am expecting the LUIS result in _recognizer.RecognizeAsync ,but there is no relevant data in this . I am trying to do something like below:-



But, my code flow ends here and i get error in ChatBot emulator as attached in screenshot.[![enter image description here][3]][3]


Steps to reproduce:
1. Download or pull the project from github and then Open the CoreBot.csproj  in Visual studio from this link .
[CoreBot Project][4]

2. Then select CoreBot and build it (Don't forget to add luis app id,key and host in csharp_dotnetcore\13.core-bot\appsettings.json file).
In Luis you can import this file csharp_dotnetcore\13.core-bot\CognitiveModels\FlightBooking.json and then train and publish it.
In Luis.ai go to My apps, and click Import App. Choose the file JSON file for the app you want to import and click Import.

3. Also put debug breakpoints in MainDialog.cs class (line 67 jus before switch statement) and FlightBookingRecognizer.cs class (last 2 lines ) .

4.Run the project in IIS browser mode and not in console mode ,it will open in browser you will see this link  http://localhost:3978/ 

5. In chatbot Emulator open this link http://localhost:3979/api/messages

6. You will see cards in chatbot as per attached screenshot.

7. Enter a message which is given in chatbot example i.e "Flight to paris"

8. You will see debug point ends at FlightRecognizer.cs class last line and turnContext has your message but _recognizer.RecognizeAsync doesn't carry any information about the Luis intent .

9.Also,it is not clear that LUIS intent is matched from local file or luis.ai 


More info can be found here [Microsoft documentation about this v4 code][5]
Please Help.


  [1]: https://github.com/microsoft/BotBuilder-Samples/blob/master/samples/csharp_dotnetcore/13.core-bot/Dialogs/MainDialog.cs
  [2]: https://github.com/microsoft/BotBuilder-Samples/blob/master/samples/csharp_dotnetcore/13.core-bot/FlightBookingRecognizer.cs
  [3]: https://i.stack.imgur.com/05Rbg.png
  [4]: https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/13.core-bot
  [5]: https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-howto-v4-luis?view=azure-bot-service-4.0&tabs=csharp
AllTech
  • 563
  • 6
  • 27
  • Please enable debugging and have it break when it hits an error. Please then edit your question with the error as well as the relevant code that causes it to error. – mdrichardson Feb 13 '20 at 20:28
  • I have updated those lines and RecognizeAsync api call where code flows ends during debugging . – AllTech Feb 13 '20 at 20:30
  • If there are syntax errors, you should fix them. As it stands, I still am not sure what your actual issue is. You need to include more detailed information about the error, where it's happening, and what you expect to be happening instead. – mdrichardson Feb 13 '20 at 23:10
  • @mdrichardson-MSFT I have resolved that syntax error but still there is a exception in source code as per chatbot emulator screenshot and Issue is happening in FlightBookingRecognizer.cs class as mentioned in steps to reproduce . _recognizer.RecognizeAsync should contain the intent match or score as expected but i am not able to see any such value in that line . – AllTech Feb 14 '20 at 06:52

2 Answers2

0

The V4 MessageController should rarely, if ever, change from the skeleton. In this line:

await _adapter.ProcessAsync(Request, response, _bot);

...you can see that the Controller passes the Request to the _bot. Use your bot to handle the dialog.

In the CoreBot sample, you can see that after the message hits the BotController (which is equivalent to MessageController, it goes to DialogBot, where it calls the Dialog:

protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
    Logger.LogInformation("Running dialog with Message Activity.");

    // Run the Dialog with the new message Activity.
    await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>("DialogState"), cancellationToken);
}

It "knows" to do this, because in Startup.cs, it uses Dependecy Injection to add both the bot and the dialog so that BotController and DialogBot can use them, respectively:

services.AddTransient<IBot, DialogAndWelcomeBot<MainDialog>>();

Before migrating, I highly, highly recommend setting up CoreBot and reading through it until you understand how it works. It will likely be helpful for future migration questions.

mdrichardson
  • 7,141
  • 1
  • 7
  • 21
  • Thanks a lot, Can you please help me in the LUIS intent flow. i.e when i enter some message in chatbot then it should detect it as utterance and then map it to particular intent and i have also configured LUIS app id and key in appsettings.json. – AllTech Feb 13 '20 at 13:07
  • @AllTech CoreBot [does this in MainDialog](https://github.com/microsoft/BotBuilder-Samples/blob/master/samples/csharp_dotnetcore/13.core-bot/Dialogs/MainDialog.cs#L68) – mdrichardson Feb 13 '20 at 16:37
  • In MainDialog.cs i found only this line which is related to Luis intent : var luisResult = await _luisRecognizer.RecognizeAsync(stepContext.Context, cancellationToken); and i guess FlightBooking is mentioned in the template argument which is explicilty getting data from FlightBooking class . – AllTech Feb 13 '20 at 17:53
  • Also, there is a class FlightBookingRecognizer.cs which has public virtual async Task RecognizeAsync(ITurnContext turnContext, CancellationToken cancellationToken) => await _recognizer.RecognizeAsync(turnContext, cancellationToken); thats where my code fails when i check the flow with debugger ( while using chatbot emulator ) . – AllTech Feb 13 '20 at 17:53
  • @AllTech Please update your question with your code. MainDialog has a `switch` statement that acts on each intent from `luisResult` – mdrichardson Feb 13 '20 at 19:56
  • I have updated the code and my observation till now. – AllTech Feb 13 '20 at 20:15
0

This issue is resolved now.I am able to get the intent from Luis. When i used Luis host which is configured in appsettings.json in format https://xxxx.xxxx.xxxx I was not getting Luis Intent,but after removing https:// ,i am getting the result now. Thanks everybody for your efforts.

AllTech
  • 563
  • 6
  • 27