question

jondecker76 avatar image
jondecker76 asked

Prompting for all slots within intent?

I've done plenty of tests so far with the Alexa Skill Kit, and have simple skills working. However, now I want to make my first "useful" skill, a simple score keeper for a variety of games. Now I'm having an issue with slot validation. I basically need all 3 slots populated (Game,PlayerA,PlayerB). Is there a way to guide the dialogue to ensure that all 3 slots are populated? Looking at the API reference, I don't see where it's possible without some crazy hacks. For example: Example1: (my StartGame intent is provided with no slots populated) >Alexa, tell scoreboard to start a new game < Sure. What Game will you be playing? > Corn hole < I will set up a scoreboard to track your corn hole game. Who are the players? > Tommy and Brian < You are ready to play. Just say, Add 3 points to Tommy to update the score. Example 2: (my StartGame intent is provided only a game name) >Alexa, tell scoreboard to start a new game of Can Jam < I will set up a scoreboard to track your can jam game. Who are the players? > Tommy and Brian < You are ready to play. Just say, Add 3 points to Tommy to update the score. Example 3: (my StartGame intent is only provided with player names) >Alexa, tell scoreboard to start a new game between Tommy and Brian < Sure. What Game will you be playing? > Hillbilly Golf < You are ready to play. Just say, Add 3 points to Tommy to update the score. Example 4: (all slots are populated) > Alexa, tell scoreboard to start a new ring toss game between Anna and Jeff < You are ready to play. Just say, Add 3 points to Tommy to update the score. I'm not seeing a way to do this with one single intent, and prompt the user for any missing information. Here is where I ended up confused while I started to code: [code] function StartGame(intent,session,callback) { console.log("*** In StartGame()") var cardTitle="Starting new game"; var repromptText=""; var sessionAttributes = {}; var shouldEndSession=false; var speechOutput=""; if(!intent.slots.game) { // Doh! We need to know what game we're scoring! console.log(" We need to get the name of the game!") speechOutput="Great! What game are you playing?"; } else if(!intent.slots.home) { // Doh! We need to know who the home team is! console.log(" We need to get the name of the home team!") } else if(!intent.slots.visitor) { // Doh! We need to know who the visitor team is! console.log(" We need to get the name of the visitor team!") } else { // We have all the information we need to start keeping score! speechOutput="Good luck playing!"; } callback(sessionAttributes, buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession)); } [/code] I can have speech sent back, but no control over which slot gets the information. Any tips? thanks!
alexa skills kitdebugging
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

jjaquinta avatar image
jjaquinta answered
Alexa's accuracy decreases rapidly with the number of slots you have in your intent. If you need to collect multiple items of information, you have to be prepared to write code to selectively ask for missing information when not all the slots are filled. In your code, you are just looking at the slots in the intent. What you need to do is to take what slots are populated, and push any valid values in them (since Alexa will also mix up the values to the slots) into the session. Whatever is missing, compose a response asking for that. Then, the logic repeats. Only when you get an intent, look both in the slots in the intent for new values, and in the session for old value. Ultimately, you are going to want to push everything into an off-line store anyway. The session values only persist for the current Alexa session. Any gap of more than 8 seconds will terminate the session. That's going to make session variables useless for tracking scores. So you are going to need a back end data store anyway. If you are using it for some things, you might as well use it for all things. [The 2nd edition of my book has a new section "Working With Alexa's Limitations" which has a subsection dealing with this. The above is the bits that are most relevant to your problem. But you might want to check it out anyway. http://www.amazon.com/How-Program-Amazon-Echo-Development-ebook/dp/B011J6AP26 ]
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.