【问题标题】:speechletResponse null error on alexa skill launch requestAlexa技能启动请求上的speechletResponse null错误
【发布时间】:2020-08-28 22:38:10
【问题描述】:

启动技能时出现错误。

SpeechletResponse was null

这是我在 aws lambda cloudwatch 中看到的响应

{
  "response": {
    "outputSpeech": {
      "type": "SSML",
      "ssml": "<speak>Welcome to the Alexa Skills Kit, you can say hello</speak>"
    },
    "reprompt": {
      "outputSpeech": {
        "type": "SSML",
        "ssml": "<speak>Go ahead and say hello to me!</speak>"
      }
    },
    "shouldEndSession": false
  },
  "version": "1.0",
  "sessionAttributes": {}
}

以上回复是我刚刚返回的示例,因为它在this 页面(alexa 文档)中提到。

这是我的代码:

using Alexa.NET;
using Alexa.NET.Request;
using Alexa.NET.Response;
using Amazon.Lambda.Core;
using Newtonsoft.Json;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace MyNameSpace
{
    public class Function
    {

        /// <summary>
        /// A simple function that takes a input and returns an output
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            context.Logger.LogLine("Entered the function handler");
            context.Logger.LogLine("This is the request: " + JsonConvert.SerializeObject(input));

            //RequestHandler

            //var output = new AlexaSkillsKit.Speechlet.SpeechletResponse()
            //{
            //    ShouldEndSession = true,
            //    OutputSpeech = new AlexaSkillsKit.UI.PlainTextOutputSpeech()
            //    { 
            //        Text = "This is alexa skills kit output."
            //    },
            //    Card = null,
            //    Directives = null,
            //    Reprompt = null
            //};

            ResponseBuilder builder = new ResponseBuilder();

            //var output = ResponseBuilder.Tell("Hello, sample output");
            var output = JsonConvert.DeserializeObject<SkillResponse>("{" +
  "\"response\": {" +
                "\"outputSpeech\": {" +
                    "\"type\": \"SSML\"," +
      "\"ssml\": \"<speak>Welcome to the Alexa Skills Kit, you can say hello</speak>\"" +
                "}," +
    "\"reprompt\": {" +
                    "\"outputSpeech\": {" +
                        "\"type\": \"SSML\"," +
        "\"ssml\": \"<speak>Go ahead and say hello to me!</speak>\"" +
                    "}" +
                "}," +
    "\"shouldEndSession\": false" +
  "}," +
  "\"version\": \"1.0\"," +
  "\"sessionAttributes\": { }" +
        "}");

            context.Logger.LogLine("This is the response: " + JsonConvert.SerializeObject(output));

            return output;
        }
    }
}

一旦 Lambda 向技能发送响应,这是来自 alexa 服务的请求,这是因为它不理解我之前发送的响应(如上所示):

"request": {
        "type": "SessionEndedRequest",
        "requestId": "amzn1.echo-api.request.9e44df59-62fd-4a12-8568-6a701fadbe61",
        "locale": "en-US",
        "timestamp": "2020-05-12T21:47:56Z",
        "reason": "ERROR",
        "error": {
            "type": "INVALID_RESPONSE",
            "message": "SpeechletResponse was null"
        }
    }

自 24 小时以来,我一直在努力克服这个错误,但没有运气。我尝试了不同的 nuget 包等。有人可以帮忙吗?

【问题讨论】:

    标签: c# aws-lambda alexa-skill


    【解决方案1】:

    在我的情况下,我最初遇到了这个错误,因为我没有从 AWS lambda 正确部署我的 python 代码。

    一般来说,如果从 lambda 返回的响应中有错误,alexa 技能包开发人员会报告此错误。

    要解决这个问题,您可以检查技能包开发人员的输入 json,检查它是否从 json 输入到技能包的意图分类正确,并使用 lambda 中的测试功能来调试错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-14
      • 2020-07-23
      • 2018-09-24
      • 1970-01-01
      • 2018-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多