【问题标题】:Alexa service response contains "Speechlet response" which contains an extra card, unsure why?Alexa 服务响应包含包含额外卡片的“Speechlet 响应”,不确定为什么?
【发布时间】:2018-06-01 19:23:14
【问题描述】:

我已经创建了我的第一个测试 Alexa 技能,它应该做的就是让 Alexa 侮辱你。 (我知道这已经创建,但这只是一个测试) 我一直在学习教程,但是现在当我在回声上打开技能时,我得到的响应是“抱歉,出了点问题”。 被调用的代码是

this.emit(":tellWithCard", speechOutput, SKILL_NAME, randomInsult);

这是我在服务模拟器上得到的服务响应:

    {
      "version": "1.0",
      "response": {
        "outputSpeech": {
          "ssml": "<speak> Nah shut up, you bad little weapon </speak>",
          "type": "SSML"
        },
        "card": {
          "content": "Nah shut up, you bad little weapon",
          "title": "Insulter"
        },
        "speechletResponse": {
          "outputSpeech": {
            "ssml": "<speak> Nah shut up, you bad little weapon </speak>"
          },
          "card": {
            "content": "Nah shut up, you bad little weapon",
            "title": "Insulter"
          },
          "shouldEndSession": true
        }
      },
      "sessionAttributes": {}
    }

在我遵循的教程中,speechlet 响应不在服务响应中,有人知道为什么它现在包含在我的响应中吗?我不确定我的代码中是否存在错误,或者 Lambda 函数的工作方式是否发生了变化。这是 cloudwatch 上的回复:

    21:12:48
    START RequestId: 4085e037-b9c9-11e7-b5e8-23df701a71f2 Version: $LATEST
    
    21:12:48
    2017-10-25T21:12:48.029Z    4085e037-b9c9-11e7-b5e8-23df701a71f2    
    Warning: Application ID is not set
    
    21:12:48
    END RequestId: 4085e037-b9c9-11e7-b5e8-23df701a71f2
    
    21:12:48
    REPORT RequestId: 4085e037-b9c9-11e7-b5e8-23df701a71f2  Duration: 0.68 
    ms  Billed Duration: 100 ms Memory Size: 128 MB Max Memory Us

这是我的 index.js 代码:

"use strict";

//Variables
var Alexa = require("alexa-sdk");
var SKILL_NAME = "Insulter";
var APP_ID = "";

//List of insults
var INSULT_LIST = [
    "Nah shut up, you bad little weapon",
    "Sample insult 2",
    "Sample insult 3"
];


//Setup
exports.handler = function(event, context, callback){
    var alexa = Alexa.handler(event,context);
    alexa.APP_ID = APP_ID;
    alexa.registerHandlers(handlers);
    alexa.execute();
}

var handlers = {
    'LaunchRequest': function(){
        this.emit('GetInsult');
    },
    'GetInsultIntent': function() {
        this.emit('GetInsult');
    },
    'GetInsult' : function() {
        var insultIndex = Math.floor(Math.random()*INSULT_LIST.length);
        var randomInsult = INSULT_LIST[insultIndex];

        //Output
        var speechOutput = randomInsult;

        this.emit(":tellWithCard", speechOutput, SKILL_NAME, randomInsult);
    },
    'AMAZON.HelpIntent' : function() {
        var speechOutput = "You can say give me an insult, or, you can say exit.";
        var reprompt = "What can I help you with?";
        this.emit(":ask", speechOutput, reprompt);
    },
    'AMAZON.StopIntent' : function() {
        this.emit(":tell","Goodbye!");
    },
    'AMAZON.CancelIntent' : function() {
        this.emit(":tell","Goodbye!");
    }
}

【问题讨论】:

  • 能否分享来自 cloudwatch 的 Lambda 日志?
  • 这些是日志,有几个,但它只是一遍又一遍,因为我已经尝试过很多次了
  • 我在日志中找不到任何错误。您可以在 lambda 的开头和结尾添加一个 console.log 吗?
  • 我已将我的代码添加到问题中,也许这样更容易查看是否有任何错误。这是我的 index.js

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


【解决方案1】:

第四个参数(according to amazon is this.emit(':tellWithCard', speechOutput, cardTitle, cardContent, imageObj);)imageObj,您正试图在其中放置一个语音字符串,我相信这就是您的 Alexa 崩溃的原因。在此处放置图像或将其完全删除。

【讨论】:

  • 我在 ":tellWithCard" 之后只有 3 个参数,我实际上只用 ":tell" 尝试过这个,但我的响应本身总是有这个额外的 "speechletResponse",我没有看到这个出现在我遵循的任何示例中,并相信这可能会导致问题,但不确定如何阻止它。
【解决方案2】:

我已经解决了我遇到的问题。事实证明,问题在于我使用的是英语(美国),尽管我有一个英国 Alexa,并且将亚马逊开发者控制台上的内容更改为英语(英国),一切都按预期工作。还是谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-07
    • 1970-01-01
    • 1970-01-01
    • 2016-09-12
    • 2014-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多