Навык Alexa Custom в AWS lambda не распознает Alexa.getSupportedInterfaces[Ошибка обработана: Alexa.getSupportedInterfaces не является функцией]

Попытка использовать функции языка презентации Alexa в настраиваемой лямбда-функции, размещенной на AWS. Обработчик намерений запускается, но когда я добавляю Alexa.getSupportedInterfaces, он не работает. Сообщение: "Ошибка обработана: Alexa.getSupportedInterfaces не является функцией"


// 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 ответ

Вместо использования условия ниже:

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

вы можете использовать условие ниже, чтобы проверить, поддерживает ли устройство APL:

if (supportsAPL(handlerInput))

Убедитесь, что вы включили в индексный файл следующее определение функций:

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;
}

Надеюсь, что это сработало для меня.

Другие вопросы по тегам