UNPKG

ask-sdk-core

Version:
63 lines 2.55 kB
"use strict"; /* * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * http://www.apache.org/licenses/LICENSE-2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.DelegateToIntentHandler = void 0; const RequestEnvelopeUtils_1 = require("../../../util/RequestEnvelopeUtils"); const ACDL_AUTOGEN_NAMESPACE = "com.amazon.autogenerated"; const SPLIT_CHAR = "_"; class DelegateToIntentHandler { canHandle(input) { if ((0, RequestEnvelopeUtils_1.getRequestType)(input.requestEnvelope) !== 'Dialog.API.Invoked') { return false; } if (!input.requestEnvelope.request.apiRequest || !input.requestEnvelope.request.apiRequest.name) { return false; } const apiName = input.requestEnvelope.request.apiRequest.name; if (!apiName.startsWith(ACDL_AUTOGEN_NAMESPACE)) { return false; } return true; } handle(input) { const apiRequest = input.requestEnvelope.request.apiRequest; const apiName = apiRequest.name; const intentName = (apiName.substring(apiName.indexOf(SPLIT_CHAR) + 1)); const directiveType = "Dialog.DelegateRequest"; const delegationTarget = "skill"; const updatedRequestType = "IntentRequest"; const delegationPeriod = { until: 'EXPLICIT_RETURN' }; const intent = { name: intentName, confirmationStatus: 'NONE', slots: (0, RequestEnvelopeUtils_1.generateSlotsFromApiRequest)(apiRequest) }; const updatedRequest = { type: updatedRequestType, intent }; const delegateRequestDirective = { type: directiveType, target: delegationTarget, period: delegationPeriod, updatedRequest }; return input.responseBuilder.addDirective(delegateRequestDirective).getResponse(); } } exports.DelegateToIntentHandler = DelegateToIntentHandler; //# sourceMappingURL=DelegateToIntentHandler.js.map