Esempio n. 1
0
        /// <summary>
        /// Get the Answer(s) based on the intent name. In this situation, the intent will have one or more entities that we will do a search on
        /// </summary>
        /// <param name="intent"></param>
        /// <returns></returns>
        public static async Task <List <AnswerModel> > GetAndFormatAnswer(LuisResponse intent)
        {
            //List<Answer> chatAnswers = new List<Answer>();

            var chatAnswers = new List <AnswerModel>();

            var questionInfo = await DataAccess.GetQuestion(GetHighScoringIntent(intent));

            if (questionInfo.QuestionText != null)
            {
                chatAnswers = DataAccess.GetAnswers(questionInfo.QuestionId).Result;

                //if we get back answers with AnswerTypeId = 2, then we need to do a web search. Format those answers.
                if (chatAnswers.Count > 0 && chatAnswers[0].AnswerTypeId == 2)
                {
                    if (intent.entities.Length > 0)
                    {
                        var searchString = intent.entities[0].entity;

                        for (int i = 1; i < intent.entities.Length; i++)
                        {
                            searchString += $" {intent.entities[i].entity}";
                        }

                        chatAnswers[0].AnswerText = GetGoogleSearchMessage(searchString);
                    }
                }
            }

            return(chatAnswers);
        }
        /// <summary>
        /// Enumerates and returns additional entities returned by LUIS.
        /// </summary>
        /// <param name="luisResponse">The response from LUIS.</param>
        /// <param name="log">A logger instance.</param>
        /// <returns>A dictionary representing the additional entities.</returns>
        public Dictionary<string, string> EnumerateAdditionalEntities(LuisResponse luisResponse, ILogger log)
        {
            if (luisResponse.Entities == null)
            {
                return null;
            }

            IList<LuisEntity> extraEntities = luisResponse
                .Entities
                .Where(x => !_expectedEntities.Contains(x.Type))
                .ToList();

            Dictionary<string, string> extraEntitiesDictionary = new Dictionary<string, string>();

            int keySuffixNumber = 1;

            foreach (LuisEntity entity in extraEntities)
            {
                string key = entity.Type;

                while (extraEntitiesDictionary.ContainsKey(key))
                {
                    key = $"{key}-{++keySuffixNumber}";
                }

                extraEntitiesDictionary.Add(key, entity.Entity);
            }

            return extraEntitiesDictionary;
        }
Esempio n. 3
0
        public ConversationResponse ProcessInContext(LuisResponse response)
        {
            if (!IsConnected)
            {
                return(ConnectPath(response));
            }
            if (SelectedEntity == null)
            {
                return(EntityPath(response));
            }
            var unsetEntity = CheckUnsetEntity(response);

            if (unsetEntity != null)
            {
                return(unsetEntity);
            }

            var setFilter = CheckSetFilter(response);

            if (setFilter != null)
            {
                return(setFilter);
            }

            var unsetFilter = CheckUnsetFilter(response);

            if (unsetFilter != null)
            {
                return(unsetFilter);
            }

            return(new ConversationResponse(""));
        }
        private void HandleIntent(LuisResponse intent, MessageType msgObj)
        {
            var primaryIntent = intent.topScoringIntent;
            var primaryEntity = intent.entities.FirstOrDefault();

            if (primaryIntent != null && primaryEntity != null)
            {
                if (primaryIntent.intent.Equals("OrderIn") && primaryIntent.score > 0.75)
                {
                    //Detected an actionable request with an identified entity
                    if (primaryEntity != null && primaryEntity.score > 0.5)
                    {
                        String destination      = primaryEntity.type.Equals("RoomService::FoodItem") ? "Room Service" : "Housekeeping";
                        String generatedMessage = string.Format("We've sent your request for {0} to {1}, we will confirm it shortly.", primaryEntity.entity, destination);
                        SendBotMessage(msgObj, generatedMessage);
                    }
                    else
                    {
                        //Detected only an actionable request, but no entity
                        String generatedMessage = "We've received your request for service, our staff will followup momentarily.";
                        SendBotMessage(msgObj, generatedMessage);
                    }
                }
            }
        }
        /// <summary>
        /// Extracts person information from the transcript.
        /// </summary>
        /// <param name="luisResponse">The transcript.</param>
        /// <param name="log">Trace logging instance.</param>
        /// <returns>The extracted person information.</returns>
        public PersonInfo ExtractPerson(LuisResponse luisResponse, ILogger log)
        {
            PersonInfo personInfo = null;

            if (luisResponse.Entities == null
                || luisResponse.Entities.Count == 0)
            {
                return personInfo;
            }

            LuisEntity personEntity = luisResponse
                .Entities
                .Where(x => x.Type == _config.PersonEntityName)
                .FirstOrDefault();

            if (personEntity != null)
            {
                personInfo = new PersonInfo()
                {
                    Name = personEntity.Entity,
                    Type = luisResponse.TopScoringIntent != null
                                ? (_config.PersonIntentTypeMap.ContainsKey(luisResponse.TopScoringIntent.Intent) ? _config.PersonIntentTypeMap[luisResponse.TopScoringIntent.Intent] : "Unknown")
                                : "Unknown",
                };
            }

            return personInfo;
        }
Esempio n. 6
0
        private static async Task HandleIntent(LuisResponse intent, MessageType msgObj, IAsyncCollector <BrokeredMessage> outputServiceBus)
        {
            var primaryIntent = intent.topScoringIntent;
            var primaryEntity = intent.entities.FirstOrDefault();

            if (primaryIntent != null && primaryEntity != null)
            {
                if (primaryIntent.intent.Equals("OrderIn") && primaryIntent.score > 0.75)
                {
                    //Detected an actionable request with an identified entity
                    if (primaryEntity != null && primaryEntity.score > 0.5)
                    {
                        var destination      = primaryEntity.type.Equals("RoomService::FoodItem") ? "Room Service" : "Housekeeping";
                        var generatedMessage =
                            $"We've sent your request for {primaryEntity.entity} to {destination}, we will confirm it shortly.";
                        await SendBotMessage(msgObj, generatedMessage, outputServiceBus);
                    }
                    else
                    {
                        //Detected only an actionable request, but no entity
                        var generatedMessage = "We've received your request for service, our staff will followup momentarily.";
                        await SendBotMessage(msgObj, generatedMessage, outputServiceBus);
                    }
                }
            }
        }
Esempio n. 7
0
        public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
        {
            switch (turnContext.Activity.Type)
            {
            case ActivityTypes.Message:
                var luisResult   = turnContext.TurnState.Get <RecognizerResult>(LuisRecognizerMiddleware.LuisRecognizerResultKey);
                var luisResponse = new LuisResponse();
                luisResponse.Convert(luisResult);

                if (luisResult != null)
                {
                    await turnContext.SendActivityAsync($"Your input message after translation is " + luisResponse.Text);

                    var topItem = luisResponse.TopIntent();
                    await turnContext.SendActivityAsync($"After using LUIS recognition:\nthe top intent was: {topItem.intent}, with score {topItem.score}");
                }

                break;

            case ActivityTypes.ConversationUpdate:
                foreach (var newMember in turnContext.Activity.MembersAdded)
                {
                    if (newMember.Id != turnContext.Activity.Recipient.Id)
                    {
                        await turnContext.SendActivityAsync("Hello and welcome to the Luis Sample bot.");
                    }
                }

                break;
            }
        }
Esempio n. 8
0
        private async Task HandleWeatherIntent(IDialogContext context, LuisResponse intent, bool showWeekendInfo)
        {
            if (intent.entities.Length > 0)
            {
                var location = string.Empty;
                //check to see if we just have a city, or a city and a state.
                if (intent.entities.Length == 2)
                {
                    location = intent.entities[0].entity + "," + intent.entities[1].entity;
                }
                else
                {
                    location = intent.entities[0].entity;
                }

                await GetDisplayWeatherInfo(context, location, showWeekendInfo);
            }
            else
            {
                context.UserData.SetValue("intentName", intent.topScoringIntent.intent);

                PromptDialog.Text(
                    context: context,
                    resume: CheckWeatherUserInfo,
                    prompt: "What city would you like the weather for? Enter in the City/State or Zip Code for the intended area.",
                    retry: "Sorry, I didn't understand that. Please try again."
                    );
            }
        }
Esempio n. 9
0
        protected virtual async Task AfterBirthdayEntry(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var message = await result;

            context.ConversationData.SetValue <string>("INSURANCE-BIRTHDAY", message.Text);

            LuisResponse luisInfo = await ServiceProxies.GetEntityFromLUIS(message.Text);

            if (luisInfo.intents != null && luisInfo.intents.Length > 0 && luisInfo.intents[0].score > 0.6 && luisInfo.intents[0].intent == "Abort")
            {
                await context.PostAsync("Ok, sorry, wir hören jetzt auf. Vielleicht ein anderes mal!");

                context.Done <string>(null);
            }
            else
            {
                string birthday        = message.Text;
                string insuranceNumber = context.ConversationData.GetValue <string>("INSURANCE-NUMBER");
                string insuranceName   = context.ConversationData.GetValue <string>("INSURANCE-NAME");
                System.Diagnostics.Trace.TraceInformation($"KREDITABL {insuranceNumber} - {insuranceName} - {birthday}");
                await context.PostAsync($"Vielen Dank, Ihre Kreditablöseinformation ist unterwegs!");

                context.Done <string>(null);
            }
        }
        private static async Task <LuisResponse> GetEntityFromConginitiveService(string text)
        {
            LuisResponse Data = new LuisResponse();

            try
            {
                text = Uri.EscapeDataString(text);

                using (HttpClient client = new HttpClient())
                {
                    var responseInString = await client.GetStringAsync(@"https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/59583dde-cc2f-4554-b004-db3bae7e9b8a?subscription-key=4939782dc2df43fbb61a67154a79a30a&staging=true&verbose=true&timezoneOffset=-360&q="
                                                                       + System.Uri.EscapeDataString(text));

                    Data = JsonConvert.DeserializeObject <LuisResponse>(responseInString);

                    //if (msg.IsSuccessStatusCode)
                    //{
                    //    var JsonDataResponse = await msg.Content.ReadAsStringAsync();

                    //}
                }
            }
            catch (Exception ex)
            {
                //ErrorLog.ErrorLogging("", ex.Message, "", DateTime.Now);
                throw ex;
            }
            return(Data);
        }
Esempio n. 11
0
        private void HandleIntent(LuisResponse intent, MessageType msgObj)
        {
            var primaryIntent = intent.topScoringIntent;
            var primaryEntity = intent.entities.FirstOrDefault();

            if (primaryIntent != null && primaryEntity != null)
            {
                if (primaryIntent.intent.Equals("PlaceOrder") && primaryIntent.score > 0.75)
                {
                    //Detected an actionable request with an identified entity
                    if (primaryEntity != null && primaryEntity.score > 0.5)
                    {
                        //TODO: Process request for identified entity
                        String destination = primaryEntity.type.Equals("PoolService::FoodItem")
                            ? "the bartender has been notified"
                            : "unknown request";
                        String generatedMessage = string.Format("We have sent your request {0} to {1}",
                                                                primaryEntity.entity, destination);
                        SendBotMessage(msgObj, generatedMessage);
                    }
                    else
                    {
                        //TODO: Process request generically
                        String generatedMessage = "We have received your request for service";
                        SendBotMessage(msgObj, generatedMessage);
                    }
                }
            }
        }
Esempio n. 12
0
        public async Task <LuisResponse> GetUserIntent(string query)
        {
            using (var client = new HttpClient {
                BaseAddress = new Uri(Configuration.LuisBaseAddress)
            })
            {
                var response = await client.GetAsync($"{Configuration.LuisAppId}?subscription-key={Configuration.LuisApiKey}&q={query}");

                if (!response.IsSuccessStatusCode)
                {
                    if (response.Content != null)
                    {
                        throw new WebException($"Server error {response.StatusCode} - {await response.Content.ReadAsStringAsync()}");
                    }
                    throw new Exception($"Server error {response.StatusCode}");
                }
                else
                {
                    var luisResponseDto = await response.Content.ReadAsAsync <LuisResponseDto>();


                    var luisResponse = new LuisResponse
                    {
                        UserIntent = (UserIntent)Enum.Parse(typeof(UserIntent), luisResponseDto.topScoringIntent.intent),
                        Entities   = luisResponseDto.entities.Select(e => e.entity).ToList()
                    };

                    return(luisResponse);
                }
            }



            //    var client = new RestClient( Configuration.LuisBaseAddress );

            //    var request = new RestRequest( Configuration.LuisAppId, Method.GET );

            //    request.AddParameter( "subscription-key", Configuration.LuisApiKey, ParameterType.QueryString );
            //    request.AddParameter( "q", query, ParameterType.QueryString );

            //    var response = await client.ExecuteGetTaskAsync<LuisResponseDto>( request );

            //    if (response.ResponseStatus != ResponseStatus.Completed)
            //    {
            //        throw new WebException( response.ErrorMessage, response.ErrorException );
            //    }



            //    var luisResponse = new LuisResponse
            //    {
            //        UserIntent = (UserIntent)Enum.Parse( typeof( UserIntent ), response.Data.topScoringIntent.intent ),
            //        Entities = response.Data.entities.Select( e => e.entity ).ToList()
            //    };

            //    return luisResponse;
        }
