示例#1
0
        /// <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));
                //// calculate something for us to return
                //int length = (activity.Text ?? string.Empty).Length;

                //// return our reply to the user
                //Activity reply = activity.CreateReply($"You sent {activity.Text} which was {length} characters");
                //await connector.Conversations.ReplyToActivityAsync(reply);

                string ResponseString = "";


                LUISDataModel LDM = await GetIntentFromLUIS(activity.Text);

                if (LDM.entities.Count() > 0)
                //if (LDM.entities.Count() > 0)
                {
                    //switch (LDM.topintent.intent)
                    switch (LDM.entities[0].type)
                    {
                    case "StockSymbol":
                        ResponseString = await GetStock(LDM.entities[0].entity);

                        break;

                    case "WeatherLocation":
                        ResponseString = await GetWeather(LDM.entities[0].entity);

                        break;

                    default:
                        ResponseString = "Sorry, I am not getting you...";
                        break;
                    }
                }
                else
                {
                    ResponseString = "Sorry, I am not getting you...";
                }

                // return our reply to the user  
                Activity reply = activity.CreateReply(ResponseString);
                await connector.Conversations.ReplyToActivityAsync(reply);
            }
            else
            {
                HandleSystemMessage(activity);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }
示例#2
0
        private static async Task <LUISDataModel> GetIntentFromLUIS(string Query)
        {
            Query = Uri.EscapeDataString(Query);
            LUISDataModel Data = new LUISDataModel();

            using (HttpClient client = new HttpClient())
            {
                string RequestURI       = ConfigurationManager.AppSettings["LuisURI"] + "&q=" + Query;
                HttpResponseMessage msg = await client.GetAsync(RequestURI);

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

                    Data = JsonConvert.DeserializeObject <LUISDataModel>(JsonDataResponse);
                }
            }
            return(Data);
        }