public PartialViewResult Comment(CommentViewModel data) { _viewModel = new CommentViewModel(); Comment comment = new Comment(); FieldHelper.CopyNotNullValue(comment, data); _commentOfPost.Add(comment); _commentOfPost.Save(); //Determine user of post, send noti via mess bot var currentPost = _postService.GetById(comment.Id_Post); var userOfPost = _service.GetUserById(currentPost.Id_User); var userOfComment = _service.GetUserById(comment.Id_User); if (userOfComment.Id_Messenger != userOfPost.Id_Messenger) { ChatBotMessenger.sendTextMeg(userOfPost.Id_Messenger, "🔥 *Câu hỏi:* " + currentPost.Content + "\r\n" + "✎ *Đáp án:* " + comment.Content); } // FieldHelper.CopyNotNullValue(CommentViewModel, comment); if (data.Id_Comment == 0) { return(PartialView("_Comment", CommentViewModel)); } else { return(PartialView("_ChildComment", CommentViewModel)); } }
public async Task <PartialViewResult> Comment(CommentViewModel data, bool IsFromBot = false) { _viewModel = new CommentViewModel(); Comment comment = new Comment(); FieldHelper.CopyNotNullValue(comment, data); comment.Corrected = false; // comment.CreatedBy = comment.DateComment = DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds.ToString(); _commentOfPost.Add(comment); _commentOfPost.Save(); Post post = _postService.GetById(comment.Id_Post); post.Comment++; _postService.Update(post); _postService.Save(); ApplicationUser user = _service.GetUserById(comment.Id_User); FieldHelper.CopyNotNullValue(CommentViewModel, user); FieldHelper.CopyNotNullValue(CommentViewModel, comment); CommentViewModel.Id_UserPost = post.Id_User; if (data.Id_Comment == 0) { if (CommentViewModel.Id_UserPost != User.Identity.GetUserId()) { Notification notification = new Notification(); notification.Id_User = data.Id_User; notification.Id_Friend = CommentViewModel.Id_UserPost; notification.Id_Post = data.Id_Post; notification.Id_Comment = comment.Id; notification.DateComment = data.DateComment; var userOfPost = _service.GetUserById(post.Id_User); //Send noti to chrome // _notificationService.Add(notification); _notificationService.Save(); //Send noti via chatbot ChatBotMessenger.sendTextMeg(userOfPost.Id_Messenger, "🔥 *Câu hỏi:* " + post.Content + "\r\n" + "✎ *Đáp án:* " + comment.Content); //Send noti for chrome ChromeNotiJson postJson = new ChromeNotiJson(); postJson.title = "Bạn có câu trả lời: "; postJson.text = post.Content + "<br/>" + comment.Content; postJson.urlQuestion = "http://olympusenglish.azurewebsites.net/Post?id=" + post.Id; if (IsFromBot) { ChromeNotification.sendNoti(userOfPost.Email, post.Id, comment.Id); } await NotificationHub.sendNoti(userOfPost.Email, JsonConvert.SerializeObject(postJson)); } return(PartialView("_Comment", CommentViewModel)); } else { return(PartialView("_ChildComment", CommentViewModel)); } }
public void registerChatBot(string idUser, string idmessenger) { var user = _applicationUserService.GetUserById(idUser); if (user == null) { ChatBotMessenger.sendTextMeg(idmessenger, "ID không tồn tại vui lòng kiểm tra lại"); return; } user.Id_Messenger = idmessenger; _applicationUserService.Update(user); _applicationUserService.Save(); ChatBotMessenger.sendTextMeg(idmessenger, "Chúc mừng bạn đã liên kết thành công"); return; }
public async Task CheckAnswerOnFB() { //Lay danh sách cac bài post chưa có câu trả lời // var listPost = _postService.GetAll().Where(x => x.Id_PostFB != null && x.Post_Status == 0); var listPost = _postService.checkPostOnGroup(); foreach (var post in listPost) { var dapAn = await _fbService.DetectedAnswOfPost(post.Id_PostFB); if (dapAn != "") { post.Post_Status = 10; Comment comment = new Comment(); comment.Corrected = false; comment.Content = dapAn; //Admin comment.Id_User = post.Id_User; comment.Id_Post = post.Id; comment.DateComment = DateTime.Now.Ticks.ToString(); _commentOfPost.Add(comment); _commentOfPost.Save(); _postService.Update(post); _postService.Save(); //Send noti via chatbot var userOfPost = _service.GetUserById(post.Id_User); // var userOfCmt = _service.GetUserById(comment.Id_User); ChatBotMessenger.sendTextMeg(userOfPost.Id_Messenger, "🔥 *Câu hỏi:* " + post.Content + "\r\n" + "✎ *Đáp án:* " + comment.Content); //Send noti for chrome ChromeNotiJson postJson = new ChromeNotiJson(); postJson.title = "Bạn có câu trả lời: "; postJson.text = post.Content + "<br/>" + comment.Content; postJson.urlQuestion = "http://olympusenglish.azurewebsites.net/Post?id=" + post.Id; //if (IsFromBot) { ChromeNotification.sendNoti(userOfPost.Email, post.Id, comment.Id); } await NotificationHub.sendNoti(userOfPost.Email, JsonConvert.SerializeObject(postJson)); } } }
public async Task <ActionResult> ReceivePost(BotRequest data) { try { //If fast replay if (data.entry[0].messaging[0].message.quick_reply != null) { var ctrlr = DependencyResolver.Current.GetService <LearningController>(); ctrlr.ControllerContext = new ControllerContext(this.Request.RequestContext, ctrlr); ctrlr.ReceivePost(data); //Update again ItemMessenger previousMess = new ItemMessenger(); previousMess.Id_Messenger = data.entry[0].messaging[0].sender.id; UpdatePreviousMsg(previousMess); return(null); } } catch { } // ItemMessenger previousMsg = getPreviousMsg(data.entry[0].messaging[0].sender.id); if (previousMsg != null) { //Tn trước đó có chứa payload => đang trời cho 1 câu hỏi gì đó if (previousMsg.IsPayload == true) { //Menu payload xac thuc if (previousMsg.PayLoad == "XACTHUC") { var ctrlrDict = DependencyResolver.Current.GetService <AccountController>(); ctrlrDict.ControllerContext = new ControllerContext(this.Request.RequestContext, ctrlrDict); ctrlrDict.registerChatBot(data.entry[0].messaging[0].message.text, data.entry[0].messaging[0].sender.id); } else if (previousMsg.PayLoad == "LUYENTAP") { } else if (previousMsg.PayLoad.IndexOf(@"POST_TYPE_") != -1) { var postType = int.Parse(previousMsg.PayLoad.Substring(10)); ChatBotMessenger.sendTextMeg(data.entry[0].messaging[0].sender.id, "🎉 Câu hỏi bạn đã được gửi đi 🎉 "); var ctrlrDict = DependencyResolver.Current.GetService <PostController>(); ctrlrDict.ControllerContext = new ControllerContext(this.Request.RequestContext, ctrlrDict); await ctrlrDict.createNewPostViaFB(data.entry[0].messaging[0].sender.id, data.entry[0].messaging[0].message.text, postType); } else if (previousMsg.PayLoad.IndexOf(@"REPLAY_") != -1) { ChatBotMessenger.sendTextMeg(data.entry[0].messaging[0].sender.id, "🎉 Thank you 🎉 "); // var postID = int.Parse(previousMsg.PayLoad.Substring(7)); // ApplicationUser currentUser = _service.GetUserByMessID(data.entry[0].messaging[0].sender.id); // CommentViewModel dataCmt = new CommentViewModel(); dataCmt.Id_User = currentUser.Id; dataCmt.Id_Comment = 0; dataCmt.Id_Post = postID; dataCmt.Name = data.entry[0].messaging[0].message.text; dataCmt.Content = data.entry[0].messaging[0].message.text; var ctrlrDict = DependencyResolver.Current.GetService <PostController>(); ctrlrDict.ControllerContext = new ControllerContext(this.Request.RequestContext, ctrlrDict); ctrlrDict.Comment(dataCmt, true); } //Update again ItemMessenger previousMess = new ItemMessenger(); previousMess.Id_Messenger = data.entry[0].messaging[0].sender.id; UpdatePreviousMsg(previousMess); return(null); } } string imageToText = ""; try { if (data.entry[0].messaging[0].postback != null && data.entry[0].messaging[0].message == null) { ItemMessenger previousMess = new ItemMessenger(); previousMess.PayLoad = data.entry[0].messaging[0].postback.payload; previousMess.Id_Messenger = data.entry[0].messaging[0].sender.id; previousMess.Previous_Msg = data.entry[0].messaging[0].postback.title; previousMess.Status = 1; previousMess.IsPayload = true; UpdatePreviousMsg(previousMess); //xac thu token if (data.entry[0].messaging[0].postback.payload.ToString() == "XACTHUC") { ChatBotMessenger.sendTextMeg(data.entry[0].messaging[0].sender.id, "🔑 Vui lòng nhập mã token sau tin nhắn này 🔑"); //var ctrlrDict = DependencyResolver.Current.GetService<AccountController>(); //ctrlrDict.ControllerContext = new ControllerContext(this.Request.RequestContext, ctrlrDict); // await ctrlrDict.registerChatBot(data.entry[0].messaging[0].message.text, data.entry[0].messaging[0].sender.id, ""); } else if (data.entry[0].messaging[0].postback.payload.ToString() == "LUYENTAP") { var ctrlrDict = DependencyResolver.Current.GetService <LearningController>(); ctrlrDict.ControllerContext = new ControllerContext(this.Request.RequestContext, ctrlrDict); await ctrlrDict.multiplechoiceOnline(data.entry[0].messaging[0].sender.id); } else if (data.entry[0].messaging[0].postback.payload.ToString().IndexOf(@"POST_TYPE_") != -1) { ChatBotMessenger.sendTextMeg(data.entry[0].messaging[0].sender.id, "❓ Mời bạn nhập câu hỏi ❓"); } else if (data.entry[0].messaging[0].postback.payload.ToString().IndexOf(@"REPLAY_") != -1) { ChatBotMessenger.sendTextMeg(data.entry[0].messaging[0].sender.id, "✍️ Mời bạn nhập câu trả lời ✍️"); } return(null); } //Tra tu dien if (data.entry[0].messaging[0].message.attachments != null && data.entry[0].messaging[0].postback == null) { ItemMessenger previousMess = new ItemMessenger(); previousMess.Id_Messenger = data.entry[0].messaging[0].sender.id; UpdatePreviousMsg(previousMess); // imageToText = data.entry[0].messaging[0].message.attachments[0].payload.url; string textResult = await ConvertImageURLToBase64(data.entry[0].messaging[0].message.attachments[0].payload.url); var ctrlrDict = DependencyResolver.Current.GetService <DictionaryController>(); ctrlrDict.ControllerContext = new ControllerContext(this.Request.RequestContext, ctrlrDict); await ctrlrDict.searchDictViaBot(textResult, data.entry[0].messaging[0].sender.id, ""); return(null); } if (data.entry[0].messaging[0].message.text != "" && data.entry[0].messaging[0].message.quick_reply == null && data.entry[0].messaging[0].postback == null) { ItemMessenger previousMess = new ItemMessenger(); previousMess.Id_Messenger = data.entry[0].messaging[0].sender.id; UpdatePreviousMsg(previousMess); // var ctrlrDict = DependencyResolver.Current.GetService <DictionaryController>(); ctrlrDict.ControllerContext = new ControllerContext(this.Request.RequestContext, ctrlrDict); await ctrlrDict.searchDictViaBot(data.entry[0].messaging[0].message.text, data.entry[0].messaging[0].sender.id, ""); return(null); } } catch { } return(new HttpStatusCodeResult(HttpStatusCode.OK)); }