Search code examples
node.jsbotframeworkbot-framework-composer

Move data in Waterfall-Dialog. Bot Framework SDK


I'm using Bot Framework SDK with nodejs to implement a disamibuation flow.

I want that if two intents predicted by Luis are close to each other, ask the user from which of them are the one they want. I have done the validator but, I have a problem with the flow.

It is a waterfall Dialog with 3 steps:

  1. FirstStep: Calls Orchestrator and Luis to get intents and entities. It pass the data with return await step.next({...})
  2. Disamiguation Step: Checks if it is necessary to disambiguate, and, in that case, prompts the options. If not, it pass the data like the first step.
  3. Answer step: If it has a disambiguation flag in the data it receives in step.result, it prompts the answer acordingly with the user response. Elsewhere, it uses the data in step.result that comes from the first step.

The problem is that, when it prompts user to say the intent, I lost the data of the FirstStep since I cannot use step.next({...})

¿How can I maintain both the data from the first step and the user answer in the prompt?

Here are the basic code:

 async firstStep(step) {
        logger.info(`FinalAnswer Dialog: firstStep`);
        let model_dispatch = await this.bot.get_intent_dispatch(step.context);
        let result = await this.bot.dispatchToTopIntentAsync(step.context, model_dispatch.model)
        // model_dispatch = orchestrator_model
        // result = {topIntent: String, entities: Array, disamibiguation: Array}

        return await step.next({ model_dispatch: model_dispatch, result: result})
    }

    async disambiguationStep(step) {
        logger.info(`FinalAnswer Dialog: disambiguationStep`);
        if (step.result.result.disambiguation) {
            logger.info("We need to disambiguate")
            let disambiguation_options = step.result.result.disambiguation
            const message_text = "What do you need";
            const data = [
                {
                    "title": "TEXT",
                    "value": disambiguation_option[0]
                },
                {
                    "title": "TEXT",
                    "value": disambiguation_option[1]
                },
            ]

            let buttons = data.map(function (d) {
                return {
                    type: ActionTypes.PostBack,
                    title: d.title,
                    value: d.value
                }
            });

            const msg = MessageFactory.suggestedActions(buttons, message_text);
            return await step.prompt(TEXT_PROMPT, { prompt: msg });
            return step.next(step.result) //not working
        }
        else {
            logger.info("We dont desambiguate")
            return step.next(step.result)
        }
    }

    async answerStep(step) {
        logger.info(`FinalAnswer Dialog: answerStep`);
        let model_dispatch = step.result.model_dispatch
        let result = step.result.result

        //Show answer
 
        return await step.endDialog();
    }

Solution

  • You can use the step dictionary to store your values. The complex dialogs sample on GitHub is excellent for demonstrating this. https://github.com/microsoft/BotBuilder-Samples/blob/main/samples/javascript_nodejs/43.complex-dialog/dialogs/topLevelDialog.js