0

尝试在 AWS 托管的自定义 lambda 函数中使用 Alexa 演示语言功能。Intent 处理程序正在触发,但是当我添加 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();
    },
};


4

1 回答 1

0

而不是使用以下条件:

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

希望这对我有用。

于 2020-02-25T03:56:13.357 回答