botbuilder-dialogs-adaptive
Version:
Rule system for the Microsoft BotBuilder dialog system.
110 lines • 4.83 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.EditActions = void 0;
const actionChangeType_1 = require("../actionChangeType");
const actionContext_1 = require("../actionContext");
const converters_1 = require("../converters");
const botbuilder_1 = require("botbuilder");
const adaptive_expressions_1 = require("adaptive-expressions");
const botbuilder_dialogs_1 = require("botbuilder-dialogs");
/**
* Class which allows you to edit the current actions.
*/
class EditActions extends botbuilder_dialogs_1.Dialog {
/**
* Initializes a new instance of the [EditActions](xref:botbuilder-dialogs-adaptive.EditActions) class.
*
* @param changeType Optional. [ActionChangeType](xref:botbuilder-dialogs-adaptive.ActionChangeType), type of change to apply to the active actions.
* @param actions Optional. Child [Dialog](xref:botbuilder-dialogs.Dialog) dependencies so they can be added to the containers dialogset.
*/
constructor(changeType, actions) {
super();
/**
* The actions to update the dialog with.
*/
this.actions = [];
if (changeType) {
this.changeType = new adaptive_expressions_1.EnumExpression(changeType);
}
if (actions) {
this.actions = actions;
}
}
/**
* @param property The key of the conditional selector configuration.
* @returns The converter for the selector configuration.
*/
getConverter(property) {
switch (property) {
case 'actions':
return converters_1.DialogListConverter;
case 'changeType':
return new adaptive_expressions_1.EnumExpressionConverter(actionChangeType_1.ActionChangeType);
case 'disabled':
return new adaptive_expressions_1.BoolExpressionConverter();
default:
return super.getConverter(property);
}
}
/**
* Gets the child [Dialog](xref:botbuilder-dialogs.Dialog) dependencies so they can be added to the containers [Dialog](xref:botbuilder-dialogs.Dialog) set.
*
* @returns The child [Dialog](xref:botbuilder-dialogs.Dialog) dependencies.
*/
getDependencies() {
return this.actions;
}
/**
* Starts a new [Dialog](xref:botbuilder-dialogs.Dialog) and pushes it 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();
}
if (dc.parent instanceof actionContext_1.ActionContext) {
const planActions = this.actions.map((action) => {
return {
dialogStack: [],
dialogId: action.id,
options: options,
};
});
const changes = {
changeType: this.changeType.getValue(dc.state),
actions: planActions,
};
dc.parent.queueChanges(changes);
return yield dc.endDialog();
}
else {
throw new Error('EditActions should only be used in the context of an adaptive dialog.');
}
});
}
/**
* @protected
* Builds the compute Id for the [Dialog](xref:botbuilder-dialogs.Dialog).
* @returns A `string` representing the compute Id.
*/
onComputeId() {
const idList = this.actions.map((action) => action.id);
return `EditActions[${this.changeType.toString()}|${botbuilder_1.StringUtils.ellipsis(idList.join(','), 50)}]`;
}
}
exports.EditActions = EditActions;
EditActions.$kind = 'Microsoft.EditActions';
//# sourceMappingURL=editActions.js.map