Skip to content

Instantly share code, notes, and snippets.

@steveandroulakis
Created May 30, 2019 03:48
Show Gist options
  • Save steveandroulakis/ab7bffd87b6546f85abddf2f4f9a67cc to your computer and use it in GitHub Desktop.
Save steveandroulakis/ab7bffd87b6546f85abddf2f4f9a67cc to your computer and use it in GitHub Desktop.
In case anyone wants to use APL with the Alexa-App framework (https://github.com/alexa-js/alexa-app)
// Making alexa-app work for APL
var alexa = require("alexa-app");
var app = new alexa.app();
// any old APL document will do
var testAplDoc = require('./templates/test_apl.json')
// determines if the device has a screen
var has_display = function (request) {
try {
if ('Alexa.Presentation.APL' in request.data.context.System.device.supportedInterfaces) {
return true;
};
return false;
} catch (e) {
return false;
}
};
// on launch, displays an APL screen
app.launch(function (request, response) {
response.say("OK").send();
if (has_display(request)) {
response.response.response.directives.push(testAplDoc);
response.shouldEndSession(false);
response.say("SCREEN").send();
}
// because this is an async handler
return false;
});
// Catches an APL TouchWrapper event and says the argument
app.on('Alexa.Presentation.APL.UserEvent', function (request, response) {
var componentArgument = request.data.request.arguments[0];
console.log(componentArgument);
response.shouldEndSession(false);
response.say(componentArgument).send();
return false;
})
// connect to lambda
exports.handler = app.lambda();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment