private AmazonIntent ValidateIfRequestIsComplete(ref AmazonRequest request, ref AmazonResponse response) { AmazonIntent intent = ((AmazonIntentRequest)request.request).intent; if (!intent.name.Contains("Incomplete") && !intent.name.Contains("FollowUp")) { intent.RemoveNullValueSlots(); List <RequiredSlotWithPrompt> reqSlots = siteSettings.FindRequiredSlotsByIntent(intent.name); if (reqSlots != null) { intent.SortSlots(reqSlots); } return(intent); } else { RequiredSlotWithPrompt slWithPrompt = DetermineNextMissingSlot(ref request, ref response); if (slWithPrompt != null) { response.response.outputSpeech.text = "OK. " + slWithPrompt.VoicePrompt; response.response.shouldEndSession = false; } else { return(intent); } } return(null); }
public RequiredSlotWithPrompt CreateAttributesFromSlots(Dictionary <string, AmazonSlot> slots, List <RequiredSlotWithPrompt> reqSlots) { bool nextSlotFound = false; RequiredSlotWithPrompt nextMissingSlot = null; sessionAttributes = new Dictionary <string, object>(); foreach (KeyValuePair <string, AmazonSlot> slot in slots) { if (slot.Value.name.StartsWith("PAR")) { sessionAttributes.Add(slot.Value.name, slot.Value.value); if (slot.Value.value == null && !nextSlotFound) { sessionAttributes.Add("NextSlot", AmazonSession.CreateNextSlotString(slot.Value.name)); foreach (RequiredSlotWithPrompt sl in reqSlots) { if (sl.RequiredSlot == slot.Value.name) { nextMissingSlot = sl; } } nextSlotFound = true; } } else { sessionAttributes.Add(slot.Value.name, slot.Value.value); } } return(nextMissingSlot); }
private RequiredSlotWithPrompt DetermineNextMissingSlot(ref AmazonRequest request, ref AmazonResponse response) { AmazonIntent intent = ((AmazonIntentRequest)request.request).intent; //First we determine the list of required slots //We also need to remove the suffix List <RequiredSlotWithPrompt> reqSlots = siteSettings.FindRequiredSlotsByIntent(intent.name); //This is an incomplete request - i.e. first one issued //It will tell us all the other parameters we need to determine //First we add them all to session attributes on the response if (intent.name.Contains("Incomplete")) { //Slots seem to come in a completely random order so we need to arrange them before passing them //on intent.SortSlots(reqSlots); return(response.CreateAttributesFromSlots(intent.slots, reqSlots)); } //This is a follow up request so will come with the value for next parameter(s) if (intent.name.Contains("FollowUp")) { foreach (KeyValuePair <string, AmazonSlot> kv in intent.slots) { string searchStr = kv.Key.Insert(3, request.session.attributes["NextSlot"].ToString()); if (request.session.attributes[searchStr] == null) { request.session.attributes[searchStr] = kv.Value.value; } } } //Now we need to sort the session attributes as it appears Amazon randomizes them again :( request.session.SortSessionAttributes(reqSlots); //Check if all parameters are now present RequiredSlotWithPrompt missingSlot = request.session.CheckIfAllSlotsArePresent(reqSlots); if (missingSlot != null) { response.CopySessionAttributesFromRequest(request); return(missingSlot); } //First we need to combine all the currently known slots from session List <AmazonSlot> slotsPresent = request.session.ConvertSessionAttributesToSlots(); //We will replace slots in the main intent object witht the slots we found intent.ReplaceSlots(slotsPresent); //Now we need to sort them in the order in which they are defined in the configuration file intent.SortSlots(reqSlots); intent.name.Remove(intent.name.IndexOf("FollowUp")); return(null); }