static ContactRootObject GetContactBasedPolicy(string state) { client = new HttpClient(); client.BaseAddress = new Uri(host); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); ContactRootObject allContactPolicies = null; string path = string.Format(contactBasedPolicy, client_id, state); HttpResponseMessage response = client.GetAsync(path).Result; if (response.IsSuccessStatusCode) { string result = response.Content.ReadAsStringAsync().Result; allContactPolicies = Newtonsoft.Json.JsonConvert.DeserializeObject <ContactRootObject>(result); } return(allContactPolicies); }
public AlexaResponse ContactBasedPolicyIntentHandler(Request request) { string speech = ""; string state_type = ""; string state = ""; if (request.SlotsList.Any()) { state = request.SlotsList.FirstOrDefault(s => s.Key == "state_type").Value; state_type = request.SlotsList.FirstOrDefault(s => s.Key == "state_type").Value; state_type = Helper.StateConversion.ConvertState(state_type); } try { string _contacts = string.Empty; int _total = 0; ContactRootObject contacts = GetContactBasedPolicy(state_type); if (contacts != null) { int counter = 1; foreach (var con in contacts.result) { _contacts = _contacts + " Contact " + counter + con.name + " Phone Number is " + con.telephone + "<break time=\"1s\"/> "; counter = counter + 1; } _total = contacts.result.Count(); } if (_total > 0) { speech = "<prosody rate=\"slow\">There are a total of " + _total + " Contacts in " + state + "Here they are " + _contacts + "</prosody>"; } else { speech = "Unable to find any contacts, please try another state."; } } catch { speech = ErrorMessage(); } var response = new AlexaResponse(speech, false, AddSSML(speech)); response.Response.Reprompt.OutputSpeech.Type = "SSML"; response.Response.Reprompt.OutputSpeech.Text = speech; response.Response.Reprompt.OutputSpeech.Ssml = AddSSML(speech); return(response); }