botbuilder-dialogs-adaptive
Version:
Rule system for the Microsoft BotBuilder dialog system.
90 lines • 4.29 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BeginDialog = void 0;
/**
* @module botbuilder-dialogs-adaptive
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
const baseInvokeDialog_1 = require("./baseInvokeDialog");
const adaptive_expressions_1 = require("adaptive-expressions");
const botbuilder_dialogs_1 = require("botbuilder-dialogs");
/**
* Action which begins executing another [Dialog](xref:botbuilder-dialogs.Dialog), when it is done, it will return to the caller.
*/
class BeginDialog extends baseInvokeDialog_1.BaseInvokeDialog {
/**
* Creates a new [BeginDialog](xref:botbuilder-dialogs-adaptive.BeginDialog) instance.
*
* @param dialogIdToCall Optional. ID of the [Dialog](xref:botbuilder-dialogs.Dialog) to call.
* @param options Optional. Static options to pass the called dialog.
*/
constructor(dialogIdToCall, options) {
super(dialogIdToCall, options);
}
/**
* @param property The key of the conditional selector configuration.
* @returns The converter for the selector configuration.
*/
getConverter(property) {
switch (property) {
case 'resultProperty':
return new adaptive_expressions_1.StringExpressionConverter();
case 'disabled':
return new adaptive_expressions_1.BoolExpressionConverter();
default:
return super.getConverter(property);
}
}
/**
* Called when the [Dialog](xref:botbuilder-dialogs.Dialog) is started and pushed onto the dialog stack.
*
* @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation.
* @param options Optional. Initial information to pass to the dialog.
* @returns A `Promise` representing the asynchronous operation.
*/
beginDialog(dc, options) {
return __awaiter(this, void 0, void 0, function* () {
if (this.disabled && this.disabled.getValue(dc.state)) {
return yield dc.endDialog();
}
const dialog = this.resolveDialog(dc);
// use bindingOptions to bind to the bound options
const boundOptions = this.bindOptions(dc, options);
// set the activity processed state (default is true)
dc.state.setValue(botbuilder_dialogs_1.TurnPath.activityProcessed, this.activityProcessed.getValue(dc.state));
return yield dc.beginDialog(dialog.id, boundOptions);
});
}
/**
* Called when a child [Dialog](xref:botbuilder-dialogs.Dialog) completed its turn, returning control to this dialog.
*
* @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation.
* @param reason [DialogReason](xref:botbuilder-dialogs.DialogReason), reason why the dialog resumed.
* @param result Optional. Value returned from the dialog that was called. The type
* of the value returned is dependent on the child dialog.
* @returns A `Promise` representing the asynchronous operation.
*/
resumeDialog(dc, reason, result = null) {
return __awaiter(this, void 0, void 0, function* () {
if (this.resultProperty) {
dc.state.setValue(this.resultProperty.getValue(dc.state), result);
}
return yield dc.endDialog(result);
});
}
}
exports.BeginDialog = BeginDialog;
BeginDialog.$kind = 'Microsoft.BeginDialog';
//# sourceMappingURL=beginDialog.js.map