UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

111 lines 5.17 kB
"use strict"; 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.GetActivityMembers = void 0; const adaptive_expressions_1 = require("adaptive-expressions"); const botbuilder_dialogs_1 = require("botbuilder-dialogs"); /** * Calls `BotFrameworkAdapter.getActivityMembers()` and sets the result to a memory property. */ class GetActivityMembers extends botbuilder_dialogs_1.Dialog { /** * Initializes a new instance of the [GetActivityMembers](xref:botbuilder-dialogs-adaptive.GetActivityMembers) class. * * @param activityId Optional. The expression to get the value to put into property path. * @param property Optional. Property path to put the value in. */ constructor(activityId, property) { super(); if (activityId) { this.activityId = new adaptive_expressions_1.StringExpression(activityId); } if (property) { this.property = new adaptive_expressions_1.StringExpression(property); } } /** * @param property The key of the conditional selector configuration. * @returns The converter for the selector configuration. */ getConverter(property) { switch (property) { case 'activityId': return new adaptive_expressions_1.StringExpressionConverter(); case 'property': 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 id = dc.context.activity.id; if (this.activityId) { const value = this.activityId.getValue(dc.state); id = value.toString(); } const result = yield this.getActivityMembers(dc.context, id); dc.state.setValue(this.property.getValue(dc.state), result); return yield dc.endDialog(result); }); } getActivityMembers(context, activityId) { return __awaiter(this, void 0, void 0, function* () { // If no activity was passed in, use the current activity. if (!activityId) { activityId = context.activity.id; } if (!context.activity.conversation) { throw new Error('[GetActivityMembers]: Missing conversation'); } const conversationId = context.activity.conversation.id; if (!conversationId || conversationId.trim() === '') { throw new Error('[GetActivityMembers]: Missing conversation.id'); } const connectorClient = this.getConnectorClient(context); const accounts = yield connectorClient.conversations.getActivityMembers(conversationId, activityId); return accounts; }); } getConnectorClient(context) { var _a; const client = context.adapter && 'createConnectorClient' in context.adapter ? context.adapter.createConnectorClient(context.activity.serviceUrl) : (_a = context.turnState) === null || _a === void 0 ? void 0 : _a.get(context.adapter.ConnectorClientKey); if (!client) { throw new Error('This method requires a connector client.'); } return client; } /** * @protected * Builds the compute Id for the [Dialog](xref:botbuilder-dialogs.Dialog). * @returns A `string` representing the compute Id. */ onComputeId() { return `GetActivityMembers[${this.activityId ? this.activityId.toString() : ''}, ${this.property ? this.property.toString() : ''}]`; } } exports.GetActivityMembers = GetActivityMembers; GetActivityMembers.$kind = 'Microsoft.GetActivityMembers'; //# sourceMappingURL=getActivityMembers.js.map