public async Task AskDetails(IDialogContext context, LuisResult result) { await context.PostAsync($"fetching details"); EntityRecommendation rec; if (result.TryFindEntity("place", out rec)) { placename = rec.Entity; await context.PostAsync($"place : " + placename); PlaceDetails pd = new PlaceDetails(); var attachment = pd.displayPlaceDetails(placename); Activity msg = (Activity)context.MakeMessage(); msg.Recipient = msg.Recipient; msg.Type = "message"; msg.AttachmentLayout = AttachmentLayoutTypes.Carousel; msg.Attachments.Add(attachment); await context.PostAsync(msg); } else { await context.PostAsync($"Please enter your place "); } context.Wait(MessageReceived); }
public List <Attachment> makeRequest(string placeName, string category) { Random rnd = new Random(); int rk = rnd.Next(keys.Count); string key = keys[rk]; List <Attachment> types = new List <Attachment>(); string ts_url = "https://maps.googleapis.com/maps/api/place/textsearch/json?key=" + key + "&query=" + category + "+in+" + placeName; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ts_url);//making a http web request request.Method = Method.ToString(); using (HttpWebResponse res = (HttpWebResponse)request.GetResponse()) { Stream res_stream = res.GetResponseStream(); //creating a response stream to read the response StreamReader st_read = new StreamReader(res_stream); //crreating a stream reader to read from the response stream string places = st_read.ReadToEnd(); //reading the response stream until the end and assigning to string //the response we get is in the form of a json but converted to string when we get, this is serialization //once we get the string form of data we convert it into jason to access internal class objects and data,this is called deserialization RootObject_ts places_ts = JsonConvert.DeserializeObject <RootObject_ts>(places); //Root object of city deserialization of json data int i = 0; references.Clear(); foreach (var r1 in places_ts.results) { string typeName = r1.name; string rating = " RATING : " + r1.rating.ToString(); string typeAddress = " ADDRESS : " + r1.formatted_address; PlaceDetails pd = new PlaceDetails(); pd.makeRequest(r1.place_id); string url = pd.getUrl(); try { references.Add(r1.photos[0].photo_reference); } catch (Exception e) { references.Add(""); } List <CardAction> buttons = new List <CardAction> { new CardAction(ActionTypes.PostBack, " View place and its reviews ", value: "Place Id : " + i + r1.place_id), new CardAction(ActionTypes.OpenUrl, " Get directions to visit place ", value: url) }; Attachment heroCard = GetHeroCard(typeName, rating, typeAddress, buttons); types.Add(heroCard); i++; if (i == 5) { break; } } return(types); } }
/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <HttpResponseMessage> Post([FromBody] Activity activity) { if (activity.Type == ActivityTypes.Message) { ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); Activity reply = activity.CreateReply($""); Activity reply1 = activity.CreateReply($""); if (activity.Text.Contains("Place Id : ")) { var place_id = activity.Text.ToString().Substring(11, activity.Text.ToString().Length - 11); int index = (int)Char.GetNumericValue(place_id[0]); TextSearch ts = new TextSearch(); string refe = ts.getReference(index); PlaceDetails pd = new PlaceDetails(); Attachment attachment = pd.makeCard(refe, place_id.Substring(1, place_id.Length - 1)); reply.Attachments = new List <Attachment>(); reply.Attachments.Add(attachment); await connector.Conversations.ReplyToActivityAsync(reply); string review = pd.GetReviews(place_id.Substring(1, place_id.Length - 1)); reply1 = activity.CreateReply($"" + review); await connector.Conversations.ReplyToActivityAsync(reply1); var res = Request.CreateResponse(HttpStatusCode.OK); return(res); } await Conversation.SendAsync(activity, () => new LuisDialogs(activity.Text.ToString())); } else { HandleSystemMessage(activity); } var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }