是的,这两个问题。您可以将响应与6个不同的自定义插槽串联起来。 “用户:我的号码是{num1},{num2},{num3},{num4},{num5},{num6}”,并使用技能测试开发人员完成所有必要的工作。然而,如果用户没有恰当地回答他们的答案,那么这将是一个相当不好的用户体验,Alexa必须要求跟进问题以获得每个号码。最后一个问题是,虽然自定义广告位可以定义为包含数字1-50,但alexa通常会识别与自定义广告位中提供的值类似的值,例如50-99之间的数字。然后由您来检查您收到的值是否在1到50之间。如果不是,您会希望要求用户在适当的范围内提供不同的数字。
结论:您将希望进行单独的交互,用户一次只能提供一个号码。
Alexa:"you will be prompted for 6 numbers between 1 and 50 please state them one at a time. Choose your first number."
User:"50"
Alexa:"Your First number is 50, Next number."...
您可以使用单一意图来实现此目的。让我们将其命名为GetNumberIntent
。 GetNumberIntent将具有样品uterances沿
{number}
pick {number}
choose {number}
行其中{数}为一个自定义的时隙类型或者简单地AMAZON.NUMBER。然后由您来检查数字是在1到50之间。
我使用SDK在Node.js中编程。您的实施可能因您的语言选择而异。
我会做的是定义6个不同的状态处理程序。每个处理程序应该有GetNumberIntent。如果槽值适当,则返回GetNumberIntent将该值存储到会话数据和/或dynamodb并前进到下一个状态。如果时隙值无效逗留例如在状态“NumberInputFiveStateHandlers”直到接收到好的值,则改变状态到下一个“NumberInputSixStateHandlers”
var NumberInputFiveStateHandlers = Alexa.CreateStateHandler(states.NUMFIVEMODE, {
'NewSession': function() {
this.emit('NewSession'); // Uses the handler in newSessionHandlers
},
//Primary Intents
'GetNumberIntent': function() {
let message = ` `;
let reprompt = ` `;
let slotValue = this.event.request.intent.slots.number.value;
if(parseInt(slotValue) >= 1 && parseInt(slotValue) <= 50){
this.handler.state = states.NUMSIXMODE;
this.attributes['NUMBERFIVE'] = this.event.request.intent.slots.number.value;
message = ` Your fifth number is `+slotValue+`. please select your sixth value. `;
reprompt = ` please select your sixth value. `;
}else{
message = ` The number `+slotValue)+` is not in the desired range between 1 and 50. please select a valid fifth number. `;
reprompt = ` please select your fifth value. `;
}
this.emit(':ask',message,reprompt);
},
//Help Intents
"InformationIntent": function() {
console.log("INFORMATION");
var message = ` You've been asked to choose a lottery number between 1 and 50. Please say your selection.`;
this.emit(':ask', message, message);
},
"AMAZON.StopIntent": function() {
console.log("STOPINTENT");
this.emit(':tell', "Goodbye!");
},
"AMAZON.CancelIntent": function() {
console.log("CANCELINTENT");
this.emit(':tell', "Goodbye!");
},
'AMAZON.HelpIntent': function() {
var message = `You're playing lottery. you'll be picking six numbers to play the game. For help with your current situation say Information. otherwise you may exit the game by saying quit.`;
this.emit(':ask', message, message);
},
//Unhandled
'Unhandled': function() {
console.log("UNHANDLED");
var reprompt = ' That was not an appropriate response. Please say a number between 1 and 50.';
this.emit(':ask', reprompt, reprompt);
}
});
这是第五请求的一个例子。你将有6个完全相同的状态,就像这个串起来的状态。最终你会得到6个会话值。
this.attributes['NUMBERONE']
this.attributes['NUMBERTWO']
this.attributes['NUMBERTHREE']
this.attributes['NUMBERFOUR']
this.attributes['NUMBERFIVE']
this.attributes['NUMBERSIX']
然后,您可以将这些值用于您的游戏。
如果你还没有使用Alexa的-SDK之前,你必须记住注册您的状态处理程序,并添加您的模式到states
变量。
alexa.registerHandlers(newSessionHandlers, NumberInputOneStateHandlers, ... NumberInputSixStateHandlers);
var states = {
NUMONEMODE: '_NUMONEMODE',
...
...
NUMSIXMODE: '_NUMSIXMODE',
}
此答案无意涵盖使用Alexas-SDK进行编码的基础知识。还有其他资源可以为这个主题提供更具体的问题。
可替换地,因为您的目的是相同的[GetNumberIntent],则可以与该推新的有效的数字到一个阵列中的单个StateHandler获得通过,直到阵列的期望的长度。这只需要在Intent Handler中有更多的逻辑,并且一旦数组长度为6,就有条件跳出状态。 首先尝试上面的代码,因为它更容易看到不同的状态。
难道你不能只做{number} {number} {number} {number} {number} {number}吗?我使用类似的随机单词列表。这样,一旦用户说了6个单词,它只发送一个意图。然后你只要确保他们都在你正在寻找的范围内。 – ialexander