UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

75 lines 3.06 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.TextTemplate = void 0; const templateEngineLanguageGenerator_1 = require("../generators/templateEngineLanguageGenerator"); const languageGeneratorExtensions_1 = require("../languageGeneratorExtensions"); /** * Defines a text template where the template expression is local aka "inline" * and processed through registered language generator. */ class TextTemplate { /** * Initialize a new instance of TextTemplate class. * * @param template The template to evaluate to create text. */ constructor(template) { this.toString = () => { return `TextTemplate(${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) { throw new Error(`ArgumentNullException: ${this.template}`); } let languageGenerator = dialogContext.services.get(languageGeneratorExtensions_1.languageGeneratorKey); languageGenerator !== null && languageGenerator !== void 0 ? languageGenerator : (languageGenerator = new templateEngineLanguageGenerator_1.TemplateEngineLanguageGenerator()); const lgResult = yield languageGenerator.generate(dialogContext, this.template, data); return lgResult ? lgResult.toString() : ''; }); } } exports.TextTemplate = TextTemplate; TextTemplate.$kind = 'Microsoft.TextTemplate'; //# sourceMappingURL=textTemplate.js.map