コード例 #1
0
        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));
        }
コード例 #2
0
        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("");
        }
コード例 #3
0
        public void initChatBotMenu()
        {
            ChatbotMenu menu = new ChatbotMenu();
            //
            PersistentMenu infoMenu = new PersistentMenu();

            //
            infoMenu.locale          = "default";
            infoMenu.call_to_actions = new List <CallToAction>();
            //\
            CallToAction parentMenu3 = new CallToAction();

            parentMenu3.title           = "🔍 Đặt câu hỏi nhanh ";
            parentMenu3.type            = "nested";
            parentMenu3.call_to_actions = new List <CallToAction2>();
            //Child menu
            foreach (var typeObj in _postTypeService.GetAll())
            {
                CallToAction2 childMenu = new CallToAction2();
                childMenu.payload = "POST_TYPE_" + typeObj.Id;
                childMenu.title   = "🚩." + typeObj.Name;
                childMenu.type    = "postback";
                parentMenu3.call_to_actions.Add(childMenu);
            }
            infoMenu.call_to_actions.Add(parentMenu3);
            //
            CallToAction parentMenu = new CallToAction();

            parentMenu.title   = "🎓 Xác thực token với Olympus";
            parentMenu.type    = "postback";
            parentMenu.payload = "XACTHUC";
            infoMenu.call_to_actions.Add(parentMenu);
            //
            CallToAction parentMenu2 = new CallToAction();

            parentMenu2.title   = "💡 Luyện tập";
            parentMenu2.type    = "postback";
            parentMenu2.payload = "LUYENTAP";
            infoMenu.call_to_actions.Add(parentMenu2);
            //

            menu.persistent_menu.Add(infoMenu);
            ChatBotMessenger.sendRequest(JsonConvert.SerializeObject(menu, Newtonsoft.Json.Formatting.None,
                                                                     new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            }), true);
        }