【发布时间】:2019-01-31 00:45:52
【问题描述】:
目前我正在创建一个处理常见问题的 Alexa 技能,以及导致直接回复的问题可以正常工作,但是我对 Alexa 何时期望另一个回复有疑问。
例如,如果用户询问,
“我应该吃什么”
Alexa 会回复“你想吃意大利面吗?”
-
用户会说“是”或“否”
- 如果用户说“是”,alexa 会回复“这是意大利面”,或者如果用户说“不”,则建议其他内容
如果用户说的是或否以外的任何其他内容,它会再次提示用户说是或否。
目前我有以下代码:
if (intentName == "WhatShouldIEat")
{
EatQuestion = true;
reprompt = "Answer with yes or no";
return MakeSkillResponse(FAQHelper.getQuestionInformation(intentName)); //returns the voice response on alexa
}
//Check if users says yes or no for for eating that food
if (EatQuestion)
{
switch (intentName)
{
case "AMAZON.YesIntent":
intentName = "YesFood"; //sets response to when user says yes
EatQuestion = false;
reprompt = "Ask me another question";
break;
case "AMAZON.NoIntent":
intentName = "NoFood"; //sets response for when user says no
EatQuestion = false;
reprompt = "Ask me another question";
break;
default:
intentName = "YesNoPrompt"; //Alexa will ask the user to say either yes or no
break;
}
}
所以代码可以工作,如果用户说的是或否以外的任何内容,它将循环重新提示,并给出我想要的正确响应。
但是我想知道是否有更好的方法来实现这一点,因为该功能当前位于 FunctionHandler 中,并且与 switch 案例相当混乱,并且将当前代码扩展为其他需要是,不确认的问题也会很乱。
基本上我想知道是否有更简洁的方法可以在上面的代码中执行相同的功能。
【问题讨论】:
标签: c# alexa alexa-skills-kit