public static async Task <LuisTemplate> FetchTemplateAsync(string s) { string LUISapp = "https://api.projectoxford.ai/luis/v1/application?id=e4a7d459-7a76-4fac-979c-0247f056f8ce&subscription-key=9ba5a167ea0d4b2ca890c2a04786514f&q="; HttpClient client = new HttpClient(); string response = await client.GetStringAsync(LUISapp + s); client.Dispose(); LuisTemplate result = JsonConvert.DeserializeObject <LuisTemplate>(response); return(result); }
/// <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)); Luis.LuisTemplate res = await Luis.GetIntent.FetchTemplateAsync(activity.Text); string Intent = res.intents[0].intent; Activity reply; if (activity.Text.Contains("@email:")) { string[] result = await GetFromEmail.get(activity.Text.Substring(7)); reply = activity.CreateReply(result[0]); connector.Conversations.ReplyToActivity(reply); reply = activity.CreateReply(result[1]); connector.Conversations.ReplyToActivity(reply); reply = activity.CreateReply(result[2]); } else if (Intent.Equals("FindFriend")) { if (res.entities.Length > 0) { List <string> emails = await GetFromName.get(res.entities[0].entity); reply = activity.CreateReply("Here are the users with the name : " + res.entities[0].entity); reply.Recipient = activity.From; reply.Type = "message"; reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; reply.Attachments = new List <Attachment>(); foreach (var x in emails) { List <CardImage> images = new List <CardImage>(); images.Add(new CardImage("http://nulm.gov.in/images/user.png")); List <CardAction> actions = new List <CardAction>(); CardAction action = new CardAction() { Value = "@email:" + x, Type = ActionTypes.PostBack, Title = "FIND" }; actions.Add(action); HeroCard card = new HeroCard() { Images = images, Buttons = actions, Title = "Email", Subtitle = x }; Attachment a = card.ToAttachment(); reply.Attachments.Add(a); } reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; } else { reply = activity.CreateReply("Sorry, I did not understand that"); } } else { reply = activity.CreateReply("Sorry, I did not understand that"); } await connector.Conversations.ReplyToActivityAsync(reply); } else { HandleSystemMessage(activity); } var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }