Example #1
0
        public async Task <string> ToeicQues(string content, string idmessenger)
        {
            ChatfuelJson result       = new ChatfuelJson();
            MessJson     messPron     = new MessJson();
            MessJson     messPron2    = new MessJson();
            var          userMakeQues = _service.listUserID().Where(x => x.Id_Messenger == idmessenger).ToList();

            if (userMakeQues.Count != 0)
            {
                Post newPost = new Model.Post();
                newPost.Content  = content;
                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  = 8; // TOIEC
                //Send lên nhóm fb

                {
                    //post to fb toiec
                    //Gửi cho admin trước khi dc duyệt

                    //
                    //var IdPost = await _fbService.PostingToGroupFB(newPost.Content);
                    //  newPost.Id_PostFB = IdPost.id;
                }
                _postService.Add(newPost);
                _postService.Save();
                await NotifyForAdminToApprove(newPost.Id);

                //Send notify
                List <ApplicationUser> userSubQues = getNormalUserBasedOnType(newPost);
                foreach (var itemUser in userSubQues)
                {
                    await sendNofityToMessenger(newPost, itemUser);

                    HaveSendQuestion haveSendQues = new HaveSendQuestion();
                    haveSendQues.QuesID    = newPost.Id;
                    haveSendQues.UserID    = itemUser.Id;
                    haveSendQues.Status    = false;
                    haveSendQues.Protected = false;
                    _haveSendQuesService.Add(haveSendQues);
                    _haveSendQuesService.Save();
                }
                messPron.text = "Câu hỏi của bạn đã được gửi đi cho mọi người !";
                result.messages.Add(messPron);
                // messPron2.text = "https://www.facebook.com/" + newPost.Id_PostFB;
                //result.messages.Add(messPron2);
                return(JsonConvert.SerializeObject(result));
            }
            else
            {
                messPron.text = "Hình như bạn chưa có tài khoản trên Olympus English";
                result.messages.Add(messPron);
                return(JsonConvert.SerializeObject(result));
            }
        }
Example #2
0
        public async Task <string> replayDirectly(string idques, string ketqua, string idmessenger)
        {
            //
            ChatfuelJson result   = new ChatfuelJson();
            MessJson     messPron = new MessJson();
            //
            bool checkGio    = false;
            int  idQuestion  = int.Parse(idques);
            var  currentPost = _postService.GetById(idQuestion);
            var  userId      = _service.listUserID().Where(x => x.Id_Messenger == idmessenger).FirstOrDefault().Id;
            //Kiem tra xem con thoi gian tra loi hay ko
            var sendQues = _haveSendQuesService.GetAll().Where(x => x.QuesID == idQuestion && x.UserID == userId).ToList().FirstOrDefault();

            if (sendQues != null)
            {
                int tempMinute  = TimeSetting.LimitMinuteForPost();
                var timePost    = sendQues.CreatedDate.Value.AddMinutes(tempMinute).Ticks;
                var timeCurrent = DateTime.Now.AddMinutes(-5).Ticks;
                if (timePost < timeCurrent)
                {
                    checkGio = true;
                }
                else
                {
                    currentPost.Post_Status = 10;
                    Comment comment = new Comment();
                    comment.Corrected   = false;
                    comment.Content     = ketqua;
                    comment.Id_User     = userId;
                    comment.Id_Post     = idQuestion;
                    comment.DateComment = DateTime.Now.Ticks.ToString();
                    _commentOfPost.Add(comment);
                    _commentOfPost.Save();
                    _postService.Update(currentPost);
                    _postService.Save();
                    messPron.text = "Cám ơn bạn đã phản hồi";
                    result.messages.Add(messPron);
                    await notifyForUserAboutQues(idQuestion);

                    return(JsonConvert.SerializeObject(result));
                }
            }
            //
            //  currentPost.Post_Status = 1;
            // _postService.Update(currentPost);
            //_postService.Save();
            // DateTime
            messPron.text = "Hết hạn trả lời, cảm ơn bạn đã quan tâm";
            result.messages.Add(messPron);
            return(JsonConvert.SerializeObject(result));
        }
Example #3
0
        public async Task <string> ApprovedQuestion(string idques)
        {
            ChatfuelJson result   = new ChatfuelJson();
            MessJson     messPron = new MessJson();

            result.messages.Add(messPron);

            var currentPost = _postService.GetById(int.Parse(idques));
            var IdPost      = await _fbService.PostingToGroupFB(currentPost.Content);

            currentPost.Id_PostFB = IdPost.id;
            _postService.Update(currentPost);
            _postService.Save();
            //Notify for user, this question is approved by admin
            await NotifyForUser(currentPost.Id);

            //
            messPron.text = "Thành công";
            return(JsonConvert.SerializeObject(result));
        }
Example #4
0
        //make question directly from Messenger
        public async Task <string> IeltsQues(string content, string messengerid)
        {
            ChatfuelJson result   = new ChatfuelJson();
            MessJson     messPron = new MessJson();

            var userMakeQues = _service.listUserID().Where(x => x.Id_Messenger == messengerid).ToList();

            if (userMakeQues.Count != 0)
            {
                Post newPost = new Model.Post();
                newPost.Content  = content;
                newPost.DatePost = DateTime.Now.Ticks.ToString();
                newPost.Id_User  = userMakeQues.FirstOrDefault().Id;
                newPost.Id_Type  = 9; // TOIEC
                _postService.Add(newPost);
                _postService.Save();
                //Send notify
                List <ApplicationUser> userSubQues = getNormalUserBasedOnType(newPost);
                foreach (var itemUser in userSubQues)
                {
                    await sendNofityToMessenger(newPost, itemUser);

                    HaveSendQuestion haveSendQues = new HaveSendQuestion();
                    haveSendQues.QuesID    = newPost.Id;
                    haveSendQues.UserID    = itemUser.Id;
                    haveSendQues.Status    = false;
                    haveSendQues.Protected = false;
                    _haveSendQuesService.Add(haveSendQues);
                    _haveSendQuesService.Save();
                }
                messPron.text = "Câu hỏi của bạn đã được gửi đi cho mọi người";
                result.messages.Add(messPron);
                return(JsonConvert.SerializeObject(result));
            }
            else
            {
                messPron.text = "Hình như bạn chưa có tài khoản trên Olympus English";
                result.messages.Add(messPron);
                return(JsonConvert.SerializeObject(result));
            }
        }
Example #5
0
        public string busyNotReplay(string idques, string idmessenger)
        {
            ChatfuelJson result   = new ChatfuelJson();
            MessJson     messPron = new MessJson();

            //
            bool isHetGio    = false;
            int  idQuestion  = int.Parse(idques);
            var  currentPost = _postService.GetById(idQuestion);
            var  userId      = _service.listUserID().Where(x => x.Id_Messenger == idmessenger).FirstOrDefault().Id;
            //Kiem tra xem con thoi gian tra loi hay ko
            var sendQues = _haveSendQuesService.GetAll().Where(x => x.QuesID == idQuestion && x.UserID == userId).ToList().FirstOrDefault();

            if (sendQues != null && currentPost.Post_Status != 10)
            {
                var timePost    = sendQues.CreatedDate.Value.AddMinutes(TimeSetting.LimitMinuteForPost()).Ticks;
                var timeCurrent = DateTime.Now.Ticks;
                if (timePost < timeCurrent)
                {
                    isHetGio = true;
                }
            }
            else
            {
                messPron.text = "Câu hỏi không tồn tại hoặc đã trả lời";
                result.messages.Add(messPron);
                return(JsonConvert.SerializeObject(result));
            }
            if (!isHetGio)
            {
                messPron.text           = "Bạn đã bỏ qua câu hỏi số :" + idques;
                currentPost.CreatedDate = DateTime.Now.AddMinutes(-TimeSetting.LimitMinuteForPost());
                _postService.Update(currentPost);
                _postService.Save();
                result.messages.Add(messPron);
                return(JsonConvert.SerializeObject(result));
            }
            messPron.text = "Hết giờ hoặc đã trả lời";
            result.messages.Add(messPron);
            return(JsonConvert.SerializeObject(result));
        }
Example #6
0
        public async Task <string> searchDictViaBot(string contain, string id = "1554844547918927", string userid = null)
        {
            bool multiLetters = false;

            contain = contain.ToString().ToLower().Trim();
            //Tim trong cache nếu ko có thì request crawler
            var dictTemp = _dictCache.findWordCache(contain);
            //post
            //
            bool        isSaveCached     = true;
            DictCache   cacheDict        = new DictCache();
            OxfordDict  dict             = new OxfordDict();
            GoogleTrans googleTransJson  = new GoogleTrans();
            GoogleTrans detailVietnamese = new GoogleTrans();
            //Explain main of letter
            MessJson messExplaintion = new MessJson();
            //Pron
            MessJson messPron = new MessJson();
            //Vietnamese
            MessJson messVietnamese = new MessJson();
            //
            ChatfuelJson   hello = new ChatfuelJson();
            AttachmentJson sound = new AttachmentJson();

            sound.attachment.type = "audio";
            Attachment2 attach = new Attachment2();
            //Json is returned Customer
            AttachmentJson soundDic            = new AttachmentJson();
            MessJson       messExplaintionDict = new MessJson();
            MessJson       resultGoogle        = new MessJson();
            //
            JsonMessengerText jsonTextMessenger = new JsonMessengerText();

            jsonTextMessenger.recipient.id = id;
            JsonMessengerText jsonSoundMessenger = new JsonMessengerText();

            jsonSoundMessenger.recipient.id = id;
            messExplaintionDict.text       += "*" + ToTitleCase(contain) + "*";

            Payload2 payload = new Payload2();

            //
            if (dictTemp != null)
            {
                messPron.text                = dictTemp.Pron;
                messExplaintion.text         = dictTemp.MeanEn;
                messVietnamese.text          = dictTemp.MeanVi;
                sound.attachment.payload.url = dictTemp.SoundUrl;
                //
                messExplaintionDict.text       += "\r\n" + dictTemp.Pron;
                messExplaintionDict.text       += "\r\n" + dictTemp.MeanEn;
                messExplaintionDict.text       += "\r\n" + dictTemp.MeanVi;
                soundDic.attachment.payload.url = dictTemp.SoundUrl;
            }
            else
            {
                int size = contain.Split(' ').Length;
                if (size > 1)
                {
                    multiLetters    = true;
                    googleTransJson = await _clientDictionaryService.startGoogleTrans(contain);

                    foreach (var sentence in googleTransJson.sentences)
                    {
                        messExplaintion.text += sentence.trans;
                        resultGoogle.text    += sentence.trans;
                    }

                    // resultGoogle.text = googleTransJson.sentences[0].trans;
                    //messExplaintionDict.text +="\r\n" + googleTransJson.sentences[0].trans;
                }
                else
                {
                    try
                    {
                        dict = await _clientDictionaryService.startCrawlerOxford(contain);

                        messPron.text        = dict.m_Pron;
                        messExplaintion.text = dict.m_Explanation.First().m_UseCase;
                        //
                        messExplaintionDict.text += "\r\n" + dict.m_Pron;
                        messExplaintionDict.text += "\r\n" + dict.m_Explanation.First().m_UseCase;
                    }
                    catch
                    {
                        isSaveCached              = false;
                        messExplaintion.text      = contain;
                        messExplaintionDict.text += "\r\n" + contain;
                    }
                    try
                    {
                        detailVietnamese = await _clientDictionaryService.startGoogleDetailTrans(contain);
                    }
                    catch
                    {
                        detailVietnamese = null;
                    }
                    try
                    {
                        messVietnamese.text = detailVietnamese.dict.First().pos + ": ";
                        foreach (var item in detailVietnamese.dict.First().terms)
                        {
                            messVietnamese.text += item + ", ";
                        }
                        messExplaintionDict.text += "\r\n" + messVietnamese.text;
                    }
                    catch
                    {
                        isSaveCached              = false;
                        messVietnamese.text       = detailVietnamese.sentences.FirstOrDefault().trans;
                        messExplaintionDict.text += "\r\n" + detailVietnamese.sentences.FirstOrDefault().trans;
                    }
                }
                sound.attachment.payload.url    = dict.m_SoundUrl;
                soundDic.attachment.payload.url = dict.m_SoundUrl;
                //Add database
                cacheDict          = new DictCache();
                cacheDict.VocaID   = contain;
                cacheDict.Pron     = messPron.text;
                cacheDict.MeanEn   = messExplaintion.text;
                cacheDict.MeanVi   = messVietnamese.text;
                cacheDict.SoundUrl = dict.m_SoundUrl;
                _dictCache.Add(cacheDict);
                if (isSaveCached)
                {
                    _dictCache.Save();
                }
                dictTemp = cacheDict;
            }
            //DetailOurWord detailWord = _detailOutWordService.findDetailOurWord(userid, dictTemp.Id);
            //if (detailWord == null)
            //{
            //    hello.Selected = false;
            //}
            //else
            //{
            //    hello.Selected = true;
            //}
            hello.messages.Add(messPron);
            hello.messages.Add(messVietnamese);
            hello.messages.Add(messExplaintion);
            hello.messages.Add(sound);
            try
            {
                hello.strVoca = ToTitleCase(contain);
                ApplicationUser currentUser = _service.listUserID().Where(x => x.Id_Messenger == id).FirstOrDefault();
                NotificationHub.sendNoti(currentUser.Email, JsonConvert.SerializeObject(hello));
            }
            catch
            {
            }

            if (multiLetters)
            {
                jsonTextMessenger.message  = messExplaintionDict;
                jsonSoundMessenger.message = resultGoogle;
                PostRaw("", JsonConvert.SerializeObject(jsonTextMessenger));
                PostRaw("", JsonConvert.SerializeObject(jsonSoundMessenger));
                return("");
            }

            jsonTextMessenger.message  = messExplaintionDict;
            jsonSoundMessenger.message = soundDic;
            PostRaw("", JsonConvert.SerializeObject(jsonTextMessenger));
            PostRaw("", JsonConvert.SerializeObject(jsonSoundMessenger));
            return(JsonConvert.SerializeObject(hello));
        }
Example #7
0
        public async Task <string> getDictToExtension(string contain)
        {
            bool   isVN   = false;
            string userid = User.Identity.GetUserId();

            contain = contain.ToString().ToLower().Trim();
            DictCache dictTemp = new DictCache();

            //Tim trong cache nếu ko có thì request crawler
            try
            {
                dictTemp = _dictCache.findWordCache(contain);
            }
            catch (Exception e)
            {
            }
            //post
            //
            bool        isSaveCached = true;
            DictCache   cacheDict;
            OxfordDict  dict             = new OxfordDict();
            GoogleTrans googleTransJson  = new GoogleTrans();
            GoogleTrans detailVietnamese = new GoogleTrans();
            //Explain main of letter
            MessJson messExplaintion = new MessJson();
            //Pron
            MessJson messPron = new MessJson();
            //Vietnamese
            MessJson messVietnamese = new MessJson();
            //
            ChatfuelJson   hello = new ChatfuelJson();
            AttachmentJson sound = new AttachmentJson();

            sound.attachment.type = "audio";
            Attachment2 attach = new Attachment2();

            if (contain.LastOrDefault() == '.')
            {
                messPron.text = "";
                hello.messages.Add(messPron);
                return(JsonConvert.SerializeObject(hello));
            }
            Payload2 payload = new Payload2();

            //
            if (dictTemp != null)
            {
                messPron.text                = dictTemp.Pron;
                messExplaintion.text         = dictTemp.MeanEn;
                messVietnamese.text          = dictTemp.MeanVi;
                sound.attachment.payload.url = dictTemp.SoundUrl;
            }
            else
            {
                int size = contain.Split(' ').Length;
                if (size > 1)
                {
                    isSaveCached    = false;
                    googleTransJson = await _clientDictionaryService.startGoogleTrans(contain);

                    hello.strVietnamese = googleTransJson.src;
                    if (googleTransJson.src == "vi")
                    {
                        isVN = true;
                    }
                    messExplaintion.text = googleTransJson.sentences[0].trans;
                }
                else
                {
                    try
                    {
                        dict = await _clientDictionaryService.startCrawlerOxford(contain);

                        messPron.text        = dict.m_Pron;
                        messExplaintion.text = dict.m_Explanation.First().m_UseCase;
                    }
                    catch
                    {
                        isSaveCached         = false;
                        messExplaintion.text = contain;
                    }
                    detailVietnamese = await _clientDictionaryService.startGoogleDetailTrans(contain);

                    hello.strVietnamese = detailVietnamese.src;
                    if (detailVietnamese.src == "vi")
                    {
                        isVN = true;
                    }
                    try
                    {
                        messVietnamese.text = detailVietnamese.dict.First().pos + ": ";
                        foreach (var item in detailVietnamese.dict.First().terms)
                        {
                            messVietnamese.text += item + ", ";
                        }
                    }
                    catch
                    {
                        isSaveCached        = false;
                        messVietnamese.text = detailVietnamese.sentences.FirstOrDefault().trans;
                    }
                }
                sound.attachment.payload.url = dict.m_SoundUrl;
                //Add database
                cacheDict          = new DictCache();
                cacheDict.VocaID   = contain;
                cacheDict.Pron     = messPron.text;
                cacheDict.MeanEn   = messExplaintion.text;
                cacheDict.MeanVi   = messVietnamese.text;
                cacheDict.SoundUrl = dict.m_SoundUrl;
                _dictCache.Add(cacheDict);
                if (isSaveCached)
                {
                    _dictCache.Save();
                }
                dictTemp = cacheDict;
            }
            DetailOurWord detailWord = _detailOutWordService.findDetailOurWord(userid, dictTemp.Id);

            if (detailWord == null)
            {
                hello.Selected = false;
            }
            else
            {
                hello.Selected = true;
            }
            hello.messages.Add(messPron);
            hello.messages.Add(messVietnamese);
            hello.messages.Add(messExplaintion);
            hello.messages.Add(sound);
            if (isVN)
            {
                return(null);
            }
            return(JsonConvert.SerializeObject(hello));
        }
Example #8
0
        public async Task <string> callChatBot(string contain, string id, string userid)
        {
            contain = contain.ToString().ToLower().Trim();
            //Tim trong cache nếu ko có thì request crawler
            var dictTemp = _dictCache.findWordCache(contain);
            //post
            //
            bool        isSaveCached     = true;
            DictCache   cacheDict        = new DictCache();
            OxfordDict  dict             = new OxfordDict();
            GoogleTrans googleTransJson  = new GoogleTrans();
            GoogleTrans detailVietnamese = new GoogleTrans();
            //Explain main of letter
            MessJson messExplaintion = new MessJson();
            //Pron
            MessJson messPron = new MessJson();
            //Vietnamese
            MessJson messVietnamese = new MessJson();
            //
            ChatfuelJson   hello = new ChatfuelJson();
            AttachmentJson sound = new AttachmentJson();

            sound.attachment.type = "audio";
            Attachment2 attach = new Attachment2();

            if (contain.LastOrDefault() == '.')
            {
                messPron.text = "";
                hello.messages.Add(messPron);
                return(JsonConvert.SerializeObject(hello));
            }
            Payload2 payload = new Payload2();

            //
            if (dictTemp != null)
            {
                messPron.text                = dictTemp.Pron;
                messExplaintion.text         = dictTemp.MeanEn;
                messVietnamese.text          = dictTemp.MeanVi;
                sound.attachment.payload.url = dictTemp.SoundUrl;
            }
            else
            {
                int size = contain.Split(' ').Length;
                if (size > 1)
                {
                    googleTransJson = await _clientDictionaryService.startGoogleTrans(contain);

                    messExplaintion.text = googleTransJson.sentences[0].trans;
                }
                else
                {
                    try
                    {
                        dict = await _clientDictionaryService.startCrawlerOxford(contain);

                        messPron.text        = dict.m_Pron;
                        messExplaintion.text = dict.m_Explanation.First().m_UseCase;
                    }
                    catch
                    {
                        isSaveCached         = false;
                        messExplaintion.text = contain;
                    }
                    detailVietnamese = await _clientDictionaryService.startGoogleDetailTrans(contain);

                    try
                    {
                        messVietnamese.text = detailVietnamese.dict.First().pos + ": ";
                        foreach (var item in detailVietnamese.dict.First().terms)
                        {
                            messVietnamese.text += item + ", ";
                        }
                    }
                    catch
                    {
                        isSaveCached        = false;
                        messVietnamese.text = detailVietnamese.sentences.FirstOrDefault().trans;
                    }
                }
                sound.attachment.payload.url = dict.m_SoundUrl;
                //Add database
                cacheDict          = new DictCache();
                cacheDict.VocaID   = contain;
                cacheDict.Pron     = messPron.text;
                cacheDict.MeanEn   = messExplaintion.text;
                cacheDict.MeanVi   = messVietnamese.text;
                cacheDict.SoundUrl = dict.m_SoundUrl;
                _dictCache.Add(cacheDict);
                if (isSaveCached)
                {
                    _dictCache.Save();
                }
                dictTemp = cacheDict;
            }
            DetailOurWord detailWord = _detailOutWordService.findDetailOurWord(userid, dictTemp.Id);

            if (detailWord == null)
            {
                hello.Selected = false;
            }
            else
            {
                hello.Selected = true;
            }
            hello.messages.Add(messPron);
            hello.messages.Add(messVietnamese);
            hello.messages.Add(messExplaintion);
            hello.messages.Add(sound);
            try
            {
                hello.strVoca = ToTitleCase(contain);
                ApplicationUser currentUser = _service.listUserID().Where(x => x.Id_Messenger == id).FirstOrDefault();
                NotificationHub.sendNoti(currentUser.Email, JsonConvert.SerializeObject(hello));
            }
            catch
            {
            }
            return(JsonConvert.SerializeObject(hello));
        }