private async Task <LUIS.Rootobject> GetEntityFromLUIS(string query) { query = Uri.EscapeDataString(query); LUIS.Rootobject Data = new LUIS.Rootobject(); using (HttpClient client = new HttpClient()) { string RequestURI = "https://api.projectoxford.ai/luis/v1/application?id=a72b5e9d-a2be-4e89-a788-76427e41af1a&subscription-key=a5764e3cc7a442709aa8c0e4a708502c&q=" + query; HttpResponseMessage msg = await client.GetAsync(RequestURI); if (msg.IsSuccessStatusCode) { var JsonDataResponse = await msg.Content.ReadAsStringAsync(); Data = JsonConvert.DeserializeObject <LUIS.Rootobject>(JsonDataResponse); } } return(Data); }
/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <HttpResponseMessage> Post([FromBody] Activity activity) { ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); if (activity.Type == ActivityTypes.Message) { StateClient stateClient = activity.GetStateClient(); BotData userData = await stateClient.BotState.GetUserDataAsync(activity.ChannelId, activity.From.Id); var token = IsValidUser(activity.Text); string entityString; string name = string.Empty; if (token) { name = GetValidEncodedEmail(activity.Text); entityString = "[This is your first time. Please grant permission to communicate with VSTS by clicking the link.](https://botinterfaceapi.azurewebsites.net/oauth/requesttoken?userName="******"). After login type your query like 'Show my task' or 'Display my task' to get result."; } else if (!token && activity.Text.ToLower().Contains("hi")) { entityString = "Please share your work email Id to validate your data."; } else { LUIS.Rootobject StLUIS = await GetEntityFromLUIS(activity.Text); if (StLUIS.intents.Count() > 0) { switch (StLUIS.intents[0].intent.ToLower()) { case "show": entityString = await GetWorkitems(StLUIS.entities[0].type, activity); //Call VSTS API break; default: entityString = " Sorry, I am not getting you ..."; break; } } else { entityString = " Sorry, I am not getting you ..."; } } Activity reply = activity.CreateReply(entityString); if (!string.IsNullOrEmpty(name)) { name = HttpUtility.UrlDecode(name); userData.SetProperty <string>("userName", name); await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData); } activity.TextFormat = "markdown"; await connector.Conversations.ReplyToActivityAsync(reply); } else { HandleSystemMessage(activity); } var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }