public void Can_load_settings()
 {
     var path = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\"));
     path = Path.Combine(path, Path.Combine("config", "Settings.xml"));
     var doctorSharp = new DoctorSharp(path);
     Assert.DoesNotThrow(() => doctorSharp.Ask("unit test", "Are you green?"));
 }
        public void Ask_returns_answer()
        {
            var path = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\"));
            path = Path.Combine(path, Path.Combine("config", "Settings.xml"));
            var doctorSharp = new DoctorSharp(path);
            const string expectedAnswer = "I am transparent--software has no color.";

            var answer = doctorSharp.Ask("unit test", "Are you green?");

            Assert.AreEqual(expectedAnswer, answer);
        }
 public QuestionViewModel(TwitterStatus twitterStatus)
 {
     Channel = MessageChannel.Twitter;
     To = "";
     From = twitterStatus.User != null ? twitterStatus.User.Name : "LS#er";
     Content = twitterStatus.Text;
     Msg_Id = twitterStatus.Id;
     DateAsked = twitterStatus.CreatedDate.ToShortDateString();
     Keyword = "";
     if (!string.IsNullOrEmpty(Content))
     {
         var aimlPath = HttpContext.Current.Server.MapPath("~/aiml/");
         var chatbot = new DoctorSharp(aimlPath);
         var answer = chatbot.Ask(From, Content);
         Answer = answer;
     }
     else
     {
         Answer = "There was no question.";
     }
 }
示例#4
0
        public AskModule(IDocumentSession documentSession, IHubContext hubContext)
        {
            Get["/ask"] = _ =>
            {
                try
                {
                    // RavenDb
                    var storedQuestions = documentSession.Query<Question>().OrderByDescending(x => x.DateAsked).ToList();

                    // Twitter
                    var twitterService = new TwitterService(TwitterConsumerKey, TwitterConsumerSecret);
                    twitterService.AuthenticateWith(TwitterAccessToken, TwitterAccessTokenSecret);

                    var twitterOptions = new ListTweetsMentioningMeOptions();
                    if (storedQuestions.Any())
                    {
                        var sinceId = storedQuestions.First().MessageId;
                        twitterOptions.SinceId = sinceId;
                    }

                    var tweets = twitterService.ListTweetsMentioningMe(twitterOptions).ToList();
                    if (!tweets.Any()) return null;

                    var nextQuestion = tweets.First(t => !string.IsNullOrEmpty(t.Text) && t.Text.Contains("#drsharp"));

                    //var model = this.Bind<AskViewModel>();

                    var pathToAiml = System.Web.HttpContext.Current.Server.MapPath(@"~/aiml");
                    var drSharp = new DoctorSharp(pathToAiml);
                    var answer = drSharp.Ask(nextQuestion.Author.ScreenName, nextQuestion.Text);

                    // Note: tweet working, but not in reply to sender. Also need to add some hashtag to the answer.
                    //twitterService.SendTweet(new SendTweetOptions
                    //{
                    //    DisplayCoordinates = false,
                    //    InReplyToStatusId = nextQuestion.Id,
                    //    Status = answer
                    //});

                    var question = new Question
                    {
                        From = nextQuestion.Author.ScreenName,
                        DateAsked = nextQuestion.CreatedDate,
                        Content = nextQuestion.Text,
                        MessageId = nextQuestion.Id,
                        Answer = answer
                    };

                    documentSession.Store(question);
                    documentSession.SaveChanges();

                    // SignalR
                    hubContext.Clients.All.broadcastAnswer(question.Content, question.Answer, question.From);
                    return null;
                }
                catch (Exception ex)
                {
                    return string.Format("Message: {0}\r\nDetail {1}", ex.Message, ex.StackTrace);
                }

            };
        }