【问题标题】:Alexa Custom skill in AWS lambda not recognizing Alexa.getSupportedInterfaces[Error handled: Alexa.getSupportedInterfaces is not a function]AWS lambda 中的 Alexa 自定义技能无法识别 Alexa.getSupportedInterfaces [错误处理:Alexa.getSupportedInterfaces 不是函数]
【发布时间】:2020-04-05 21:27:25
【问题描述】:

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


【问题讨论】:

    标签: aws-lambda alexa alexa-presentation-language


    【解决方案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;
    }
    

    希望对我有用。

    【讨论】:

      猜你喜欢
      • 2020-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-18
      相关资源
      最近更新 更多