Esempio n. 13
0
 private ConversationResponse CheckUnsetEntity(LuisResponse response)
 {
     if (response.topScoringIntent?.intent == UnsetEntity)
     {
         this.SelectedEntity = null;
         return(new ConversationResponse("Seleccione otra entidad"));
     }
     return(null);
 }
Esempio n. 14
0
        private static string[] ExtractV1TimeEntities(ChatState state, LuisResponse luisResponse)
        {
            LuisDateParser parser = new LuisDateParser(state.GetUserTimeZoneOffset());

            var luisTimes = parser.ParseLuisTimes(luisResponse.Entities);

            return((from time in luisTimes
                    where time.Time != null
                    select time.Time.Format12Hour).ToArray());
        }
Esempio n. 15
0
        private async Task <string> ParseLuisResponse(LuisResponse luisResponse)
        {
            Intent winner = luisResponse.Winner();

            if (winner == null || winner.IsNone())
            {
                return(Sad);
            }

            return(luisResponse.Winner().Name);
        }
Esempio n. 16
0
        public async void MakeRequest(object sender, EventArgs e)
        {
            var client      = new HttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            // This app ID is for a public sample app that recognizes requests to turn on and turn off lights
            var luisAppId       = "<replace with your LUIS App ID here>";
            var subscriptionKey = "<replace with your LUIS subscription Key here>";

            // The request header contains your subscription key
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);

            // The "q" parameter contains the utterance to send to LUIS
            queryString["q"] = txtMessage.Text;

            // These optional request parameters are set to their default values
            queryString["timezoneOffset"] = "0";
            queryString["verbose"]        = "false";
            queryString["spellCheck"]     = "false";
            queryString["staging"]        = "false";

            var uri      = "https://southeastasia.api.cognitive.microsoft.com/luis/v2.0/apps/" + luisAppId + "?" + queryString; //remember to change to the region that you set in LUIS.ai
            var response = await client.GetAsync(uri);

            var strResponseContent = await response.Content.ReadAsStringAsync();

            //// Display the JSON result from LUIS
            //Console.WriteLine(strResponseContent.ToString());

            try
            {
                lblIntent.Text   = "";
                lblEntities.Text = "";
                LuisResponse luisResponse = JsonConvert.DeserializeObject <LuisResponse>(strResponseContent);
                if (luisResponse != null)
                {
                    if (luisResponse.topScoringIntent != null)
                    {
                        lblIntent.Text = luisResponse.topScoringIntent.intent;
                    }

                    if (luisResponse.entities.Count() > 0)
                    {
                        foreach (var entities in luisResponse.entities)
                        {
                            lblEntities.Text += entities.entity + "(" + entities.type + ")\n";
                        }
                    }
                }
            }catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Esempio n. 17
0
        public async Task <LuisResponse> LuisDetectDateTime([ActivityTrigger] IDurableActivityContext context, ILogger log)
        {
            var message = context.GetInput <string>();

            log.LogInformation("Calling Luis to detect time.");

            using var httpClient = _httpClientFactory.CreateClient();
            var luisJsonResponse = await httpClient.GetStringAsync(string.Format(_options.LuisUrl, message));

            return(LuisResponse.Parse(luisJsonResponse));
        }
Esempio n. 18
0
        private DateTimeParseResult[] ExtractDateResults(ChatState chatState, LuisResponse luisResponse, bool assumeFuture)
        {
            LuisDateParser parser = new LuisDateParser(chatState.GetUserTimeZoneOffset());

            if (luisResponse?.Entities.Length > 0)
            {
                return(parser.ParseLuisDates(luisResponse.Entities, assumeFuture));
            }

            return(null);
        }
