【问题标题】:Alexa function works in AWS lamda, but not from the Service SimulatorAlexa 函数适用于 AWS lambda,但不适用于服务模拟器
【发布时间】:2018-09-17 18:33:28
【问题描述】:

我对 AWS 和 Alexa 技能比较陌生。我正在构建一个简单的自定义技能,根据天气为您提供穿衣建议。

我有 2 个自定义意图:dressingTodayIntent 和 DressingTomorrowIntent。在开发人员门户的服务模拟器中,我的两个意图不起作用,虽然我得到了一个 lambda 响应,但输出语音未定义,如下所示:

{ 
 "version": "1.0", 
 "response": { 
   "outputSpeech": { 
     "type": "SSML", 
     "ssml": "<speak> undefined </speak>" 
   }, 
   "card": null, 
   "reprompt": null, 
   "speechletResponse": { 
     "outputSpeech": { 
       "id": null, 
       "ssml": "<speak> undefined </speak>" 
     }, 
     "card": null, 
     "directives": null, 
     "reprompt": null, 
     "shouldEndSession": true 
   } 
 }, 
 "sessionAttributes": {} 
}

这可能是我的意图代码中的范围问题吗?

'DressingTodayIntent': function() {
    var dressingAdvice;
    var speechOutput = getJSON('https://api.darksky.net/forecast/9e0495a835ed823a705a9a567eee982a/48.861317,2.348764?units=si&exclude=currently,minutely,hourly,alerts,flags',
        function(err, forecast) {
            if (err) {
              console.log('Error occurred while trying to retrieve weather data', err);
            } else {
              dressingAdvice = getDressingAdvice(forecast, true);
              console.log("one " + dressingAdvice);
            }
            console.log("two " + dressingAdvice);
            return dressingAdvice;
        });
    console.log("three " + speechOutput);
    this.response.cardRenderer("Your dressing advice for today:", speechOutput);
    this.response.speak(speechOutput);
    this.emit(':responseReady');
},

在 AWS Lambda 中,我看到前 2 个日志的输出正确,而第三个日志的输出错误:

  • 第一个日志:“一个”+dressingAdvice,如预期的那样
  • 第二个日志:“两个”+dressingAdvice,如预期的那样
  • 第三条日志:“三个”+未定义

感谢您的帮助!

【问题讨论】:

  • 您的调用关键字有问题?它与您的自定义插槽匹配吗?
  • 它确实匹配插槽是的,这不是问题。

标签: amazon-web-services aws-lambda alexa alexa-skills-kit alexa-skill


【解决方案1】:

当您说“从 AWS Lambda 测试”时,我假设您的意思是使用 AWS 控制台向 Lambda 发送 JSON 测试消息,然后查看响应 JSON 以确定它是否正确?

如果是这样,请确保它与发送到/从开发门户中的 Alexa 测试页面发送的 JSON 匹配。听起来他们可能会有所不同。

此外,请确保您已链接到 Alexa 技能中的正确 ARN。

【讨论】:

  • 是的,这就是我的意思。我仔细检查过,这不是问题,更可能是我的代码中的 SpeechOutput 范围问题...
【解决方案2】:

undefined 可能是代码中的变量范围问题。

我在您的回复中注意到您没有任何sessionAttributes。您的代码是设置还是从会话值中提取响应值?如果是这样,则需要将值与sessionAttributes 一起发回。

【讨论】:

  • 你是对的。我更新了帖子以反映范围问题。但我仍然无法定义语音输出
【解决方案3】:

我发现出了什么问题,我需要将响应代码移动到回调函数中,如下所示:

'DressingTodayIntent': function() {
    var speechOutput;
    var self = this;
    var dressingAdvice = getJSON('https://api.darksky.net/forecast/9e0495a835ed823a705a9a567eee982a/48.861317,2.348764?units=si!ude=currently,minutely,hourly,alerts,flags',
        function(err, forecast) {
            if (err) {
              console.log('Error occurred while trying to retrieve weather data', err);
            } else {
              speechOutput = getDressingAdvice(forecast, true);
            }
            self.response.cardRenderer("Your dressing advice for today:", speechOutput);
            self.response.speak(speechOutput);
            self.emit(':responseReady');
        });    
},

【讨论】:

    猜你喜欢
    • 2019-09-05
    • 1970-01-01
    • 2017-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多