Search code examples
botframeworkasp.net-core-2.1

How to call dialog inside botframework v4 in net-core?


I finally migrated a bot from v3 to v4 and it is working. It wouldn't be possible with out this community. Thank you all!

Now I am trying to include dialog in my bot. I've read documentation and have studied samples in github (botframework v4 repository), in this case all samples always start with dialog.

I don't need to start with dialogs because not all messages from the users require dialog. The most of messages from users call Luis and it is enough to unique response.

The issue is:

In some cases, my logic identify that user message requires more details, then I need to start a dialog to ask for more detail. I don't know how to start the dialog after user has sent several messages that doesn't require dialogs in the same session.

Thank you for ever help me!


Solution

  • You don't need to use Dialog to process single turn responses. In your case you can process the user input in OnMessageActivityAsync from your ActivityHandler, run against Luis, then use SendActivityAsync to send response back directly for simple intents, or run dialog.RunAsync to start a dialog when needed.

    Your simple intents don't have a state, so there is nothing you need to worry about "previous messages".

    However, I personally would suggest you start with a parent dialog which handles intent identification and intent processing. By doing that your intent identification/processing logic can be moved out of the ActivityHandler and it's easier to add things like authentication.

    This does require a bit of code though. I tried to simplify this kind of situation in one of my projects so that bot developers can focus on their business logic. I shared the code on git hub with some sample. If you are interested you can check it out.