How to use the botbuilder-dialogs.NumberPrompt function in botbuilder-dialogs

To help you get started, we’ve selected a few botbuilder-dialogs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / botbuilder-js / samples / multiple-prompts-bot-es6 / bot.js View on Github external
function createBotLogic(conversationState) {

    const dialogs = new DialogSet();

    // Create prompt for name with string length validation
    dialogs.add('namePrompt', new TextPrompt(async (context, value) => {
        if (value && value.length < 2) {
            await context.sendActivity('Your name should be at least 2 characters long.');
            return undefined;
        }
        return value.trim();
    }));

    // Create prompt for age with number value validation
    dialogs.add('agePrompt', new NumberPrompt(async (context, value) => {
        if (0 > value || value > 122) {
            await context.sendActivity('Your age should be between 0 and 122.');
            return undefined;
        }
        return value;
    }));

    // Add a dialog that uses both prompts to gather information from the user
    dialogs.add('gatherInfo', [
        async (dialogContext) => {
            await dialogContext.prompt('namePrompt', 'What is your name?');
        },
        async (dialogContext, value) => {
            const state = conversationState.get(dialogContext.context);
            state.name = value;
            await dialogContext.prompt('agePrompt', 'What is your age?');
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 19.custom-dialogs / dialogs / rootDialog.js View on Github external
// Link the questions together into a parent group that contains references
        // to both the fullname and address questions defined above.
        const slots = [
            new SlotDetails('fullname', 'fullname'),
            new SlotDetails('age', 'number', 'Please enter your age.'),
            new SlotDetails('shoesize', 'shoesize', 'Please enter your shoe size.', 'You must enter a size between 0 and 16. Half sizes are acceptable.'),
            new SlotDetails('address', 'address')
        ];

        // Add the individual child dialogs and prompts used.
        // Note that the built-in prompts work hand-in-hand with our custom SlotFillingDialog class
        // because they are both based on the provided Dialog class.
        this.addDialog(new SlotFillingDialog('address', addressSlots));
        this.addDialog(new SlotFillingDialog('fullname', fullnameSlots));
        this.addDialog(new TextPrompt('text'));
        this.addDialog(new NumberPrompt('number'));
        this.addDialog(new NumberPrompt('shoesize', this.shoeSizeValidator));
        this.addDialog(new SlotFillingDialog('slot-dialog', slots));

        // Finally, add a 2-step WaterfallDialog that will initiate the SlotFillingDialog,
        // and then collect and display the results.
        this.addDialog(new WaterfallDialog('root', [
            this.startDialog.bind(this),
            this.processResults.bind(this)
        ]));

        this.initialDialogId = 'root';
    }
github microsoft / botbuilder-js / samples / 10. sidecarDebugging / src / bot.ts View on Github external
// Link the questions together into a parent group that contains references
		// to both the fullname and address questions defined above.
		const slots = [
			new SlotDetails('fullname', 'fullname'),
			new SlotDetails('age', 'number', 'Please enter your age.'),
			new SlotDetails('shoesize', 'shoesize', 'Please enter your shoe size.', 'You must enter a size between 0 and 16. Half sizes are acceptable.'),
			new SlotDetails('address', 'address')
		];

		// Add the individual child dialogs and prompts used.
		// Note that the built-in prompts work hand-in-hand with our custom SlotFillingDialog class
		// because they are both based on the provided Dialog class.
		this.dialogs.add(new SlotFillingDialog('address', addressSlots));
		this.dialogs.add(new SlotFillingDialog('fullname', fullnameSlots));
		this.dialogs.add(new TextPrompt('text'));
		this.dialogs.add(new NumberPrompt('number'));
		this.dialogs.add(new NumberPrompt('shoesize', this.shoeSizeValidator));
		this.dialogs.add(new SlotFillingDialog('slot-dialog', slots));

		// Finally, add a 2-step WaterfallDialog that will initiate the SlotFillingDialog,
		// and then collect and display the results.
		this.dialogs.add(new WaterfallDialog('root', [
			this.startDialog.bind(this),
			this.processResults.bind(this)
		]));
	}
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 19.custom-dialogs / bot.js View on Github external
// to both the fullname and address questions defined above.
        const slots = [
            new SlotDetails('fullname', 'fullname'),
            new SlotDetails('age', 'number', 'Please enter your age.'),
            new SlotDetails('shoesize', 'shoesize', 'Please enter your shoe size.', 'You must enter a size between 0 and 16. Half sizes are acceptable.'),
            new SlotDetails('address', 'address')
        ];

        // Add the individual child dialogs and prompts used.
        // Note that the built-in prompts work hand-in-hand with our custom SlotFillingDialog class
        // because they are both based on the provided Dialog class.
        this.dialogs.add(new SlotFillingDialog('address', addressSlots));
        this.dialogs.add(new SlotFillingDialog('fullname', fullnameSlots));
        this.dialogs.add(new TextPrompt('text'));
        this.dialogs.add(new NumberPrompt('number'));
        this.dialogs.add(new NumberPrompt('shoesize', this.shoeSizeValidator));
        this.dialogs.add(new SlotFillingDialog('slot-dialog', slots));

        // Finally, add a 2-step WaterfallDialog that will initiate the SlotFillingDialog,
        // and then collect and display the results.
        this.dialogs.add(new WaterfallDialog('root', [
            this.startDialog.bind(this),
            this.processResults.bind(this)
        ]));
    }
github microsoft / botbuilder-js / samples / dialogs / prompts-ts / src / app.ts View on Github external
// Show menu if no response sent
            if (!context.responded) {
                await dc.beginDialog('mainMenu');
            }
        }
    });
});

