0

我正在尝试为 Alexa 制作一个简单的问答游戏,其中向用户展示了两个事件,并尝试猜测第一个第二个事件是在第二个事件之前还是之后发生。

游戏需要填写一个名为“答案”的位置。我的问题是我的 DialogElicitSlot() 方法导致错误并且 Alexa 无法读出响应。

任何帮助表示赞赏,如果有人有类似的工作示例(使用 C#),那也很棒:)

[assembly: 
LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]

namespace Timeline
{
 public class Function
 {

    /// <summary>       
    /// </summary>
    /// <param name="input"></param>
    /// <param name="context"></param>
    /// <returns></returns>
    private SkillResponse MakeResponse(string outputSpeech, bool shouldEndSession, string repromptSpeech)
    {
        var response = new ResponseBody
        {
            ShouldEndSession = shouldEndSession,
            OutputSpeech = new PlainTextOutputSpeech { Text = outputSpeech }
        };

        var skillResponse = new SkillResponse
        {
            Response = response,
            Version = "1.0"
        };

        return skillResponse;
    }

    public IOutputSpeech GetOutputSpeech(string response)
    {
        return new PlainTextOutputSpeech()
        {
            Text = response
        };
    }



    public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
    {
        var requestType = input.GetRequestType();
        if (requestType == typeof(IntentRequest))
        {

            var intentRequest = input.Request as IntentRequest;

            if (intentRequest != null)
            {

                switch (intentRequest.Intent.Name)
                {
                    case "nextEvent":
                        {
                            string lastEventName = QuestionController.getPreviousEventName();
                            DateTime lastEventDate = QuestionController.getPreviousEventDate();

                            string nextEventName = QuestionController.getNextEventName();
                            DateTime nextEventDate = QuestionController.getNextEventDate();

                            if (intentRequest.DialogState == DialogState.Started)
                            {
                                return ResponseBuilder.DialogElicitSlot(GetOutputSpeech($"did the {lastEventName} happen before, or after {nextEventName} ?"), intentRequest.Intent.Slots["answer"].Name, intentRequest.Intent);

                            }
                            else if (intentRequest.DialogState != DialogState.Completed)
                            {
                                return ResponseBuilder.DialogElicitSlot(GetOutputSpeech($"did the {lastEventName} happen before, or after {nextEventName} ?"), intentRequest.Intent.Slots["answer"].Name, intentRequest.Intent);
                            }
                            else
                            {
                                var questionEvaluation = intentRequest.Intent.Slots["answer"].Value;

                                if (QuestionController.evaluateAnswer() == true)
                                {
                                    return MakeResponse($"That is correct! The {nextEventName} was {questionEvaluation} the {lastEventName}. The {nextEventName} was in {nextEventDate} while the {lastEventName} was in {lastEventDate}", true, "");
                                }
                                else
                                {
                                    return MakeResponse($"That is wrong! The {nextEventName} was not {questionEvaluation} the {lastEventName}. The {nextEventName} was in {nextEventDate} while the {lastEventName} was in {lastEventDate}", true, "");
                                }

                            }
                        }
                    default:
                        return MakeResponse("hmm. i dont think i understand what you are asking of me", false, "");
                }
            }
            return MakeResponse("",false,"");

        }
        else
        {
            return MakeResponse("Welcome", false, "");

        }
    }
}
}

`

当我测试我的技能时,我得到的回应是

{
"body": {
    "version": "1.0",
    "response": {
        "outputSpeech": {
            "type": "PlainText",
            "text": "did the previous event happen before, or after next event ?"
        },
        "directives": [
            {
                "type": "Dialog.ElicitSlot",
                "updatedIntent": {
                    "name": "nextEvent",
                    "confirmationStatus": "NONE",
                    "slots": {
                        "answer": {
                            "name": "answer",
                            "confirmationStatus": "NONE"
                        }
                    }
                },
                "slotToElicit": "answer"
            }
        ],
        "shouldEndSession": false
    }
}

}

另外-如果有人能告诉我如何使插槽成为从代码中工作的必需值,我将不胜感激。

4

0 回答 0