Skip to content Skip to sidebar Skip to footer

Botbuilder Python - Handling Multiple Dialog And Intent

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

Solution 1:

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

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

asyncdefprocess_intent(self, turn_context: TurnContext, recognizer_result, intent):
    if intent == "Greeting_Wishes"andnot entity:
        await greeting_wishes(turn_context, user_info)
        returnif intent == "Greeting_Question"andnot 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.

classMainDialog(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 defmain_step(self, step_context: WaterfallStepContext) -> DialogTurnResult:
        dialog_detail = self.luis.get_entities(self.intent, self.recognizer_result)
        ifself.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)

Post a Comment for "Botbuilder Python - Handling Multiple Dialog And Intent"