botbuilder-dialogs-adaptive
Version:
Rule system for the Microsoft BotBuilder dialog system.
88 lines • 3.9 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.SignOutUser = void 0;
const adaptive_expressions_1 = require("adaptive-expressions");
const botbuilder_dialogs_1 = require("botbuilder-dialogs");
/**
* Singns out the user and finishes the dialog.
*/
class SignOutUser extends botbuilder_dialogs_1.Dialog {
/**
* Initializes a new instance of the [SignOutUser](xref:botbuilder-dialogs-adaptive.SignOutUser) class.
*
* @param userId Optional. The expression which resolves to the userId to sign out.
* @param connectionName Optional. The name of the OAuth connection.
*/
constructor(userId, connectionName) {
super();
if (userId) {
this.userId = new adaptive_expressions_1.StringExpression(userId);
}
if (connectionName) {
this.connectionName = new adaptive_expressions_1.StringExpression(connectionName);
}
}
/**
* @param property The key of the conditional selector configuration.
* @returns The converter for the selector configuration.
*/
getConverter(property) {
switch (property) {
case 'userId':
return new adaptive_expressions_1.StringExpressionConverter();
case 'connectionName':
return new adaptive_expressions_1.StringExpressionConverter();
case 'disabled':
return new adaptive_expressions_1.BoolExpressionConverter();
default:
return super.getConverter(property);
}
}
/**
* 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();
}
let userId;
if (this.userId) {
userId = this.userId.getValue(dc.state);
}
const connectionName = this.connectionName.getValue(dc.state);
const adapter = dc.context.adapter;
if (typeof adapter['signOutUser'] === 'function') {
yield adapter['signOutUser'](dc.context, connectionName, userId);
return yield dc.endDialog();
}
else {
throw new Error('signOutUser() not supported by the current adapter.');
}
});
}
/**
* @protected
* Builds the compute Id for the [Dialog](xref:botbuilder-dialogs.Dialog).
* @returns A `string` representing the compute Id.
*/
onComputeId() {
return `SignOutUser[${this.connectionName ? this.connectionName.toString() : ''}, ${this.userId ? this.userId.toString() : ''}]`;
}
}
exports.SignOutUser = SignOutUser;
SignOutUser.$kind = 'Microsoft.SignOutUser';
//# sourceMappingURL=signOutUser.js.map