UNPKG

ask-sdk-v1adapter

Version:
132 lines 5.63 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.ResponseBuilder = void 0; const ask_sdk_1 = require("ask-sdk"); class ResponseBuilder { constructor(adapter) { this._responseObject = adapter.response; this._responseObject.sessionAttributes = adapter._event.session.attributes; this.responseHelper = ask_sdk_1.ResponseFactory.init().withShouldEndSession(true); } speak(speechOutput) { this.responseHelper.speak(speechOutput); this._responseObject.response = this.responseHelper.getResponse(); return this; } listen(repromptSpeechOutput) { this.responseHelper.reprompt(repromptSpeechOutput) .withShouldEndSession(false); this._responseObject.response = this.responseHelper.getResponse(); return this; } cardRenderer(cardTitle, cardContent, cardImage) { if (cardImage && cardImage.smallImageUrl && cardImage.largeImageUrl) { this.responseHelper.withStandardCard(cardTitle, cardContent, cardImage.smallImageUrl, cardImage.largeImageUrl); } else if (cardImage && cardImage.smallImageUrl) { this.responseHelper.withStandardCard(cardTitle, cardContent, cardImage.smallImageUrl); } else if (cardImage && cardImage.largeImageUrl) { this.responseHelper.withStandardCard(cardTitle, cardContent, cardImage.largeImageUrl); } else { this.responseHelper.withSimpleCard(cardTitle, cardContent); } this._responseObject.response = this.responseHelper.getResponse(); return this; } linkAccountCard() { this.responseHelper.withLinkAccountCard(); this._responseObject.response = this.responseHelper.getResponse(); return this; } askForPermissionsConsentCard(permissions) { this.responseHelper.withAskForPermissionsConsentCard(permissions); this._responseObject.response = this.responseHelper.getResponse(); return this; } delegate(intent) { this.responseHelper.addDelegateDirective(intent) .withShouldEndSession(false); this._responseObject.response = this.responseHelper.getResponse(); return this; } elicitSlot(slotName, updatedIntent) { this.responseHelper.addElicitSlotDirective(slotName, updatedIntent) .withShouldEndSession(false); this._responseObject.response = this.responseHelper.getResponse(); return this; } confirmSlot(slotName, updatedIntent) { this.responseHelper.addConfirmSlotDirective(slotName, updatedIntent) .withShouldEndSession(false); this._responseObject.response = this.responseHelper.getResponse(); return this; } confirmIntent(updatedIntent) { this.responseHelper.addConfirmIntentDirective(updatedIntent) .withShouldEndSession(false); this._responseObject.response = this.responseHelper.getResponse(); return this; } audioPlayerPlay(behavior, url, audioToken, expectedPreviousToken, offsetInMilliseconds) { this.responseHelper.addAudioPlayerPlayDirective(behavior, url, audioToken, offsetInMilliseconds, expectedPreviousToken); this._responseObject.response = this.responseHelper.getResponse(); return this; } audioPlayerStop() { this.responseHelper.addAudioPlayerStopDirective(); this._responseObject.response = this.responseHelper.getResponse(); return this; } audioPlayerClearQueue(clearBehavior) { this.responseHelper.addAudioPlayerClearQueueDirective(clearBehavior); this._responseObject.response = this.responseHelper.getResponse(); return this; } renderTemplate(template) { this.responseHelper.addRenderTemplateDirective(template); this._responseObject.response = this.responseHelper.getResponse(); return this; } hint(hintText) { this.responseHelper.addHintDirective(hintText); this._responseObject.response = this.responseHelper.getResponse(); return this; } playVideo(source, metadata) { if (metadata) { this.responseHelper.addVideoAppLaunchDirective(source, metadata.title, metadata.subtitle); } else { this.responseHelper.addVideoAppLaunchDirective(source); } this.responseHelper.withShouldEndSession(undefined); this._responseObject.response = this.responseHelper.getResponse(); return this; } shouldEndSession(val) { this.responseHelper.withShouldEndSession(val); this._responseObject.response = this.responseHelper.getResponse(); return this; } _addDirective(directive) { this.responseHelper.addDirective(directive); this._responseObject.response = this.responseHelper.getResponse(); return this; } } exports.ResponseBuilder = ResponseBuilder; //# sourceMappingURL=responseBuilderShim.js.map