Esempio n. 1
0
        private static async Task <CountyLUIS> GetEntityFromLUIS(string Query)
        {
            Query = Uri.EscapeDataString(Query);
            CountyLUIS Data = new CountyLUIS();

            using (HttpClient client = new HttpClient())
            {
                string RequestURI = WebConfigurationManager.AppSettings["LUISAPIURI"] + Query;


                HttpResponseMessage msg = await client.GetAsync(RequestURI);

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

                    Data = JsonConvert.DeserializeObject <CountyLUIS>(JsonDataResponse);
                }
            }
            return(Data);
        }
Esempio n. 2
0
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task <HttpResponseMessage> Post([FromBody] Activity message)
        {
            ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));

            if (message.Type == "message")
            {
                string     StockRateString;
                CountyLUIS StLUIS = await GetEntityFromLUIS(message.Text);

                if (StLUIS.intents.Count() > 0 && StLUIS.entities.Count() > 1)
                {
                    switch (StLUIS.intents[0].intent)
                    {
                    case "AddComplaints":
                        StockRateString = await AddComplaint(StLUIS.entities[0].entity, StLUIS.entities[1].entity, message.Text);

                        break;

                    case "GetComplaintsStatus":
                        StockRateString = await AddComplaint(StLUIS.entities[0].entity, "empty", message.Text);

                        break;

                    default:
                        StockRateString = "Sorry, I am not getting you. :(\nPlease try contacting our super friendly officer at  +1 425-882-8080";
                        break;
                    }
                }

                else if (StLUIS.intents.Count() > 0 && StLUIS.entities.Count() > 0)
                {
                    StateClient stateClient = message.GetStateClient();
                    BotData     userData    = await stateClient.BotState.GetUserDataAsync(message.ChannelId, message.From.Id);

                    switch (StLUIS.intents[0].intent)
                    {
                    case "AddComplaints":


                        userData.SetProperty <string>("entity1", StLUIS.entities[0].entity);
                        await stateClient.BotState.SetUserDataAsync(message.ChannelId, message.From.Id, userData);

                        StockRateString = await AddComplaint(StLUIS.entities[0].entity);

                        break;

                    case "GetComplaintsStatus":
                        StockRateString = await AddComplaint(StLUIS.entities[0].entity, "empty", message.Text);

                        break;

                    case "EnterLocation":

                        string intent = userData.GetProperty <string>("entity1").ToString();
                        StockRateString = await AddComplaint(intent, StLUIS.entities[0].entity, message.Text);

                        break;

                    default:
                        StockRateString = "Sorry, I am not getting you. :(\nPlease try contacting our super friendly officer at  +1 425-882-8080";
                        break;
                    }
                }
                else
                {
                    StockRateString = "Sorry, I am not getting you. :(\nPlease try contacting our super friendly officer at  +1 425-882-8080";
                }

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

            return(response);
        }