Esempio n. 1
0
        public static async Task <LUISResponse> GetIntentFromLUIS(string Query)
        {
            Query = Uri.EscapeDataString(Query);
            LUISResponse Data = new LUISResponse();

            using (HttpClient client = new HttpClient())
            {
                string RequestURI       = "https://api.projectoxford.ai/luis/v1/application?id=" + Environment.GetEnvironmentVariable("YESBOT.LUIS_ID") + "&subscription-key=" + Environment.GetEnvironmentVariable("YESBOT.LUIS_PASSWORD") + "&q=" + Query;
                HttpResponseMessage msg = await client.GetAsync(RequestURI);

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

                    Data = JsonConvert.DeserializeObject <LUISResponse>(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 activity)
        {
            if (activity.Type == ActivityTypes.Message && activity.Text.Length > 0)
            {
                // Request intent and entities from LUIS
                LUISResponse luis = await LUISFactory.GetIntentFromLUIS(activity.Text);

                // Manual calculation is LUIS caps out
                if (luis.intents.Count() == 0 && (
                        activity.Text.ToLower().Contains("yesbot") ||
                        activity.Text.ToLower().Contains("agreed?") ||
                        activity.Text.ToLower().Contains("agree?") ||
                        activity.Text.ToLower().Contains("yes?") ||
                        activity.Text.ToLower().Contains("think?") ||
                        activity.Text.ToLower().Contains("do you agree") ||
                        activity.Text.ToLower().Contains("what do you think")) ||
                    // Or if LUIS decides to trigger agreement
                    luis.intents[0].intent == "RequestAgreement"
                    )
                {
                    ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
                    // random statements of agreement to return
                    string[] statements = new[] { "I agree with you 100 percent.", "I couldn't agree with you more.", "I'm with you on this one!", "That's so true!", "For sure!", "Tell me about it!", "You're absolutely right.", "That's exactly how I feel.", "No doubt about it.", "You have a point there.", "I was just going to say that!", "You are so right.", "I couldn't have said it better myself." };

                    // return a random statement to the user
                    Activity reply = activity.CreateReply($"{statements[rand.Next(statements.Length)]}");
                    await connector.Conversations.ReplyToActivityAsync(reply);
                }
            }
            else
            {
                HandleSystemMessage(activity);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }