@corux/ask-extensions
Version:
Extensions to improve development with Alexa Skills Kit SDK
53 lines • 2.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function getSupportedInterfaces(handlerInput) {
return handlerInput.requestEnvelope.context
&& handlerInput.requestEnvelope.context.System
&& handlerInput.requestEnvelope.context.System.device
&& handlerInput.requestEnvelope.context.System.device.supportedInterfaces
|| {};
}
function supportsDisplay(handlerInput) {
return !!getSupportedInterfaces(handlerInput).Display;
}
function supportsApl(handlerInput) {
return !!getSupportedInterfaces(handlerInput)["Alexa.Presentation.APL"];
}
function isPlaybackController(handlerInput) {
return handlerInput.requestEnvelope.request.type.startsWith("PlaybackController");
}
function getResponseBuilder(handlerInput) {
var builder = handlerInput.responseBuilder;
builder.if = function (condition, callback) {
var result = typeof condition === "function"
? condition(handlerInput.requestEnvelope)
: condition;
if (result) {
callback(builder);
}
return builder;
};
builder.speakIfSupported = function (speechOutput, playBehavior) {
return builder.if(!isPlaybackController(handlerInput), function (n) {
n.speak(speechOutput, playBehavior);
});
};
builder.addRenderTemplateDirectiveIfSupported = function (template) {
return builder.if(supportsDisplay(handlerInput), function (n) {
n.addRenderTemplateDirective(template);
});
};
builder.addHintDirectiveIfSupported = function (text) {
return builder.if(supportsDisplay(handlerInput), function (n) {
n.addHintDirective(text);
});
};
builder.addAplDirectiveIfSupported = function (directive) {
return builder.if(supportsApl(handlerInput), function (n) {
n.addDirective(directive);
});
};
return builder;
}
exports.getResponseBuilder = getResponseBuilder;
//# sourceMappingURL=ExtendedResponseBuilder.js.map