是的,這兩個問題。您可以將響應與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