Returning APL-A Responses
Up until this point, anytime we want Alexa to speak anything to the user in response to a request, we have used the speak() function on the response builder, like this:
| return handlerInput.responseBuilder |
| .speak("Hello world!") |
| .getResponse(); |
But now we’re going to ask Alexa to send back audio rendered from an APL-A template, so we’ll need to do something a little different. Instead of calling speak(), we’ll return a directive that tells Alexa to send audio from a given template. The code to build your response builder will change to look something like this:
| return handlerInput.responseBuilder |
| .addDirective({ |
| "type": "Alexa.Presentation.APLA.RenderDocument", |
| "document": { |
| // APL-A document ... |
Get Build Talking Apps for Alexa now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.