コード例 #1
0
        public async Task Help(IDialogContext context, LuisResult result)
        {
            QureyController qc = new QureyController();

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");

            if (result.TopScoringIntent.Score < 0.4)
            {
                string ans = "";
                ans = qc.GetTrainedAnswer(result.Query);

                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);

                await context.PostAsync(ans);

                context.Wait(MessageReceived);
            }
            else
            {
                var options = new UserChoice[]
                {
                    UserChoice.SearchWiki, UserChoice.Weather, UserChoice.PopularMovie, UserChoice.SearchMovie,
                    UserChoice.Game, UserChoice.Train
                };
                var descriptions = new string[]
                {
                    "Search Wikipedia", "Get Weather Info", "Popular Movies", "Search for movie", "Play Game",
                    "Train Me"
                };
                PromptDialog.Choice <UserChoice>(context, ResumeAfterDialogChoiceSelection,
                                                 options, "You asked for help, well here are some of main topics you can find here...",
                                                 descriptions: descriptions);
            }
        }
コード例 #2
0
        public async Task Color(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            string          ans = "";
            string          ent = "it";
            QureyController qc  = new QureyController();

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");
            if (result.Entities != null && result.Entities.Count > 0)
            {
                ent = result.Entities[0].Entity;
            }

            string[] matching_words = { "blue", "your", "favourite", "like", "love" };
            if (FindMatchingString.findMatchingString(result.Query, matching_words))
            {
                ans = "Well blue is my favourite color. But i also like other colors.. :) ";
            }
            else
            {
                string[] listAns = { ent + "is interesting color but my favourite one is blue :)", "I don't find " + ent + " colorfull enough xD", "Well " + ent + " is interesting color but not as my favourite ;)", "Yea i like " + ent + " too :) " };
                Random   rand    = new Random();
                ans = listAns[rand.Next(0, listAns.Length)];
            }
            qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
            await context.PostAsync(ans);

            context.Wait(MessageReceived);
        }
コード例 #3
0
        public async Task Music(IDialogContext context, LuisResult result)
        {
            QureyController qc  = new QureyController();
            string          ans = "";

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");
            if (result.TopScoringIntent.Score < 0.3)
            {
                ans = qc.GetTrainedAnswer(result.Query);
                await context.PostAsync(ans);

                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
                context.Wait(MessageReceived);
            }
            else
            {
                bool     found           = false;
                string[] matching_words1 = { "like" };
                string[] matching_words2 = { "make", "create", "play" };
                string[] matching_words3 = { "you" };

                string tr_ans = qc.GetTrainedAnswer(result.Query);

                if (!string.IsNullOrEmpty(tr_ans))
                {
                    ans   = tr_ans;
                    found = true;
                }
                else if (FindMatchingString.findMatchingString(result.Query, matching_words1))
                {
                    ans   = "Well I can say that I do :D ";
                    found = true;
                }
                else if (FindMatchingString.findMatchingString(result.Query, matching_words2))
                {
                    ans = "Hmmm well listen to this... DO RE MI .... FA SO LAAAAAaaaaaaaa... How did that sound xD ";
                }
                else if (FindMatchingString.findMatchingString(result.Query, matching_words3))
                {
                    ans   = "Well music is always fun. :) ";
                    found = true;
                }
                else
                {
                    var options      = new MovieChoice[] { MovieChoice.PopularMovie, MovieChoice.SearchMovie };
                    var descriptions = new string[] { "Popular Movies", "Search for movie" };
                    PromptDialog.Choice <MovieChoice>(context, ResumeAfterMovieChoiceSelection,
                                                      options, "What would you like to choose about movies?", descriptions: descriptions);
                }
                if (found)
                {
                    await context.PostAsync(ans);

                    context.Wait(MessageReceived);
                }

                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
                context.Call(new BingWikiSearchDialog(), this.ResumeAfterOptionDialog);
            }
        }
コード例 #4
0
        public async Task Weather(IDialogContext context, LuisResult result)
        {
            // OpenWeatherAPI openWeatherAPI = new OpenWeatherAPI(WebConfigurationManager.AppSettings["OpenWeatherAPI"]);
            //OpenWeatherAPI openWeatherAPI = new OpenWeatherAPI("bd5e378503939ddaee76f12ad7a97608");
            string          entity = "";
            QureyController qc     = new QureyController();

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");

            if (result.Entities.Count > 0)
            {
                entity = result.Entities[0].Entity;
            }

            if (entity == "" || WeatherData.getWeatherData(entity) == null)
            {
                context.Call(new WeatherDialog(), this.ResumeAfterOptionDialog);
            }
            else
            {
                try
                {
                    CardUtil.showWeatherHeroCard((IMessageActivity)context.Activity, WeatherData.getWeatherData(entity));
                    string res = "Weather for entity";
                    qc.PostAnswerOne(res, result.TopScoringIntent.Intent);
                }
                catch (Exception e)
                {
                    Debug.WriteLine($"Error when generating data: {e}");
                    await context.PostAsync($"I couldn't find a weather forecast :( You can try again. ");
                }
            }
        }
コード例 #5
0
        public async Task WelcomeGreeting(IDialogContext context, string messageText)
        {
            QureyController qc  = new QureyController();
            string          ans = qc.GetAnswer(messageText, "Greetings", "0.8", "0");
            await context.PostAsync(ans);

            context.Done(true);
        }
