UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

70 lines 2.82 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.ChoiceOptionsSet = void 0; const languageGeneratorExtensions_1 = require("../languageGeneratorExtensions"); /** * Sets the ChoiceFactoryOptions. */ class ChoiceOptionsSet { /** * Initializes a new instance of the [ChoiceOptionsSet](xref:botbuilder-dialogs-adaptive.ChoiceOptionsSet) class. * * @param obj Choice values. */ constructor(obj) { if (typeof obj === 'string') { this.template = obj; } } /** * Bind data to template. * * @param dialogContext DialogContext * @param data Data to bind to. * @returns Data binded ChoiceFactoryOptions. */ bind(dialogContext, data) { return __awaiter(this, void 0, void 0, function* () { if (this.template == null) { return this; } const languageGenerator = dialogContext.services.get(languageGeneratorExtensions_1.languageGeneratorKey); if (languageGenerator == null) { throw new Error('language generator is missing.'); } const lgResult = yield languageGenerator.generate(dialogContext, this.template, data); if (lgResult instanceof ChoiceOptionsSet) { return lgResult; } else if (typeof lgResult === 'string') { try { const jObj = JSON.parse(lgResult); const options = { inlineSeparator: jObj[0].toString(), inlineOr: jObj[1].toString(), inlineOrMore: jObj[2].toString(), }; if (Object.keys(jObj).length > 3) { options.includeNumbers = Boolean(jObj[3]); } return options; } catch (_a) { return null; } } return null; }); } } exports.ChoiceOptionsSet = ChoiceOptionsSet; //# sourceMappingURL=choiceOptionsSet.js.map