public static PolicyRootObject GetAllPoliciesByLocation(string state, string category) { client = new HttpClient(); client.BaseAddress = new Uri(host); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); PolicyRootObject allPolicies = null; string path = string.Format(locationBasedPolicies, client_id, 1000, state, category); HttpResponseMessage response = client.GetAsync(path).Result; if (response.IsSuccessStatusCode) { string result = response.Content.ReadAsStringAsync().Result; allPolicies = Newtonsoft.Json.JsonConvert.DeserializeObject <PolicyRootObject>(result); } return(allPolicies); }
public AlexaResponse AllPoliciesByLocationIntentHandler(Request request) { client = new HttpClient(); string speech = ""; string state_type = ""; string categories = ""; string state = ""; string cat = ""; if (request.SlotsList.Any()) { state = request.SlotsList.FirstOrDefault(s => s.Key == "state_type").Value; cat = request.SlotsList.FirstOrDefault(s => s.Key == "categories").Value; state_type = request.SlotsList.FirstOrDefault(s => s.Key == "state_type").Value; categories = request.SlotsList.FirstOrDefault(s => s.Key == "categories").Value; state_type = Helper.StateConversion.ConvertState(state_type); } try { string _contacts = string.Empty; int _total = 0; PolicyRootObject contacts = GetAllPoliciesByLocation(state_type, Helper.StateConversion.ConvertCategory(categories)); if (contacts != null) { foreach (var con in contacts.result) { _contacts = _contacts + " Policy Number <say-as interpret-as=\"digits\">" + con.id + "</say-as>" + " The Policy is " + con.title + " "; } _total = contacts.result.Count(); if (_total > 0) { speech = "<prosody rate=\"slow\">" + "There are a total of " + _total + " Policies. You can find detailed information on each policy by saying Give me details on policy number. Here are titles of each policy. " + _contacts + "</prosody>"; } else { speech = "Unable to find any policies for " + cat + " in " + state + " Please try another Category"; } } else { speech = "Unable to find any policies for " + cat + " in " + state + " Please try another Category"; } } catch { speech = ErrorMessage(); } var response = new AlexaResponse(speech, false, AddSSML(speech)); speech = "You can say Find all Categories to get a listing of all Categories"; response.Response.Reprompt.OutputSpeech.Text = speech; response.Response.Reprompt.OutputSpeech.Ssml = AddSSML(speech); return(response); }