vinay narayana
vinay narayana

Reputation: 307

How to have dynamic flow for teams bot built using microsoft bot framework?

I have created a Microsoft teams app which consists of tabs and a bot. I took this as reference for creating teams addon. Here I am using the Waterfall flow model which was suggested by bot framework. While using this I have to give fixed number of actions, but I wanted to have dynamic actions. here is the example

class MainDialog extends ComponentDialog {
constructor(luisRecognizer, bookingDialog) {
    super('MainDialog');

    if (!luisRecognizer) throw new Error('[MainDialog]: Missing parameter \'luisRecognizer\' is required');
    this.luisRecognizer = luisRecognizer;

    if (!bookingDialog) throw new Error('[MainDialog]: Missing parameter \'bookingDialog\' is required');

    // Define the main dialog and its related components.
    // This is a sample "book a flight" dialog.
    this.addDialog(new TextPrompt(TEXT_PROMPT))
        .addDialog(bookingDialog)
        .addDialog(nominationDialogue)
        .addDialog(new ChoicePrompt(CHOICE_PROMPT))
        .addDialog(new WaterfallDialog(MAIN_WATERFALL_DIALOG, [
            this.introStep.bind(this),
            this.decidestep.bind(this),
            this.originStep.bind(this),
            this.actStep.bind(this),
            this.Actualstep.bind(this)
        ]));

    this.initialDialogId = MAIN_WATERFALL_DIALOG;
}

/**
 * The run method handles the incoming activity (in the form of a TurnContext) and passes it through the dialog system.
 * If no dialog is active, it will start the default dialog.
 * @param {*} turnContext
 * @param {*} accessor
 */
async run(turnContext, accessor) {
    const dialogSet = new DialogSet(accessor);
    dialogSet.add(this);

    const dialogContext = await dialogSet.createContext(turnContext);
    const results = await dialogContext.continueDialog();
    if (results && results.status === DialogTurnStatus.empty) {
        await dialogContext.beginDialog(this.id);
    }
}

How can I go to previous function i.e, actStep to decidesStep again without having any problem. I tried calling the decideStep from actStep then I am having an exception and bot is failing. When there is some repetitive work to be done I am not able to do due to the fixed number of actions.

Thanks in advance.

Upvotes: 0

Views: 212

Answers (2)

Ojas Maru
Ojas Maru

Reputation: 459

I had the same problem and I solved it using something like the following code (C#). It's not clean (kind of hack) but it works

private static async Task<DialogTurnResult> actStep (WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
    .
    .
    .
    stepContext.ActiveDialog.State["stepIndex"] = (int)stepContext.ActiveDialog.State["stepIndex"] - 2;
    return await stepContext.NextAsync(null, cancellationToken);
}

Upvotes: 2

Subhasish
Subhasish

Reputation: 509

Could you please look into the sample code for Conversation Bot .

You could find more sample solutions here

Upvotes: 0

Related Questions