【发布时间】: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