How to use the botbuilder-dialogs.DatetimePrompt 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 / BotFramework-Samples / docs-samples / V4 / JS / contosocafebot-luis-dialogs / lib / luisbot.js View on Github external
}
        }
    }));
});
// Add dialogs
dialogs.add('default', [
    function (dc, args) {
        return __awaiter(this, void 0, void 0, function* () {
            const state = conversationState.get(dc.context);
            yield dc.context.sendActivity(`Hi! I'm the Contoso Cafe reservation bot. Say something like make a reservation."`);
            yield dc.end();
        });
    }
]);
dialogs.add('textPrompt', new botbuilder_dialogs_1.TextPrompt());
dialogs.add('dateTimePrompt', new botbuilder_dialogs_1.DatetimePrompt());
dialogs.add('reserveTable', [
    function (dc, args, next) {
        return __awaiter(this, void 0, void 0, function* () {
            var typedresult = args;
            // Call a helper function to save the entities in the LUIS result
            // to dialog state
            yield SaveEntities(dc, typedresult);
            yield dc.context.sendActivity("Welcome to the reservation service.");
            if (dc.activeDialog.state.dateTime) {
                yield next();
            }
            else {
                yield dc.prompt('dateTimePrompt', "Please provide a reservation date and time. We're open 4PM-8PM.");
            }
        });
    },
github microsoft / botbuilder-js / samples / dialogs / alarmbot-ts / lib / addAlarmDialog.js View on Github external
// Confirm to user
                    yield dc.context.sendActivity(`Your alarm named "${alarm.title}" is set for "${moment(alarm.time).format("ddd, MMM Do, h:mm a")}".`);
                    yield dc.endDialog();
                });
            }
        ]);
        this.dialogs.add('titlePrompt', new botbuilder_dialogs_1.TextPrompt((context, value) => __awaiter(this, void 0, void 0, function* () {
            if (!value || value.length < 3) {
                yield context.sendActivity(`Title should be at least 3 characters long.`);
                return undefined;
            }
            else {
                return value.trim();
            }
        })));
        this.dialogs.add('timePrompt', new botbuilder_dialogs_1.DatetimePrompt((context, values) => __awaiter(this, void 0, void 0, function* () {
            try {
                if (!Array.isArray(values) || values.length < 0) {
                    throw new Error('missing time');
                }
                if (values[0].type !== 'datetime') {
                    throw new Error('unsupported type');
                }
                const value = new Date(values[0].value);
                if (value.getTime() < new Date().getTime()) {
                    throw new Error('in the past');
                }
                return value;
            }
            catch (err) {
                yield context.sendActivity(`Please enter a valid time in the future like "tomorrow at 9am" or say "cancel".`);
                return undefined;
github microsoft / botbuilder-js / samples / dialogs / prompts-ts / src / app.ts View on Github external
await dc.continueDialog();

            // 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 / botbuilder-js / samples / dialogs / prompts-ts / lib / app.js View on Github external
yield dc.endAll();
            }
            // Continue the current dialog
            yield dc.continueDialog();
            // Show menu if no response sent
            if (!context.responded) {
                yield dc.beginDialog('mainMenu');
            }
        }
    }));
});
const dialogs = new botbuilder_dialogs_1.DialogSet();
// Add prompts
dialogs.add('choicePrompt', new botbuilder_dialogs_1.ChoicePrompt());
dialogs.add('confirmPrompt', new botbuilder_dialogs_1.ConfirmPrompt());
dialogs.add('datetimePrompt', new botbuilder_dialogs_1.DatetimePrompt());
dialogs.add('numberPrompt', new botbuilder_dialogs_1.NumberPrompt());
dialogs.add('textPrompt', new botbuilder_dialogs_1.TextPrompt());
dialogs.add('attachmentPrompt', new botbuilder_dialogs_1.AttachmentPrompt());
//-----------------------------------------------
// Main Menu
//-----------------------------------------------
dialogs.add('mainMenu', [
    function (dc) {
        return __awaiter(this, void 0, void 0, function* () {
            function choice(title, value) {
                return {
                    value: value,
                    action: { type: botbuilder_1.ActionTypes.ImBack, title: title, value: title }
                };
            }
            yield dc.prompt('choicePrompt', `Select a demo to run:`, [
github microsoft / botbuilder-js / samples / dialogs / alarmbot-ts / src / addAlarmDialog.ts View on Github external
// Confirm to user
                await dc.context.sendActivity(`Your alarm named "${alarm.title}" is set for "${moment(alarm.time).format("ddd, MMM Do, h:mm a")}".`);
                await dc.end();
            })
        ]));
        
        this.dialogs.add('titlePrompt', new TextPrompt(async (context, value) => {
            if (!value || value.length < 3) {
                await context.sendActivity(`Title should be at least 3 characters long.`);
                return undefined;
            } else {
                return value.trim();
            }
        }));
        
        this.dialogs.add('timePrompt', new DatetimePrompt(async (context, values) => {
            try {
                if (!Array.isArray(values) || values.length < 0) { throw new Error('missing time') }
                if (values[0].type !== 'datetime') { throw new Error('unsupported type') }
                const value = new Date(values[0].value);
                if (value.getTime() < new Date().getTime()) { throw new Error('in the past') }
                return value;
            } catch (err) {
                await context.sendActivity(`Please enter a valid time in the future like "tomorrow at 9am" or say "cancel".`);
                return undefined;
            }
        }));
    }
}
github microsoft / BotFramework-Samples / docs-samples / V4 / JS / contosocafebot-luis-dialogs / src / luisbot.ts View on Github external
});
});


// Add dialogs
dialogs.add('default', [
    async function (dc, args) {
        const state = conversationState.get(dc.context);
        await dc.context.sendActivity(`Hi! I'm the Contoso Cafe reservation bot. Say something like make a reservation."`);
        await dc.end();
    }
]);


dialogs.add('textPrompt', new TextPrompt());
dialogs.add('dateTimePrompt', new DatetimePrompt());
dialogs.add('reserveTable', [
    async function(dc, args, next){
        var typedresult = args as CafeLUISModel;

        // Call a helper function to save the entities in the LUIS result
        // to dialog state
        await SaveEntities(dc, typedresult);

        await dc.context.sendActivity("Welcome to the reservation service.");
        
        if (dc.activeDialog.state.dateTime) {
            await next();     
        }
        else {
            await dc.prompt('dateTimePrompt', "Please provide a reservation date and time. We're open 4PM-8PM.");
        }
github microsoft / botbuilder-js / samples / luis-bot-es6 / app.js View on Github external
dialogs.add(
    'titlePrompt',
    new TextPrompt(async (dc, value) => {
        if (!value || value.length < 3) {
            await dc.context.sendActivity(`Title should be at least 3 characters long.`);
            return undefined;
        } else {
            return value.trim();
        }
    })
);

dialogs.add(
    'timePrompt',
    new DatetimePrompt(async (dc, values) => {
        try {
            if (!Array.isArray(values) || values.length < 0) {
                throw new Error('missing time');
            }
            const value = moment(values[0].value, 'hh:mm a');

            if (value.toDate().getTime() < new Date().getTime()) {
                throw new Error('in the past');
            }
            return value;
        } catch (err) {
            await dc.context.sendActivity(`Please enter a valid time in the future like "tomorrow at 9am" or say "cancel".`);
            return undefined;
        }
    })
);