How to use the botbuilder-dialogs.ComponentDialog 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.

github microsoft / botbuilder-js / samples / dialogs / alarmbot-ts / lib / dialogs / addAlarmDialog.js View on Github external
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const botbuilder_dialogs_1 = require("botbuilder-dialogs");
const moment = require("moment");
const timePrompt_1 = require("../prompts/timePrompt");
const titlePrompt_1 = require("../prompts/titlePrompt");
const START_DIALOG = 'start';
const TITLE_PROMPT = 'titlePrompt';
const TIME_PROMPT = 'timePrompt';
const TITLE_VALUE = 'title';
const TIME_VALUE = 'time';
class AddAlarmDialog extends botbuilder_dialogs_1.ComponentDialog {
    constructor(dialogId, alarmsProperty) {
        super(dialogId);
        this.alarmsProperty = alarmsProperty;
        // NOTE: since waterfall steps are passed in as a function to the waterfall dialog 
        // it will be called from the context of the waterfall dialog.  With javascript/typescript
        // you need to write this function as using the lambda syntax so that it captures the context of the this pointer
        // if you don't do this, the this pointer will be incorrect for waterfall steps.
        this.initializeValuesStep = (dc, step) => __awaiter(this, void 0, void 0, function* () {
            if (step.options && step.options.alarm) {
                step.values[TITLE_VALUE] = step.options.alarm.title;
                step.values[TIME_VALUE] = step.options.alarm.time;
            }
            return yield step.next();
        });
        this.promptForTitleStep = (dc, step) => __awaiter(this, void 0, void 0, function* () {
            // Prompt for title if missing
github microsoft / botbuilder-js / samples / dialogs / sequences-ts / lib / addAlarmDialog.js View on Github external
return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const botbuilder_dialogs_1 = require("botbuilder-dialogs");
const titlePrompt_1 = require("./prompts/titlePrompt");
const timePrompt_1 = require("./prompts/timePrompt");
const moment = require("moment");
const ADD_ALARM_DLG = 'addAlarm';
const TITLE_PROMPT_DLG = 'titlePrompt';
const TIME_PROMPT_DLG = 'timePrompt';
class AddAlarmDialog extends botbuilder_dialogs_1.ComponentDialog {
    constructor(dialogId, userState) {
        super(dialogId);
        // Add control flow dialogs (first added is initial dialog)
        this.add(new botbuilder_dialogs_1.SequenceDialog(ADD_ALARM_DLG, [
            new botbuilder_dialogs_1.PromptStep('title', TITLE_PROMPT_DLG, `What would you like to call your alarm?`),
            new botbuilder_dialogs_1.PromptStep('time', TIME_PROMPT_DLG, `What time would you like to set the alarm for?`),
            new botbuilder_dialogs_1.CodeStep((dc, step) => __awaiter(this, void 0, void 0, function* () {
                // Convert to Alarm
                const alarm = {
                    title: step.values['title'],
                    time: step.values['time'].toISOString()
                };
                // Set alarm.
                const user = userState.get(dc.context);
                user.alarms.push(alarm);
                // Confirm to user
github microsoft / botbuilder-js / samples / dialogs / sequences-ts / lib / showAlarmsDialog.js View on Github external
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const botbuilder_dialogs_1 = require("botbuilder-dialogs");
const moment = require("moment");
const SHOW_ALARMS_DLG = 'showAlarms';
class ShowAlarmsDialog extends botbuilder_dialogs_1.ComponentDialog {
    constructor(dialogId, userState) {
        super(dialogId);
        // Add control flow dialogs (first added is initial dialog)
        this.add(new botbuilder_dialogs_1.SequenceDialog(SHOW_ALARMS_DLG, [
            new botbuilder_dialogs_1.CodeStep((dc, step) => __awaiter(this, void 0, void 0, function* () {
                let msg = `No alarms found.`;
                const user = userState.get(dc.context);
                if (user.alarms.length > 0) {
                    msg = `**Current Alarms**\n\n`;
                    let connector = '';
                    user.alarms.forEach((alarm) => {
                        msg += connector + `- ${alarm.title} (${moment(alarm.time).format("ddd, MMM Do, h:mm a")})`;
                        connector = '\n';
                    });
                }
                yield dc.context.sendActivity(msg);
github microsoft / botbuilder-js / samples / dialogs / sequences-ts / lib / deleteAlarmDialog.js View on Github external
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const botbuilder_dialogs_1 = require("botbuilder-dialogs");
const DELETE_ALARM_DLG = 'deleteAlarm';
const DELETE_ALARM_MULTI_DLG = 'deleteAlarmMulti';
const DELETE_ALARM_SINGLE_DLG = 'deleteAlarmSingle';
const CHOICE_PROMPT_DLG = 'choicePrompt';
const CONFIRM_PROMPT_DLG = 'confirmPrompt';
class DeleteAlarmDialog extends botbuilder_dialogs_1.ComponentDialog {
    constructor(dialogId, userState) {
        super(dialogId);
        // Add control flow dialogs (first added is initial dialog)
        this.add(new botbuilder_dialogs_1.SequenceDialog(DELETE_ALARM_DLG, [
            new botbuilder_dialogs_1.CodeStep((dc, step) => __awaiter(this, void 0, void 0, function* () {
                // Divert to appropriate dialog
                const user = userState.get(dc.context);
                if (user.alarms.length > 1) {
                    return yield dc.begin(DELETE_ALARM_MULTI_DLG);
                }
                else if (user.alarms.length === 1) {
                    return yield dc.begin(DELETE_ALARM_SINGLE_DLG);
                }
                else {
                    yield dc.context.sendActivity(`No alarms set to delete.`);
                    return yield dc.end();
github microsoft / botbuilder-js / samples / dialogs / alarmbot-ts / lib / dialogs / showAlarmsDialog.js View on Github external
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const botbuilder_dialogs_1 = require("botbuilder-dialogs");
const moment = require("moment");
const START_DIALOG = 'start';
class ShowAlarmsDialog extends botbuilder_dialogs_1.ComponentDialog {
    constructor(dialogId, alarmsProperty) {
        super(dialogId);
        this.alarmsProperty = alarmsProperty;
    }
    // for single turn dialog, we can do it all here.
    onBeginDialog(dc, options) {
        return __awaiter(this, void 0, void 0, function* () {
            let msg = `No alarms found.`;
            const list = yield this.alarmsProperty.get(dc.context, []);
            if (list.length > 0) {
                msg = `**Current Alarms**\n\n`;
                let connector = '';
                list.forEach((alarm) => {
                    msg += connector + `- ${alarm.title} (${moment(alarm.time).format("ddd, MMM Do, h:mm a")})`;
                    connector = '\n';
                });
github microsoft / botbuilder-js / samples / dialogs / alarmbot-ts / lib / dialogs / deleteAlarmDialog.js View on Github external
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const botbuilder_dialogs_1 = require("botbuilder-dialogs");
const START_DIALOG = 'start';
const DELETE_MULTI_DIALOG = 'deleteMulti';
const DELETE_SINGLE_DIALOG = 'deleteSingle';
const CHOOSE_ALARM_PROMPT = 'chooseAlarm';
const CONFIRM_DELETE_PROMPT = 'confirmDelete';
class DeleteAlarmDialog extends botbuilder_dialogs_1.ComponentDialog {
    constructor(dialogId, alarmsProperty) {
        super(dialogId);
        this.alarmsProperty = alarmsProperty;
        this.chooseAlarmStep = (dc, step) => __awaiter(this, void 0, void 0, function* () {
            // Compute list of choices based on alarm titles
            const list = yield this.alarmsProperty.get(dc.context);
            const choices = list.map((value) => value.title);
            // Prompt user to pick from list
            return yield dc.prompt(CHOOSE_ALARM_PROMPT, { prompt: `Which alarm would you like to delete? Say "cancel" to quit.`, choices: choices });
        });
        this.deleteChosenAlarmStep = (dc, step) => __awaiter(this, void 0, void 0, function* () {
            // Delete alarm by position
            const choice = step.result;
            const list = yield this.alarmsProperty.get(dc.context);
            if (choice.index < list.length) {
                list.splice(choice.index, 1);