来自dialog.elicitslot()的响应错误

时间:2018-06-07 19:50:28

标签: c# alexa alexa-skills-kit alexa-skill alexa-slot

我正在尝试为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
    }
}

}

此外 - 如果有人能告诉我如何使用代码使插槽成为必需值,我将非常感激。

0 个答案:

没有答案