コード例 #6
0
        public async Task ArtistInfo(IDialogContext context, LuisResult result)
        {
            QureyController qc     = new QureyController();
            string          entity = "";
            string          ans    = "";

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");

            if (result.Entities != null)
            {
                switch (result.Entities.Count)
                {
                case 1:
                    entity += result.Entities[0].Entity;
                    break;

                case 2:
                    entity += result.Entities[0].Entity + " " + result.Entities[1].Entity;
                    break;

                case 3:
                    entity += result.Entities[0].Entity + " " + result.Entities[1].Entity + " " + result.Entities[2].Entity;
                    break;
                }
            }
            else
            {
                entity = result.Query;
            }

            await context.PostAsync("Here are results i found : ");

            try
            {
                BingSearch bingSearch = new BingSearch();

                bingSearch = BingSearchData.getSearchResult(entity);

                if (bingSearch != null)
                {
                    CardUtil.showBingWikiHeroCard((IMessageActivity)context.Activity, bingSearch);
                    ans = bingSearch.news.readLink;
                }
                else
                {
                    await context.PostAsync($"I couldn't find a artist info :0");
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Error when filtering artists: {e}");
            }
            if (ans == "")
            {
                ans = "";
            }
            qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
        }
コード例 #7
0
        public async Task Advice(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            QureyController qc  = new QureyController();
            string          ans = qc.GetAnswer(result.Query, "Advice", result.TopScoringIntent.Score.ToString(), "0");
            await context.PostAsync("Here are my thoughts for you : ");

            await context.PostAsync(ans);

            context.Wait(MessageReceived);
        }
コード例 #8
0
        private Activity HandleSystemMessage(Activity message)
        {
            if (message.Type == ActivityTypes.DeleteUserData)
            {
                // Implement user deletion here
                // If we handle user deletion, return a real message
            }
            else if (message.Type == ActivityTypes.ConversationUpdate)
            {
                // Handle conversation state changes, like members being added and removed
                // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
                // Not available in all channels

                // Note: Add introduction here:
                string msg = "Hello there! My name is Arnie Bot and I am here to assist you. You can start by typing things like 'Hello' or 'How are you' or 'Can you give me advice' ... STry one of those : Let's play game, How are you, What's the weather like today, List popular Movies... And if you get stuck or you want to check basic functionality, just type 'help' or 'settings'.";

                IConversationUpdateActivity update = message;
                var client = new ConnectorClient(new Uri(message.ServiceUrl), new MicrosoftAppCredentials());
                if (update.MembersAdded != null && update.MembersAdded.Any())
                {
                    foreach (var newMember in update.MembersAdded)
                    {
                        if (newMember.Id != message.Recipient.Id)
                        {
                            var reply = message.CreateReply();


                            reply.Text = msg;

                            client.Conversations.ReplyToActivityAsync(reply);

                            Session session = new Session();
                            session.Date = DateTime.Now;
                            QureyController qc = new QureyController();
                            qc.PostSession(session);
                        }
                    }
                }
            }
            else if (message.Type == ActivityTypes.ContactRelationUpdate)
            {
                // Handle add/remove from contact lists
                // Activity.From + Activity.Action represent what happened
            }
            else if (message.Type == ActivityTypes.Typing)
            {
                // Handle knowing tha the user is typing
            }
            else if (message.Type == ActivityTypes.Ping)
            {
            }

            return(null);
        }
コード例 #9
0
        public async Task MovieSearch(IDialogContext context, LuisResult result_luis)
        {
            QureyController qc  = new QureyController();
            string          ans = "";

            qc.PostQuestionOne(result_luis.Query, result_luis.TopScoringIntent.Intent, result_luis.TopScoringIntent.Score.ToString(), "0");
            if (result_luis.TopScoringIntent.Score < 0.4)
            {
                ans = qc.GetTrainedAnswer(result_luis.Query);
                qc.PostAnswerOne(ans, result_luis.TopScoringIntent.Intent);
                await context.PostAsync(ans);

                context.Wait(MessageReceived);
            }
            else
            {
                string entity = "";

                if (result_luis.Entities.Count > 0)
                {
                    entity = result_luis.Entities[0].Entity;
                }

                if (entity == "")
                {
                    entity = "Star Wars: The Last Jedi";
                    await context.PostAsync("Here is a movie which i found : ");
                }
                try
                {
                    MoviesSearch search      = new MoviesSearch();
                    Movie        movieResult = await search.SearchByName(entity);

                    if (movieResult.id != 0)
                    {
                        CardUtil.showHeroCard((IMessageActivity)context.Activity, movieResult);
                        ans = movieResult.Title;
                    }
                    else
                    {
                        await context.PostAsync($"I couldn't find a movie :0");
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine($"Error when filtering by genre: {e}");
                }

                qc.PostAnswerOne(ans, result_luis.TopScoringIntent.Intent);
                context.Done <object>(null);
            }
        }
コード例 #10
0
        private async Task <QnAMakerResult> GetQnAMakerResponse(string query, string knowledgeBaseId, string subscriptionKey)
        {
            string responseString = string.Empty;

            var knowledgebaseId         = knowledgeBaseId; // Use knowledge base id created.
            var qnamakerSubscriptionKey = subscriptionKey; //Use subscription key assigned to you.

            //Build the URI
            Uri qnamakerUriBase = new Uri("https://westus.api.cognitive.microsoft.com/qnamaker/v2.0");
            var builder         = new UriBuilder($"{qnamakerUriBase}/knowledgebases/{knowledgebaseId}/generateAnswer");

            //Add the question as part of the body
            var postBody = $"{{\"question\": \"{query}\"}}";

            //Send the POST request
            using (WebClient client = new WebClient())
            {
                //Set the encoding to UTF8
                client.Encoding = System.Text.Encoding.UTF8;

                //Add the subscription key header
                client.Headers.Add("Ocp-Apim-Subscription-Key", qnamakerSubscriptionKey);
                client.Headers.Add("Content-Type", "application/json");
                responseString = client.UploadString(builder.Uri, postBody);
            }

            //De-serialize the response
            QnAMakerResult response;

            try
            {
                // response = JsonConvert.DeserializeObject<QnAMakerResult>(responseString);

                var seriesCollection = JObject.Parse(responseString)["answers"]
                                       .ToObject <ObservableCollection <QnAMakerResult> >();

                List <QnAMakerResult> res = new List <QnAMakerResult>();
                res = seriesCollection.ToList();

                response = res[0];
                QureyController qc = new QureyController();
                qc.PostAnswerOne(response.Answer, "None");
                return(response);
            }
            catch
            {
                throw new Exception("Unable to deserialize QnA Maker response string.");
            }
        }
コード例 #11
0
        public async Task TrainBot(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            QureyController qc = new QureyController();

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");
            if (result.TopScoringIntent.Score > 0.3)
            {
                context.Call(new TrainDialog(), this.ResumeAfterOptionDialog);
            }
            else
            {
                await context.PostAsync("tr tr tr trrrr try to ask me something else xD ttr trtrr trr trr");

                context.Wait(MessageReceived);
            }
        }
コード例 #12
0
        private async Task AfterQnADialog(IDialogContext context, IAwaitable <bool> result)
        {
            QureyController qc          = new QureyController();
            var             answerFound = await result;

            // we might want to send a message or take some action if no answer was found (false returned)
            if (!answerFound)
            {
                string ans = "Sorry, I really do not understand your intention. You can write 'help' to get more options. You can also train me by typing 'Train me'.";


                await context.PostAsync(ans);

                qc.PostAnswerOne(ans, "None");
            }
            context.Wait(MessageReceived);
        }
コード例 #13
0
        public virtual async Task ResumeGetAnswer(IDialogContext context, IAwaitable <string> mobile)
        {
            string response = await mobile;

            answer = response;

            try
            {
                QureyController qc = new QureyController();
                qc.PostTrainedAnswer(question, answer);
            }
            finally
            {
                await context.PostAsync("Thanks for training me. If you would like to add more, just type 'train'");

                context.Done(this);
            }
        }
コード例 #14
0
        public async Task WhoIsYou(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            QureyController qc = new QureyController();

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");
            if (result.TopScoringIntent.Score < 0.4)
            {
                string ans = "";
                ans = qc.GetTrainedAnswer(result.Query);
                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
                await context.PostAsync(ans);

                context.Wait(MessageReceived);
            }
            else
            {
                string   ans             = "";
                string[] matching_words  = { "yourself", "robot", "human", "created" };
                string[] matching_words1 = { "doing" };
                if (FindMatchingString.findMatchingString(result.Query, matching_words))
                {
                    ans =
                        "Well I am created out of 0 and 1. I can not say for myself that I'm a human but am I a robot? Huh. I can just say that I was created in good spirit to help you, that's all :) ";
                }
                else if (FindMatchingString.findMatchingString(result.Query, matching_words1))
                {
                    ans = "All I can say is that I'm created for your purpose.";
                }
                else
                {
                    string[] listAns =
                    {
                        "Like you already know, my name is Arnie and I'm a chat bot, you can ask me some interesting question :)",
                        "Arnie is my name and my purpose is to help you waste your time ;)"
                    };
                    Random rand = new Random();
                    ans = listAns[rand.Next(0, listAns.Length)];
                }
                await context.PostAsync(ans);

                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
                context.Wait(MessageReceived);
            }
        }
コード例 #15
0
        public async Task WhoIsQuestion(IDialogContext context, IAwaitable <IMessageActivity> activity,
                                        LuisResult result)
        {
            QureyController qc = new QureyController();

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");

            if (result.TopScoringIntent.Score > 0.5)
            {
                string entity = result.Query;

                await context.PostAsync("I think it is : ");

                try
                {
                    BingSearch bingSearch = new BingSearch();

                    bingSearch = BingSearchData.getSearchResult(entity);

                    if (bingSearch != null)
                    {
                        CardUtil.showBingWikiHeroCard((IMessageActivity)context.Activity, bingSearch);
                    }
                    else
                    {
                        await context.PostAsync($"I couldn't find any results :( You can try again.");
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine($"I couldn't find any results :( You can try again.");
                    Console.WriteLine(e);
                }
            }
            else
            {
                string ans = "";
                ans = qc.GetTrainedAnswer(result.Query);
                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
                await context.PostAsync(ans);

                context.Wait(MessageReceived);
            }
        }
コード例 #16
0
        public async Task Thanks(IDialogContext context, LuisResult result)
        {
            QureyController qc = new QureyController();

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");
            string ans = "";

            string[] listAns = { "No problem :) ", "You are welcome :) ", "Tha's great, you are welcome... " };

            Random random = new Random();
            int    rand   = random.Next(0, listAns.Length);

            ans = listAns[rand];

            await context.PostAsync(ans);

            qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
            context.Wait(MessageReceived);
        }
コード例 #17
0
        public async Task PopularMovies(IDialogContext context, LuisResult result_luis)
        {
            QureyController qc = new QureyController();

            qc.PostQuestionOne(result_luis.Query, result_luis.TopScoringIntent.Intent, result_luis.TopScoringIntent.Score.ToString(), "0");

            if (result_luis.TopScoringIntent.Score < 0.4)
            {
                string ans = "";
                ans = qc.GetTrainedAnswer(result_luis.Query);
                qc.PostAnswerOne(ans, result_luis.TopScoringIntent.Intent);
                await context.PostAsync(ans);

                context.Wait(MessageReceived);
            }
            else
            {
                // List of popular movies
                try
                {
                    MoviesSearch search      = new MoviesSearch();
                    List <Movie> movieResult = await search.GetPopularMovies();

                    if (movieResult.Count != 0)
                    {
                        CardUtil.showHeroCardMovies((IMessageActivity)context.Activity, movieResult);
                        qc.PostAnswer(result_luis.Query, movieResult[0].Title, "PopularMovies", "0.75", "0.75");
                    }
                    else
                    {
                        await context.PostAsync($"I couldn't find a movie :0");

                        qc.PostAnswer(result_luis.Query, "I couldn\'t find a movie", "PopularMovies", "0.75", "0.75");
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine($"Error when filtering by popular movies: {e}");
                }
                context.Done <object>(null);
            }
        }
コード例 #18
0
        public async Task BadLanguage(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            QureyController qc  = new QureyController();
            string          ans = "";

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");

            if (result.TopScoringIntent.Score < 0.4)
            {
                ans = qc.GetTrainedAnswer(result.Query);
                await context.PostAsync(ans);

                context.Wait(MessageReceived);
                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
            }
            else
            {
                string[] matching_words = { "suck", "rude", "bad", "created", "like" };
                if (FindMatchingString.findMatchingString(result.Query, matching_words))
                {
                    ans = "I'm so sorry to hear that. Well I'm still developing, give me a chance... :) ";
                }
                else
                {
                    string[] listAns =
                    {
                        "You should not speak like that",                                       "That's not good.",
                        "You should take a deep breath and clear your mind and start again :)",
                        "Maybe to try something else or some other comment :)"
                    };
                    Random rand = new Random();
                    ans = listAns[rand.Next(0, listAns.Length)];
                }
                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
                await context.PostAsync(ans);

                context.Wait(MessageReceived);
            }
        }
コード例 #19
0
        public async Task GoogleSearch(IDialogContext context, LuisResult result_luis)
        {
            QureyController qc  = new QureyController();
            string          ans = "";

            qc.PostQuestionOne(result_luis.Query, result_luis.TopScoringIntent.Intent, result_luis.TopScoringIntent.Score.ToString(), "0");
            try
            {
                List <GoogleSearchList> searchResult = GoogleSearchApi.getSearchResult(result_luis.Query);
                if (searchResult.Count != 0)
                {
                    await context.PostAsync($"Here is what i found");

                    await context.PostAsync($"List of search results : ");

                    CardUtil.showHeroCardSearch((IMessageActivity)context.Activity, searchResult);
                    ans = searchResult[0].Link;
                }
                else
                {
                    ans = $"I couldn't find a desired search :(";
                    await context.PostAsync(ans);
                }
            }
            catch (Exception e)
            {
                ans = $"Sorry, I'm currently unable to do a specific search, please try again later.";
                await context.PostAsync(ans);

                Debug.WriteLine($"Error when filtering by popular movies: {e}");
            }
            if (ans == "")
            {
                ans = "Google_search_result";
            }
            qc.PostAnswerOne(ans, result_luis.TopScoringIntent.Intent);
            context.Done <object>(null);
        }
コード例 #20
0
        public async Task Joke(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            QureyController qc = new QureyController();

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");
            if (result.TopScoringIntent.Score < 0.4)
            {
                string ans = "";
                ans = qc.GetTrainedAnswer(result.Query);
                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
                await context.PostAsync(ans);

                context.Wait(MessageReceived);
            }
            else
            {
                await context.PostAsync("Here is one joke... ");

                await context.PostAsync(qc.GetAnswer(result.Query, "Joke", result.TopScoringIntent.Score.ToString(), "0"));

                context.Wait(MessageReceived);
            }
        }
コード例 #21
0
        public async Task None(IDialogContext context, IAwaitable <IMessageActivity> message, LuisResult result)
        {
            QureyController qc = new QureyController();

            qc.PostQuestionOne(result.Query, "None", "0.75", "0.75");

            string ans = qc.GetTrainedAnswer(result.Query);

            if (ans == "")
            {
                var qnadialog        = new QnADialog();
                var messageToForward = await message;

                await context.Forward(qnadialog, AfterQnADialog, messageToForward, CancellationToken.None);
            }
            else
            {
                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
                await context.PostAsync(ans);

                context.Wait(MessageReceived);
            }
        }
コード例 #22
0
        public async Task UserAnswers(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            QureyController qc  = new QureyController();
            string          ans = "";

            if (result.TopScoringIntent.Score < 0.4)
            {
                ans = qc.GetTrainedAnswer(result.Query);
            }

            if (ans == "" || ans == "Hmmm ...")
            {
                string[] listAns = { "That's great.", "Excelent", "I'm glad to hear that." };
                Random   rand    = new Random();
                ans = listAns[rand.Next(0, listAns.Length)];
            }

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");
            qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
            await context.PostAsync(ans);

            context.Wait(MessageReceived);
        }
コード例 #23
0
        public async Task No(IDialogContext context, LuisResult result)
        {
            QureyController qc = new QureyController();

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");

            if (result.TopScoringIntent.Score < 0.3)
            {
                string ans = "";
                ans = qc.GetTrainedAnswer(result.Query);
                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
                await context.PostAsync(ans);

                context.Wait(MessageReceived);
            }
            else
            {
                string[] matching_words = { "nothing" };
                string   ans            = "";
                string[] listAns        = { "Oh ok..", "Well..ok.", "Ok, human.", "I did not expect that." };
                if (FindMatchingString.findMatchingString(result.Query, matching_words))
                {
                    listAns = new string[]
                    {
                        "Let yourself experience how nothing feels.", "Often under nothingness is great depth",
                        "I invite you to rest in nothingness"
                    };
                }
                Random random = new Random();
                int    rand   = random.Next(0, listAns.Length);
                ans = listAns[rand];
                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
                await context.PostAsync(ans);

                context.Wait(MessageReceived);
            }
        }
コード例 #24
0
        public async Task Movies(IDialogContext context, LuisResult result)
        {
            QureyController qc        = new QureyController();
            string          ans       = "";
            bool            savedData = false;

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");

            if (result.TopScoringIntent.Score < 0.4)
            {
                ans       = qc.GetTrainedAnswer(result.Query);
                savedData = true;
            }

            if (ans == "" || ans == "Hmmm ...")
            {
                ans       = qc.GetAnswer(result.Query, "Movies", result.TopScoringIntent.Score.ToString(), "0");
                savedData = true;
            }

            if (ans == "")
            {
                var options      = new MovieChoice[] { MovieChoice.PopularMovie, MovieChoice.SearchMovie };
                var descriptions = new string[] { "List Popular Movies", "Search for movie" };
                PromptDialog.Choice <MovieChoice>(context, ResumeAfterMovieChoiceSelection,
                                                  options, "What would you like to choose about movies?", descriptions: descriptions);
            }

            if (savedData)
            {
                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
                savedData = false;
                await context.PostAsync(ans);

                context.Wait(MessageReceived);
            }
        }
コード例 #25
0
        public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var message = await result;

            string entity = "";

            if (message.Text.Length > 0)
            {
                entity = message.Text;
            }

            await context.PostAsync("Here are results i found : ");

            try
            {
                BingSearch bingSearch = new BingSearch();

                bingSearch = BingSearchData.getSearchResult(entity);

                if (bingSearch != null)
                {
                    CardUtil.showBingWikiHeroCard((IMessageActivity)context.Activity, bingSearch);
                    QureyController qc = new QureyController();
                    qc.PostAnswerOne(bingSearch.entities.readLink, "BingSearch");
                }
                else
                {
                    await context.PostAsync($"I couldn't find what you asked, you can always try again..");
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Error when filtering by genre: {e}");
            }

            context.Done <object>(null);
        }
コード例 #26
0
        public async Task Yes(IDialogContext context, LuisResult result)
        {
            QureyController qc  = new QureyController();
            string          ans = "";

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");

            if (result.TopScoringIntent.Score < 0.3)
            {
                ans = qc.GetTrainedAnswer(result.Query);
                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
                await context.PostAsync(ans);

                context.Wait(MessageReceived);
            }
            else
            {
                string[] matching_words = { "everything" };
                string[] listAns        =
                { "Yes is what i like to hear.", "That's the spirit.", "Yes is always the right answer." };

                if (FindMatchingString.findMatchingString(result.Query, matching_words))
                {
                    listAns = new string[] { "We should talk more often", "Ohh.. ok." };
                }

                Random random = new Random();
                int    rand   = random.Next(0, listAns.Length);
                ans = listAns[rand];

                await context.PostAsync(ans);

                context.Wait(MessageReceived);
                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
            }
        }
コード例 #27
0
        public async Task Game(IDialogContext context, LuisResult result)
        {
            QureyController qc = new QureyController();

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");

            if (result.TopScoringIntent.Score < 0.4)
            {
                string ans = "";
                ans = qc.GetTrainedAnswer(result.Query);

                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
                await context.PostAsync(ans);

                context.Wait(MessageReceived);
            }
            else
            {
                await context.PostAsync(
                    "To play a game, answer question using numbers (1/2). To quit or exit game, just type 'stop' ");

                context.Call(new GameDialog(), this.ResumeGameAfterOptionDialog);
            }
        }
コード例 #28
0
        public async Task Greetigns(IDialogContext context, IAwaitable <IMessageActivity> message, LuisResult result)
        {
            QureyController qc = new QureyController();

            if (result.TopScoringIntent.Score < 0.4)
            {
                string ans = "";
                ans = qc.GetTrainedAnswer(result.Query);

                qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");
                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);


                await context.PostAsync(ans);

                context.Wait(MessageReceived);
            }
            else
            {
                string[] listAns1 =
                { "Well hello there, how are you today?", "Hello, how are you?", "Hellloooo... What's up?" };
                string[] listAns2 =
                { "I'm relaxing, what about you?", "Nothing much, what about you?", "Just chillin... :) " };
                string[] listAns3 =
                {
                    "I'm fine thank you, what about you?", "I'm doing great", "Great, what about you?",
                    "Fine, what about you :)"
                };
                string   ans             = "";
                Random   rand            = new Random();
                bool     found           = false;
                string[] matching_words1 = { "hello", "yo", "hi", "helo", "Greetings" };
                string[] matching_words2 = { "what", "doing" };
                string[] matching_words3 = { "how" };
                if (FindMatchingString.findMatchingString(result.Query, matching_words1))
                {
                    ans   = listAns1[rand.Next(0, listAns1.Length)];
                    found = true;
                }
                else if (FindMatchingString.findMatchingString(result.Query, matching_words2))
                {
                    ans   = listAns2[rand.Next(0, listAns2.Length)];
                    found = true;
                }
                else if (FindMatchingString.findMatchingString(result.Query, matching_words3))
                {
                    ans   = listAns3[rand.Next(0, listAns3.Length)];
                    found = true;
                }
                else
                {
                    ans = qc.GetTrainedAnswer(result.Query);
                    if (ans.Length > 0)
                    {
                        found = true;
                    }
                }
                if (!found)
                {
                    ans = "Greetins to you :)";
                }
                qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");
                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
                await context.PostAsync(ans);

                context.Wait(MessageReceived);
            }
        }