public QuestionViewModel(Question question) { To = question.ToPhoneNumber; From = question.From; Content = question.Content; Msg_Id = question.MessageId; DateAsked = question.DateAsked.ToString("g"); Keyword = question.Keyword; Answer = question.Answer; }
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); } }; }