Esempio n. 19
0
        /// <summary>
        /// Gets message from WPF and sends data to LUIS.ai and return json object
        /// </summary>
        /// <param name="utterance">the WPF user message</param>
        /// <returns>A JSON Object with data to make the query to send</returns>
        private async Task <LuisResponse> GetFromLuisAsync(string utterance)
        {
            string key       = Credentials.LUIS_KEY;
            string endpoint  = Credentials.LUIS_URL;
            string LUISAppID = Credentials.LUIS_ID;

            string luisResponse = await MakeRequest(key, endpoint, LUISAppID, utterance);

            LuisResponse wholeData = JsonConvert.DeserializeObject <LuisResponse>(luisResponse);

            return(wholeData);
        }
Esempio n. 20
0
        private void AssertResponse(LuisResponse actual, ExpectedResponse expected)
        {
            Assert.NotNull(actual);
            Assert.NotNull(expected);
            Assert.True(expected.Intent == actual.topScoringIntent.intent, "intents do not match");

            var entity = actual.entities.OrderByDescending(e => e.score).FirstOrDefault();

            Assert.True(entity != null, "entity should not be null!");
            Assert.True(expected.EntityType == entity.@type, "entity types do not match!");
            Assert.True(string.Equals(expected.EntityValue, entity.entity, StringComparison.OrdinalIgnoreCase), "entity values do not match!");
        }
Esempio n. 21
0
        public static string GetHighScoringIntent(LuisResponse intent)
        {
            //by default set intent to None. Check response to verify that the intent is a good match
            var intentName = "None";

            if (intent.topScoringIntent.score > 0.6)
            {
                intentName = intent.topScoringIntent.intent;
            }

            return(intentName);
        }
Esempio n. 22
0
        /// <summary>
        /// Gets JSON (response data from LUIS) object and returns query as a string
        /// </summary>
        /// <param name="data">the response data from LUIS</param>
        /// <returns></returns>
        private string ConstructQueryHelper(LuisResponse data)
        {
            TopScoringIntent processedIntent = data.TopScoringIntent;
            string           actualQuery     = string.Empty;

            switch (processedIntent.Intent)//compose the query
            {
            case "None":
                throw new Exception("Please paraphrase your question, couldn't understand what you meant!");

            case "MachineRequestData":

                List <Entity>      machineEntities = data.Entities;
                MachineRequestData machineRequest  = new MachineRequestData();
                machineRequest.SensorID = machineEntities.Find(e => e.Type == "MachineID").entity;
                machineRequest.Type     = machineEntities.Find(e => e.Type == "MachineRequestType").resolution.values[0];
                actualQuery             = JsonConvert.SerializeObject(machineRequest);
                break;

            default:
                List <Entity>             kpiEntities           = data.Entities;
                KPIRequestDataWithoutPart kpiRequestWithoutPart = new KPIRequestDataWithoutPart();
                int buf;
                kpiRequestWithoutPart.KpiType   = processedIntent.Intent;
                kpiRequestWithoutPart.WorkOrder = kpiEntities.Find(e => e.Type == "KPIworkOrderID" && int.TryParse(e.entity, out buf)).entity;

                //get part entity
                CompositeEntity kpiOrderPart = data.CompositeEntities.Find(e => (e.ParentType == "KPIrequestDataPart" && int.TryParse(e.Value, out buf)));

                //filter request types without part
                if (processedIntent.nonOrderQuery() && kpiOrderPart != null)
                {
                    string kpiOrderPartValue = kpiOrderPart.Value;
                    if (kpiOrderPart != null)
                    {
                        string serializedKPIWithoutPart           = JsonConvert.SerializeObject(kpiRequestWithoutPart);
                        KPIRequestDataWithPart kpiRequestWithPart = JsonConvert.DeserializeObject <KPIRequestDataWithPart>(serializedKPIWithoutPart);
                        kpiRequestWithPart.Part = kpiOrderPartValue;
                        actualQuery             = JsonConvert.SerializeObject(kpiRequestWithPart);
                        break;
                    }
                    else
                    {
                        //couldn't find part value
                        throw new NullReferenceException("Couldn't find part value");
                    }
                }

                actualQuery = JsonConvert.SerializeObject(kpiRequestWithoutPart);
                break;
            }
            return(actualQuery);
        }
Esempio n. 23
0
        /// <summary>
        /// Replaces all entity types that were found in the message construct by their values from the LuisResponse
        /// </summary>
        /// <param name="textToUpdate">The message text that should be updated. This needs to include the entity types in the format {entityType}.</param>
        /// <param name="luisReponse">The LuisResponse that is used to replace the entity values from the message.</param>
        private string ReplaceWithLuisEntities(string textToUpdate, LuisResponse luisResponse)
        {
            var newText = textToUpdate;

            // TODO: What to do, when a entity is included in message, but not found in LuisResponse?

            foreach (var entity in luisResponse.Entities)
            {
                newText = newText.Replace("{" + entity.Type + "}", entity.EntityEntity);
            }

            return(newText);
        }
Esempio n. 24
0
        public override async Task <Message> OnMessage()
        {
            if (Message.Text.Equals(Hi, StringComparison.InvariantCultureIgnoreCase))
            {
                return(Message.CreateReplyMessage(Sample));
            }

            LuisResponse luisResponse = await _luisClient.SendQuery(Message.Text);

            string result = await ParseLuisResponse(luisResponse);

            return(Message.CreateReplyMessage(result));
        }
        /// <summary>
        /// Extracts date and time information from the transcript.
        /// </summary>
        /// <param name="luisResponse">The transcript.</param>
        /// <param name="log">Trace logging instance.</param>
        /// <returns>The extracted date and time information.</returns>
        public List<DateInfo> ExtractDateTimes(LuisResponse luisResponse, ILogger log)
        {
            List<DateInfo> dateInfos = new List<DateInfo>();

            if (luisResponse.Entities == null
                || luisResponse.Entities.Count == 0)
            {
                return dateInfos;
            }

            dateInfos.AddRange(GetDateInfos(luisResponse.Entities));

            return dateInfos;
        }
Esempio n. 26
0
        private static async Task <LuisResponse> GetIntentAndEntities(string messageText)
        {
            LuisResponse result = null;

            string queryUri = string.Format(_luisQueryParams, _luisAppId, _luisKey, Uri.EscapeDataString(messageText));
            HttpResponseMessage response = await _intentClient.GetAsync($"{_luisBaseUrl}/{queryUri}");

            string res = await response.Content.ReadAsStringAsync();

            result = JsonConvert.DeserializeObject <LuisResponse>(res);

            Console.WriteLine("\nLUIS Response:\n" + res);

            return(result);
        }
Esempio n. 27
0
        public void DoAction(LuisResponse luis)
        {
            if (luis.TopScoringIntent.Intent == "TurnOnTv")
            {
                TurnOn(luis.Entities.OrderByDescending(e => e.Score).FirstOrDefault());
            }

            if (luis.TopScoringIntent.Intent == "FullScreenTv")
            {
                IsFullscreen = true;
            }

            if (luis.TopScoringIntent.Intent == "ReduceScreenTv")
            {
                IsFullscreen = false;
            }
        }
Esempio n. 28
0
        protected virtual async Task StartKreditAblöseDialog(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var input = await result;

            LuisResponse luisInfo = await ServiceProxies.GetEntityFromLUIS(input.Text);

            if (luisInfo.intents.Length > 0 && luisInfo.intents[0].intent == "Ja")
            {
                // Yes start kreditablösedialog
                IDialog <string> kreditDialog = (IDialog <string>) new KreditAblöseDialog();
                context.Call(kreditDialog, AfterKreditDialog);
            }
            else
            {
                context.Wait(MessageReceivedAsync);
            }
        }
Esempio n. 29
0
        private LuisResponseModel ParseResponse(LuisResponse luisResponse)
        {
            var model = new LuisResponseModel();

            foreach (var entity in luisResponse.entities)
            {
                if (!String.IsNullOrWhiteSpace(entity.role))
                {
                    model.Name = entity.role;
                }

                if (entity.resolution != null)
                {
                    model.Value = entity.resolution.value;
                }
            }
            return(model);
        }
        private async Task <LuisResponse> GetIntentAndEntities(string messageText)
        {
            LuisResponse result = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(_luisBaseUrl);
                string queryUri = string.Format(_luisQueryParams, _luisAppId, _luisKey, Uri.EscapeDataString(messageText));
                HttpResponseMessage response = await client.GetAsync(queryUri);

                string res = await response.Content.ReadAsStringAsync();

                result = JsonConvert.DeserializeObject <LuisResponse>(res);

                Console.WriteLine("\nLUIS Response:\n" + res);
            }
            return(result);
        }