botbuilder-dialogs-adaptive
Version:
Rule system for the Microsoft BotBuilder dialog system.
65 lines • 2.86 kB
JavaScript
;
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.TextInput = void 0;
const inputDialog_1 = require("./inputDialog");
const adaptive_expressions_1 = require("adaptive-expressions");
/**
* Declarative text input to gather text data from users.
*/
class TextInput 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 'outputFormat':
return new adaptive_expressions_1.StringExpressionConverter();
default:
return super.getConverter(property);
}
}
/**
* @protected
* @returns A `string` representing the compute Id.
*/
onComputeId() {
return `TextInput[${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) {
return __awaiter(this, void 0, void 0, function* () {
// Treat input as a string
let input = dc.state.getValue(inputDialog_1.InputDialog.VALUE_PROPERTY);
if (typeof input !== 'string') {
return inputDialog_1.InputState.invalid;
}
if (this.outputFormat) {
const value = this.outputFormat.getValue(dc.state);
if (value && value.trim()) {
input = value;
}
}
// Save formated value and ensure length > 0
dc.state.setValue(inputDialog_1.InputDialog.VALUE_PROPERTY, input);
return input.length > 0 ? inputDialog_1.InputState.valid : inputDialog_1.InputState.unrecognized;
});
}
}
exports.TextInput = TextInput;
TextInput.$kind = 'Microsoft.TextInput';
//# sourceMappingURL=textInput.js.map