Exemplo n.º 1
0
        public int CreateUser(OOPEZZ_DBEntities db, string PSID)
        {
            string fbtoken = AppInstance.getInstance().getFbPageToken();
            string url     = "https://graph.facebook.com/" + PSID +
                             "?fields=first_name,last_name,gender&access_token=" +
                             fbtoken;

            var request = (HttpWebRequest)WebRequest.Create(url);

            request.ContentType = "application/json";
            request.Method      = "GET";
            WebResponse response = request.GetResponse();
            string      result   = new StreamReader(response.GetResponseStream()).ReadToEnd();
            //UserAPITemplate userResponse =  new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<UserAPITemplate>(result);
            UserAPITemplate userResponse = JsonConvert.DeserializeObject <UserAPITemplate>(result);
            string          name         = Ulti.UnicodeDecode(userResponse.LastName + " " + userResponse.FirstName);
            USER            user         = new USER()
            {
                STATUS   = 1,
                TOKEN    = PSID,
                USERNAME = name
            };

            db.USER.Add(user);
            db.SaveChanges();

            return(user.PK_SEQ);
        }
Exemplo n.º 2
0
        //private void _lessonmenu(OOPEZZ_DBEntities db, BotMessageReceivedRequest botMessage)
        //{
        //    ///thua
        //    List<LESSION> lessionlist = db.LESSION.ToList();
        //    List<PayloadElements> listelement = new List<PayloadElements>();
        //    foreach (LESSION ls in lessionlist)
        //    {
        //        PayloadElements element = new PayloadElements()
        //        {
        //            title = ls.NAME,
        //            //image_url = ls.IMAGE,
        //            subtitle = ls.DESCRIPTION,

        //            buttons = new List<ResponseButtons>
        //            {
        //                new ResponseButtons
        //                {
        //                    type = "web_url",
        //                    title = "View",
        //                    url = "https://www.facebook.com/pg/OOP-Ezz-108722340761918"
        //                }
        //            },
        //            default_action = new PayloadElementDefautAction
        //            {
        //                type = "web_url",
        //                url = "https://www.facebook.com/pg/OOP-Ezz-108722340761918"
        //            }
        //        };
        //        listelement.Add(element);
        //    }

        //    List<ResponseButtons> lbt = new List<ResponseButtons>()
        //    {
        //        new ResponseButtons
        //        {
        //            title = "View More",
        //            type = "postback",
        //            payload = "payload view more"
        //        }
        //    };
        //    //listelement.RemoveAt(1);
        //    String json = fbTemplate.ListTemplate(botMessage.sender.id, listelement);
        //    _post(json);

        //}

        private void _rqQuestion(OOPEZZ_DBEntities db, BotMessageReceivedRequest botMessage)
        {
            String mess = botMessage.message.text.Remove(0, 6);

            mess = mess.Trim();
            mess = Ulti.replaceKeyword(db, mess);
            USER user      = db.USER.Where(x => x.TOKEN == botMessage.sender.id).FirstOrDefault();
            int  userpkseq = -1;

            if (user == null)
            {
                UserControl control = new UserControl();
                userpkseq = control.CreateUser(db, botMessage.sender.id);
            }
            else
            {
                userpkseq = user.PK_SEQ;
            }

            QUESTION ques = new QUESTION()
            {
                BEST_ANSWER_FK   = 0,
                QUESTION_TEXT    = mess,
                QUESTION_USER_FK = userpkseq,
                STATUS           = 0
            };

            db.QUESTION.Add(ques);
            db.SaveChanges();
            String json = fbTemplate.SimpleTextTemplate(botMessage.sender.id, "Oki đã ghi nhận nào có câu trả lời mình sẽ trả lời ngay");

            _post(json);
        }
Exemplo n.º 3
0
        private void _postRelateGroupcontent(OOPEZZ_DBEntities db, BotMessageReceivedRequest mess, List <String> strques, QUESTION linkedques = null)
        {
            char[] charac = { '-' };
            List <GROUP_CONTENT> gcontents = db.GROUP_CONTENT.ToList();
            List <GROUP_CONTENT> gresult   = new List <GROUP_CONTENT>();

            foreach (GROUP_CONTENT goupcontent in gcontents)
            {
                List <String> gStrStr      = Ulti.replaceAEIOU(goupcontent.NAME.ToLower()).Split(charac).ToList();
                int           resultLength = Ulti.LevenshteinDistance(strques, gStrStr);
                if (Ulti.calculateResultisAvaiable(resultLength, gStrStr))
                {
                    gresult.Add(goupcontent);
                }
            }
            //Tìm xong  => post


            //post group content
            if (gresult.Count > 0)
            {
                String json;
                foreach (GROUP_CONTENT gcontent in gresult)
                {
                    json = fbTemplate.ButtonTemplate(mess.sender.id, "Nội dung tương tự :" + gcontent.NAME, new List <ResponseButtons> {
                        new ResponseButtons()
                        {
                            type    = "postback",
                            title   = "Xem",
                            payload = "GROUPCONTENT_" + gcontent.PK_SEQ
                        }
                    });
                    _post(json);
                }
            }
            else
            {
                if (linkedques != null)
                {
                    string json = fbTemplate.SimpleTextTemplate(mess.sender.id, "Câu hỏi tương tự ");
                    _post(json);
                    _postQuestion(db, linkedques, mess);
                }
                else
                {
                    _postNoQuest(mess);
                }
            }
        }
Exemplo n.º 4
0
        private void _question(OOPEZZ_DBEntities db, BotMessageReceivedRequest botMessage)
        {
            String mess = botMessage.message.text.ToLower();

            mess = Ulti.removeCommonstr(mess);
            mess = mess.Trim();
            mess = Ulti.replaceKeyword(db, mess);
            mess = Ulti.replaceAEIOU(mess);
            char[]        charac  = { '-' };
            List <String> strques = mess.Split(charac).ToList();


            List <QUESTION> questionlist = db.QUESTION.ToList();
            int             maxCompare   = 10000;
            QUESTION        result       = null;

            foreach (QUESTION question in questionlist)
            {
                List <String> ques         = Ulti.replaceAEIOU(question.QUESTION_TEXT.ToLower()).Split(charac).ToList();
                int           resultLength = Ulti.LevenshteinDistance(strques, ques);
                if (resultLength < maxCompare)
                {
                    maxCompare = resultLength;
                    result     = question;
                }
            }

            if (!Ulti.calculateResultisAvaiable(maxCompare, Ulti.replaceAEIOU(result.QUESTION_TEXT.ToLower()).Split(charac).ToList()) || result == null)
            {
                _postRelateGroupcontent(db, botMessage, strques);
            }
            else
            {
                _postRelateGroupcontent(db, botMessage, strques, result);
            }
        }