0

I have the following code to handle multiple intents,

Code

async def on_message_activity(self, turn_context: TurnContext):
    recognizer_result = await self.luis.recognize(self.recognizer, turn_context)
    intent = self.luis.get_top_intent(recognizer_result)
    await self.process_intent(turn_context, recognizer_result, intent)

async def process_intent(self, turn_context: TurnContext, recognizer_result, intent):
    if intent == 'Greeting_Wishes':
        await greeting_wishes(turn_context, user_info)
    elif intent == 'Greeting_Question':
        await greeting_question(turn_context)
    elif intent == 'Movement':
        dialog = Movement(recognizer_result)
        await DialogHelper.run_dialog(
            dialog,
            turn_context,
            self.dialog_state
        )

Problem

  1. Greeting intent is working fine
  2. Movement intent is properly taking to the configured dialog but after asking a couple of inputs to the user and when the user enters their value it is either going back to greeting intent or going nowhere since the intent is None

Can someone help how to handle multiple intents with dialogs?

Any help would be appreciated!

moustacheman
  • 1,424
  • 4
  • 21
  • 47

1 Answers1

1

I ended up having one main dialog and extended the other dialogs depending upon the other intent. Look at the code sample below,

async def on_message_activity(self, turn_context: TurnContext):
    recognizer_result = await self.luis.recognize(self.recognizer, turn_context)
    intent = self.luis.get_top_intent(recognizer_result)
    await self.process_intent(turn_context, recognizer_result, intent)

async def process_intent(self, turn_context: TurnContext, recognizer_result, intent):
    if intent == "Greeting_Wishes" and not entity:
        await greeting_wishes(turn_context, user_info)
        return

    if intent == "Greeting_Question" and not entity:
        await greeting_question(turn_context)
        return

    dialog = MainDialog(self.luis, intent, recognizer_result)
    await DialogHelper.run_dialog(
        dialog,
        turn_context,
        self.conversation_state.create_property("DialogState")
    )

main_dialog.py

Within the main dialog, I'll check for the intent and begin the appropriate dialog.

class MainDialog(ComponentDialog):
    def __init__(self, luis, intent, recognizer_result):
        super(MainDialog, self).__init__(MainDialog.__name__)

        self.luis = luis
        self.intent = intent
        self.recognizer_result = recognizer_result

        self.add_dialog(SampleDialog1())
        self.add_dialog(SampleDialog2())
        self.add_dialog(
            WaterfallDialog(
                "main_dialog_id", [self.main_step]
            )
        )

        self.initial_dialog_id = "main_dialog_id"

    async def main_step(self, step_context: WaterfallStepContext) -> DialogTurnResult:
        dialog_detail = self.luis.get_entities(self.intent, self.recognizer_result)
        if self.intent == "one":
            return await step_context.begin_dialog(SampleDialog1.__name__, dialog_detail)
        elif self.intent == "two":
            return await step_context.begin_dialog(SampleDialog2.__name__, dialog_detail)
moustacheman
  • 1,424
  • 4
  • 21
  • 47
  • This is good. But when the user sends an input to the firs question from SampleDialog1(say it has multiple questions that require user inputs), that is going to end up with a different intent. Isn't that going to be a problem? – Vijay Jul 01 '20 at 06:06
  • Thanks @moustacheman. I just tested and it works well. The reason for my above comment is that, if I've a None intent, I want it to be directed to QnA instead of getting to Dialog. This is achievable from the inside the Main Dialog as well, but I'm ending up with an attribute error on DialogTurnStatus.Waiting. I'm ending the dialog as soon as I've the answer from QnA, but it still ends up in error. – Vijay Jul 01 '20 at 08:19
  • I was able to figure out executing individual dialogs based on intent using the Dispatch tool. Please find my answer here - https://stackoverflow.com/questions/62655197/get-the-active-dialog-id-in-botframework-python-dispatch-model-with-multiple-d/62788115#62788115 – Vijay Jul 08 '20 at 06:02