UNPKG

intentful

Version:

Create Custom Skills with less headache

97 lines (96 loc) 3.79 kB
"use strict"; 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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Intent = void 0; const Alexa = __importStar(require("ask-sdk")); const helpers_1 = require("./helpers"); const types_1 = require("../types"); class Intent extends types_1.ModelProvider { constructor(props) { super(); this.props = props; } toJSON() { return this.model(); } getSlotModel() { var _a; return this.props.slots ? (_a = this.props.slots) === null || _a === void 0 ? void 0 : _a.map((slot) => { return { name: slot.name, multipleValues: slot.multipleValues, samples: slot.samples, type: slot.type, confirmationRequired: slot.confirmation !== undefined, elicitationRequired: slot.required !== undefined, prompts: { confirmation: slot.confirmation ? (0, helpers_1.hashValue)(slot.confirmation.prompts) : undefined, elicitation: slot.required ? (0, helpers_1.hashValue)(slot.required.prompts) : undefined } }; }) : []; } model() { const intentModel = { name: this.props.intentName, slots: this.getSlotModel(), samples: this.props.samples, delegationStrategy: this.props.delegationStrategy }; return intentModel; } usesDialog() { var _a; const countsOfDialogSlots = this.props.slots ? (_a = this.props.slots) === null || _a === void 0 ? void 0 : _a.filter((slot) => { return slot.confirmation !== undefined || slot.required !== undefined; }) : []; return this.props.confirmation !== undefined && countsOfDialogSlots.length > 0; } slotsUsingDialog() { var _a; return this.props.slots ? (_a = this.props.slots) === null || _a === void 0 ? void 0 : _a.filter((slot) => { return slot.required !== undefined || slot.confirmation !== undefined; }) : []; } getRequestHandlers() { const handler = { uniqueId: this.props.intentName, canHandle: (input) => { const requestType = Alexa.getRequestType(input.requestEnvelope); const canHandle = requestType === 'IntentRequest' && Alexa.getIntentName(input.requestEnvelope) === this.props.intentName; return canHandle; }, handle: (0, helpers_1.wrapHandler)(this.props.intentHandler) }; return [handler]; } } exports.Intent = Intent;