Trying to use Alexa presentation Language features in AWS hosted custom lambda function. Intent handler are firing but when I add the Alexa.getSupportedInterfaces it is failing . Message is "Error handled: Alexa.getSupportedInterfaces is not a function"


// 1. Intent Handlers =============================================
const LaunchRequest_Handler =  {
    canHandle(handlerInput) {
        const request = handlerInput.requestEnvelope.request;
        return request.type === 'LaunchRequest';
    },
    handle(handlerInput) {
       let responseBuilder = handlerInput.responseBuilder;


        let speakOutput = 'Welcome to test Bot. ';
      //  let skillTitle = capitalize(invocationName);

      // Add APL directive to response

        if (Alexa1.getSupportedInterfaces(handlerInput.requestEnvelope)['Alexa.Presentation.APL']) {

            // Add the RenderDocument directive to the responseBuilder
            responseBuilder.addDirective({
                type: 'Alexa.Presentation.APL.RenderDocument',
                token: Echo_Token,
                document: Customer
            });

            // Tailor the speech for a device with a screen.
            speakOutput += " You should now also see my greeting on the screen."
        } else {
            // User's device does not support APL, so tailor the speech to this situation
            speakOutput += " This example would be more interesting on a device with a screen, such as an Echo Show or Fire TV.";
        }
  return responseBuilder
            .speak(speakOutput)
            .withShouldEndSession(false)
            .reprompt('try again, ' + speakOutput)
             .withSimpleCard("CustomerSupport!", "CustomerSupport)")
           // .reprompt('add a reprompt if you want to keep the session open for the user to respond')
            //.withStandardCard('Welcome!', 
             // 'Hello!\nThis is a card for your skill, ' + skillTitle,
             //  welcomeCardImg.smallImageUrl, welcomeCardImg.largeImageUrl)
            .getResponse();
    },
};


1

There are 1 best solutions below

0
On

Instead of using the below condition:

Alexa1.getSupportedInterfaces(handlerInput.requestEnvelope['Alexa.Presentation.APL]

you can use, below condition to check if the device supports APL:

if (supportsAPL(handlerInput))

Make sure you include below functions definition in your index file:

function supportsAPL(handlerInput) { 
    const supportedInterfaces = handlerInput.requestEnvelope.context.System.device.supportedInterfaces;
    const aplInterface = supportedInterfaces['Alexa.Presentation.APL'];
    return aplInterface != null && aplInterface != undefined;
}

function supportsAPLT(handlerInput) {
    const supportedInterfaces = handlerInput.requestEnvelope.context.System.device.supportedInterfaces;
    const aplInterface = supportedInterfaces['Alexa.Presentation.APLT'];
    return aplInterface != null && aplInterface != undefined;
}

Hope that helps as it worked for me.