protected async Task <string> sendNotificationEnlishVoca(List <int> listIdWord, string messID) { //ChatfuelJson jsonMessenger = new ChatfuelJson(); //MessJson messExplaintion = new MessJson(); //MessJson messPron = new MessJson(); //MessJson messVietnamese = new MessJson(); //AttachmentJson sound = new AttachmentJson(); // jsonMessenger.recipient.id = messID; // bool isCheck = false; foreach (var idWord in listIdWord) { isCheck = true; JsonMessengerText jsonTextMessenger = new JsonMessengerText(); MessJson messExplaintion = new MessJson(); jsonTextMessenger.recipient.id = messID; JsonMessengerText jsonSoundMessenger = new JsonMessengerText(); jsonSoundMessenger.recipient.id = messID; AttachmentJson sound = new AttachmentJson(); var tempWord = _dictCache.GetById(idWord); var infoVoca = _dictCache.findWordCache(tempWord.VocaID); messExplaintion.text = infoVoca.VocaID; messExplaintion.text += "\r\n" + infoVoca.Pron; messExplaintion.text += "\r\n" + infoVoca.MeanEn; messExplaintion.text += "\r\n" + infoVoca.MeanVi; sound.attachment.payload.url = infoVoca.SoundUrl; // jsonTextMessenger.message = messExplaintion; jsonSoundMessenger.message = sound; // string temp = JsonConvert.SerializeObject(jsonTextMessenger); temp = JsonConvert.SerializeObject(jsonSoundMessenger); PostRaw("", JsonConvert.SerializeObject(jsonTextMessenger)); PostRaw("", JsonConvert.SerializeObject(jsonSoundMessenger)); } if (isCheck) { FBPostNoti newNoti = new FBPostNoti(); newNoti.recipient.id = messID; newNoti.message.attachment.payload.text = "Luyện tập nào !"; NotiButton button = new NotiButton(); button.title = "Start"; button.payload = "LUYENTAP"; newNoti.message.attachment.payload.buttons.Add(button); PostRaw("", JsonConvert.SerializeObject(newNoti)); } //HttpClient client = new HttpClient(); //client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); //if (isCheck) // await client.PostAsync("https://api.chatfuel.com/bots/59a43f64e4b03a25b73c0ebd/users/" + messID + "/" + "send?chatfuel_token=vnbqX6cpvXUXFcOKr5RHJ7psSpHDRzO1hXBY8dkvn50ZkZyWML3YdtoCnKH7FSjC&chatfuel_block_id=5a3fc60de4b037186c58ec99", null); return(""); }
public async System.Threading.Tasks.Task <PartialViewResult> Post(PostViewModel data) { Post newPost = new Post(); newPost.Post_Status = 0; _viewModel = new PostViewModel(); FieldHelper.CopyNotNullValue(newPost, data); newPost.CreatedDate = DateTime.Now; if (data.Option == 0 && newPost.Id_Type == 8) { //post to fb toiec var IdPost = await _fbService.PostingToGroupFB(newPost.Content); newPost.Id_PostFB = IdPost.id; } _postService.Add(newPost); _postService.Save(); // string url = MaHoaMD5.Encrypt(newPost.Id + "#" + newPost.UpdatedDate); //Send notify ApplicationUser userPost = _service.GetUserById(newPost.Id_User); FieldHelper.CopyNotNullValue(PostViewModel, userPost); FieldHelper.CopyNotNullValue(PostViewModel, newPost); PostViewModel.TypeToString = _postTypeService.GetById(newPost.Id_Type).Name; PostVoteDetail vote = _postVoteDetailService.getVoteByIdUser(newPost.Id_User, newPost.Id); if (vote != null) { PostViewModel.Vote = vote.Vote; } //Send noti for all user register var userIDList = getUserIDListBasedOnType(newPost.Id_Type); foreach (var userID in userIDList) { var sendPostToUser = _service.GetUserById(userID); if (sendPostToUser.Id_Messenger != userPost.Id_Messenger && sendPostToUser.Id_Messenger != null && _eventService.IsFreeTime(sendPostToUser.Email)) { //Create json send............ FBPostNoti newNoti = new FBPostNoti(); newNoti.recipient.id = sendPostToUser.Id_Messenger; newNoti.message.attachment.payload.text = "```\r\n" + "💬 Bạn có một câu hỏi: " + "\r\n" + '"' + newPost.Content + '"' + "\r\n```"; NotiButton button = new NotiButton(); button.payload = "REPLAY_" + newPost.Id; newNoti.message.attachment.payload.buttons.Add(button); // ChatBotMessenger.sendRequest(JsonConvert.SerializeObject(newNoti)); } } return(PartialView("_Post", PostViewModel)); }
public async Task <string> createNewPostViaFB(string messID, string containQues, int typeQues) { //Determine user var userMakeQues = _service.listUserID().Where(x => x.Id_Messenger == messID).ToList(); if (userMakeQues.Count != 0) { Post newPost = new Model.Post(); newPost.Content = containQues; newPost.DatePost = DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds.ToString(); newPost.Id_User = userMakeQues.FirstOrDefault().Id; newPost.Id_Type = typeQues; // TOIEC //Post to fb group if (newPost.Id_Type == 8) { try { //post to fb toiec var IdPost = await _fbService.PostingToGroupFB(newPost.Content); newPost.Id_PostFB = IdPost.id; } catch (Exception e) { } } _postService.Add(newPost); _postService.Save(); //Send noti for all user register var userIDList = getUserIDListBasedOnType(typeQues); foreach (var userID in userIDList) { var sendToUser = _service.GetUserById(userID); if (sendToUser.Id_Messenger != messID && sendToUser.Id_Messenger != null && _eventService.IsFreeTime(sendToUser.Email)) { //Create json send............ FBPostNoti newNoti = new FBPostNoti(); newNoti.recipient.id = sendToUser.Id_Messenger; newNoti.message.attachment.payload.text = "```\r\n" + "💬 Bạn có một câu hỏi: " + "\r\n" + '"' + newPost.Content + '"' + "\r\n```"; NotiButton button = new NotiButton(); button.payload = "REPLAY_" + newPost.Id; newNoti.message.attachment.payload.buttons.Add(button); // ChatBotMessenger.sendRequest(JsonConvert.SerializeObject(newNoti)); } } } return(""); }