UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

105 lines 4.76 kB
"use strict"; /** * @module botbuilder-dialogs-adaptive */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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.DateTimeInput = void 0; const adaptive_expressions_1 = require("adaptive-expressions"); const inputDialog_1 = require("./inputDialog"); // eslint-disable-next-line import/no-extraneous-dependencies const Recognizers = __importStar(require("@microsoft/recognizers-text-date-time")); /** * Input dialog to collect a datetime from the user. */ class DateTimeInput extends inputDialog_1.InputDialog { /** * @param property The key of the conditional selector configuration. * @returns The converter for the selector configuration. */ getConverter(property) { switch (property) { case 'defaultLocale': return new adaptive_expressions_1.StringExpressionConverter(); case 'outputFormat': return new adaptive_expressions_1.StringExpressionConverter(); default: return super.getConverter(property); } } /** * @protected * @returns A `string` representing the compute Id. */ onComputeId() { return `DateTimeInput[${this.prompt && this.prompt.toString()}]`; } /** * @protected * Called when input has been received. * @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation. * @returns [InputState](xref:botbuilder-dialogs-adaptive.InputState) which reflects whether input was recognized as valid or not. */ onRecognizeInput(dc) { var _a, _b; return __awaiter(this, void 0, void 0, function* () { // Recognize input and filter out non-attachments const input = dc.state.getValue(inputDialog_1.InputDialog.VALUE_PROPERTY); /** * @deprecated Note: Default locale will be considered for deprecation as part of 4.13. */ const locale = (_a = dc.getLocale()) !== null && _a !== void 0 ? _a : (_b = this.defaultLocale) === null || _b === void 0 ? void 0 : _b.getValue(dc.state); const results = Recognizers.recognizeDateTime(input.toString(), locale); if (results.length > 0 && results[0].resolution) { const values = results[0].resolution.values; dc.state.setValue(inputDialog_1.InputDialog.VALUE_PROPERTY, values); if (this.outputFormat) { const value = this.outputFormat.getValue(dc.state); dc.state.setValue(inputDialog_1.InputDialog.VALUE_PROPERTY, value); } } else { return inputDialog_1.InputState.unrecognized; } return inputDialog_1.InputState.valid; }); } } exports.DateTimeInput = DateTimeInput; DateTimeInput.$kind = 'Microsoft.DateTimeInput'; //# sourceMappingURL=dateTimeInput.js.map