UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

77 lines 3.1 kB
"use strict"; /** * @module botbuilder-dialogs-adaptive */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ 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.ActivityTemplate = void 0; const botbuilder_1 = require("botbuilder"); const generators_1 = require("../generators"); const languageGeneratorExtensions_1 = require("../languageGeneratorExtensions"); /** * Defines an activity template where the template expression is local aka "inline" * and processed through registered language generator. */ class ActivityTemplate { /** * Initialize a new instance of ActivityTemplate class. * * @param template The template to evaluate to create the activity. */ constructor(template) { this.toString = () => { return `ActivityTemplate(${this.template})`; }; this.template = template; } /** * @param _property The key of the conditional selector configuration. * @returns The converter for the selector configuration. */ getConverter(_property) { return undefined; } /** * @param config The configuration. * @returns A object with the given configuration. */ configure(config) { const { template } = config; this.template = template; return this; } /** * Bind data to template. * * @param dialogContext DialogContext * @param data Data to bind to. * @returns A promise representing the asynchronous operation. */ bind(dialogContext, data) { return __awaiter(this, void 0, void 0, function* () { if (this.template) { let languageGenerator = dialogContext.services.get(languageGeneratorExtensions_1.languageGeneratorKey); languageGenerator !== null && languageGenerator !== void 0 ? languageGenerator : (languageGenerator = new generators_1.TemplateEngineLanguageGenerator()); const lgResult = yield languageGenerator.generate(dialogContext, this.template, data); const result = botbuilder_1.ActivityFactory.fromObject(lgResult); return result; } return undefined; }); } } exports.ActivityTemplate = ActivityTemplate; ActivityTemplate.$kind = 'Microsoft.ActivityTemplate'; //# sourceMappingURL=activityTemplate.js.map