const dialogs = new DialogSet();
    
// Add prompts
dialogs.add('choicePrompt', new ChoicePrompt());
dialogs.add('confirmPrompt', new ConfirmPrompt());
dialogs.add('datetimePrompt', new DatetimePrompt());
dialogs.add('numberPrompt', new NumberPrompt());
dialogs.add('textPrompt', new TextPrompt());
dialogs.add('attachmentPrompt', new AttachmentPrompt());

    
//-----------------------------------------------
// Main Menu
//-----------------------------------------------

dialogs.add('mainMenu', [
    async function(dc) {
        function choice(title: string, value: string): Choice {
            return {
                value: value,
                action: { type: ActionTypes.ImBack, title: title, value: title }
            };
        }
github microsoft / BotFramework-Samples / SDKV4-Samples / js / DialogPromptBot / bot.js View on Github external
constructor(conversationState) {
        // Creates our state accessor properties.
        // See https://aka.ms/about-bot-state-accessors to learn more about the bot state and state accessors.
        this.dialogStateAccessor = conversationState.createProperty(DIALOG_STATE_ACCESSOR);
        this.reservationAccessor = conversationState.createProperty(RESERVATION_ACCESSOR);
        this.conversationState = conversationState;

        // Create the dialog set and add the prompts, including custom validation.
        this.dialogSet = new DialogSet(this.dialogStateAccessor);
        this.dialogSet.add(new NumberPrompt(SIZE_RANGE_PROMPT, this.rangeValidator));
        this.dialogSet.add(new ChoicePrompt(LOCATION_PROMPT));
        this.dialogSet.add(new DateTimePrompt(RESERVATION_DATE_PROMPT, this.dateValidator));

        // Define the steps of the waterfall dialog and add it to the set.
        this.dialogSet.add(new WaterfallDialog(RESERVATION_DIALOG, [
            this.promptForPartySize.bind(this),
            this.promptForLocation.bind(this),
            this.promptForReservationDate.bind(this),
            this.acknowledgeReservation.bind(this),
        ]));
    }
github microsoft / botbuilder-js / libraries / botbuilder-ai / samples / 53.book-table-bot / dialog / index.js View on Github external
// Add control flow dialogs
        this.addDialog(
            new WaterfallDialog(TABLE_BOOK_DIALOG, [
                this.welcomeStep.bind(this),
                this.locationStep.bind(this),
                this.patySizePrompt.bind(this),
                this.timePrompt.bind(this),
                this.confirmPrompt.bind(this),
                this.confirmReadoutPrompt.bind(this)
            ])
        );

        this.addDialog(new TextPrompt(WELCOME_PROMPT));
        this.addDialog(new TextPrompt(LOCATION_PROMPT));
        this.addDialog(new NumberPrompt(PARTY_SIZE_PROMPT));
        this.addDialog(new TextPrompt(TIME_PROMPT));
        this.addDialog(new ConfirmPrompt(CONFIRM_PROMPT));
        this.addDialog(new TextPrompt(BOOKING_CONFIRMATION_READOUT_PROMPT));

        // Save off our state accessor for later use
        this.userProfileStateAccessor = userProfileStateAccessor;
        this.lgEntitiesStateAccessor = lgEntitiesStateAccessor;
    }
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 19.custom-dialogs / bot.js View on Github external
// Link the questions together into a parent group that contains references
        // to both the fullname and address questions defined above.
        const slots = [
            new SlotDetails('fullname', 'fullname'),
            new SlotDetails('age', 'number', 'Please enter your age.'),
            new SlotDetails('shoesize', 'shoesize', 'Please enter your shoe size.', 'You must enter a size between 0 and 16. Half sizes are acceptable.'),
            new SlotDetails('address', 'address')
        ];

        // Add the individual child dialogs and prompts used.
        // Note that the built-in prompts work hand-in-hand with our custom SlotFillingDialog class
        // because they are both based on the provided Dialog class.
        this.dialogs.add(new SlotFillingDialog('address', addressSlots));
        this.dialogs.add(new SlotFillingDialog('fullname', fullnameSlots));
        this.dialogs.add(new TextPrompt('text'));
        this.dialogs.add(new NumberPrompt('number'));
        this.dialogs.add(new NumberPrompt('shoesize', this.shoeSizeValidator));
        this.dialogs.add(new SlotFillingDialog('slot-dialog', slots));

        // Finally, add a 2-step WaterfallDialog that will initiate the SlotFillingDialog,
        // and then collect and display the results.
        this.dialogs.add(new WaterfallDialog('root', [
            this.startDialog.bind(this),
            this.processResults.bind(this)
        ]));
    }
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 05.multi-turn-prompt / dialogs / userProfileDialog.js View on Github external
constructor(userState) {
        super('userProfileDialog');

        this.userProfile = userState.createProperty(USER_PROFILE);

        this.addDialog(new TextPrompt(NAME_PROMPT));
        this.addDialog(new ChoicePrompt(CHOICE_PROMPT));
        this.addDialog(new ConfirmPrompt(CONFIRM_PROMPT));
        this.addDialog(new NumberPrompt(NUMBER_PROMPT, this.agePromptValidator));
        this.addDialog(new AttachmentPrompt(ATTACHMENT_PROMPT, this.picturePromptValidator));

        this.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
            this.transportStep.bind(this),
            this.nameStep.bind(this),
            this.nameConfirmStep.bind(this),
            this.ageStep.bind(this),
            this.pictureStep.bind(this),
            this.confirmStep.bind(this),
            this.summaryStep.bind(this)
        ]));

        this.initialDialogId = WATERFALL_DIALOG;
    }
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / language-generation / 05.multi-turn-prompt / dialogs / userProfileDialog.js View on Github external
constructor(userState) {
        super('userProfileDialog');

        this.userProfile = userState.createProperty(USER_PROFILE);

        this.addDialog(new TextPrompt(NAME_PROMPT));
        this.addDialog(new ChoicePrompt(CHOICE_PROMPT));
        this.addDialog(new ConfirmPrompt(CONFIRM_PROMPT));
        this.addDialog(new NumberPrompt(NUMBER_PROMPT, this.agePromptValidator));

        this.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
            this.transportStep.bind(this),
            this.nameStep.bind(this),
            this.nameConfirmStep.bind(this),
            this.ageStep.bind(this),
            this.confirmStep.bind(this),
            this.summaryStep.bind(this)
        ]));

        this.initialDialogId = WATERFALL_DIALOG;

        this.lgTemplates = Templates.parseFile('./Resources/UserProfileDialog.lg');
    }