//LIST ALL AVAILABLE INTENTS THAT CAN BE DONE IN TUTION PUBLISH
        public static List <IntentDefinition> GetIntentDefinitions()
        {
            var defs = new List <IntentDefinition>();

            if (1 == 1)
            {
                var availCourses = new IntentDefinition(WitContantsIntent.intent_subject_courses + WitContantAction.intent_action_querytask, WitContants.salutation_acknowledge, "Do you wish to find applicable courses?");
                availCourses.AddRequiredParam(WitContants.entity_grade, WitContants.entity_grade_request);
                availCourses.AddRequiredParam(WitContants.entity_location, WitContants.entity_location_request1);
                defs.Add(availCourses);
            }

            if (1 == 1)
            {
                var payment = new IntentDefinition(WitContantsIntent.intent_subject_payment + WitContantAction.intent_action_querytask, WitContants.salutation_acknowledge, "Do you wish to find payment details?");
                payment.AddRequiredParam(WitContants.entity_location, WitContants.entity_location_request1);
                payment.AddRequiredParam(WitContants.entity_subjects, WitContants.entity_subjects_request);
                payment.AddRequiredParam(WitContants.entity_grade, WitContants.entity_grade_request);
                defs.Add(payment);
            }

            if (1 == 1)
            {
                var complaint = new IntentDefinition(WitContantsIntent.intent_subject_complaint + WitContantAction.intent_action_dotask, WitContants.salutation_sorry, "");
                //complaint.AddOptionalParam(WitContants.feedback_sentiment, WitContants.entity_location_request);

                var complaint_feedback = complaint.AddRequiredParam("feedback_reason", "Can you tell me about the issue?");
                complaint_feedback.AfterAnswer = WitContants.salutation_reaction_sorry;
                complaint.AddRequiredParam(WitContants.entity_location, WitContants.entity_location_request2);
                complaint.AddRequiredParam("GuardianMobile", "We will investigate this.  Please give us your mobile number so that we can contact you.");
                defs.Add(complaint);
            }

            if (1 == 1)
            {
                var doregister = new IntentDefinition(WitContantsIntent.intent_subject_registration + WitContantAction.intent_action_dotask, "", "Do you wish to register?");
                doregister.AddRequiredParam("StudentFullName", "May i know the the fullname of child as shown in their indenty card?");
                doregister.AddRequiredParam("StudentNRIC", "How about BC / FIN / Passport?");
                doregister.AddRequiredParam("StudentBirthday", "Birthday (dd/mm/yyyy)?");
                doregister.AddRequiredParam("StudentAllergies", "Does your child have any allergies?");
                doregister.AddRequiredParam(WitContants.entity_grade, "What grade is your child in now?");
                doregister.AddRequiredParam("GuardianAddress", "May i know your full address?");
                doregister.AddRequiredParam("GuardianEmail", "Can i know your email address?");
                doregister.AddRequiredParam("GuardianMobile", "And your mobile number?");
                defs.Add(doregister);
            }

            return(defs);
        }
        public static string ProcessChatBotMessage(CalOneBotData chatdata)
        {
            if (chatdata == null)
            {
                return(null);
            }

            var    reply_builder    = new StringBuilder();
            string intent_subject   = chatdata.Entities.Intent_Subject != null ? chatdata.Entities.Intent_Subject[0].Value : "";
            string intent_direction = chatdata.Entities.Intent_Direction != null ? chatdata.Entities.Intent_Direction[0].Value : "";
            string default_answer   = chatdata.Entities.DefaultAnswers != null ? chatdata.Entities.DefaultAnswers[0].Value : "";

            // IF SUBJECT AND NOT SURE INTENT!
            if (!string.IsNullOrEmpty(intent_subject) && string.IsNullOrEmpty(intent_direction))
            {
                // SUBJECT IS KNOW BUT DONT KNOW INTENT, ASSUME ASKING
                intent_direction = WitContantAction.intent_action_querytask;
            }

            if (!string.IsNullOrEmpty(intent_subject) && !string.IsNullOrEmpty(intent_direction))
            {
                string targetIntent = intent_subject + intent_direction;

                m_currentIntent         = null;
                m_currentIntentQuestion = null;

                var ff = m_DefinitionList.Where(
                    m => m.Intent == targetIntent
                    ).Select(m => m).ToList();

                m_currentIntentQuestion = null;

                if (ff.Count > 0)
                {
                    m_currentIntent = ff[0];
                }

                if (m_currentIntent != null)
                {
                    //INITIALIZE INTENT PARAMS
                    var paramList = m_currentIntent.IntentParameters.Where(m => m.IsRequired).ToList();
                    paramList.ForEach(m => {
                        m.Value = "";
                        AssignParameterData(m, chatdata);
                    });

                    reply_builder.Append(ReplyManager.Reply(m_currentIntent.Intent_Salutation));

                    var findRequiredField = m_currentIntent.IntentParameters.Where(m => m.IsRequired && string.IsNullOrEmpty(m.Value)).ToList();
                    if (findRequiredField.Count >= 2)
                    {
                        reply_builder.Append(ReplyManager.Reply(WitContants.salutation_askfewquestions));
                    }
                }
            }

            if (m_segway != null)
            {
                if (default_answer == "default_yes")
                {
                    m_currentIntent = m_segway;
                }

                if (m_currentIntent == null)
                {
                    reply_builder.Append("No problem.  Can I assist you in any other way?");
                }

                m_segway = null;
            }

            if (m_currentIntentQuestion != null)
            {
                m_currentIntentQuestion.Value = chatdata.Text; // IF NO ENTITY DETECTED AND HAS A DEFAULT QUESTION, ASSIGN IT TO THE QUESTION

                //Append any remarks after an answer
                reply_builder.Append(ReplyManager.Reply(m_currentIntentQuestion.AfterAnswer));

                m_currentIntentQuestion = null;
            }

            if (chatdata.Entities.Farewell != null)
            {
                reply_builder.Append(ReplyManager.Reply(WitContants.entity_bye));
            }

            if (m_currentIntent != null)
            {
                var  findRequiredField = m_currentIntent.IntentParameters.Where(m => m.IsRequired && string.IsNullOrEmpty(m.Value)).ToList();
                bool IsIntentSatisfied = findRequiredField.Count == 0;

                if (IsIntentSatisfied)
                {
                    string intent_value = "";
                    if (m_currentIntent.Intent == WitContantsIntent.intent_subject_payment + WitContantAction.intent_action_querytask)
                    {
                        intent_value = CalOneBotAnswer.GetTutionPayment(m_currentIntent.IntentParameters);
                    }

                    if (m_currentIntent.Intent == WitContantsIntent.intent_subject_complaint + WitContantAction.intent_action_dotask)
                    {
                        intent_value = "I have heard you and we will get back at you as soon as possible.";
                    }

                    if (m_currentIntent.Intent == WitContantsIntent.intent_subject_registration + WitContantAction.intent_action_dotask)
                    {
                        intent_value = "Thank you.  Your registration has been filed.";
                    }

                    if (m_currentIntent.Intent == WitContantsIntent.intent_subject_courses + WitContantAction.intent_action_querytask)
                    {
                        intent_value = "Math, Mandarin, Science.";

                        var seg1 = m_DefinitionList.Find(m => m.Intent == WitContantsIntent.intent_subject_registration + WitContantAction.intent_action_dotask);
                        m_SegwayList.Enqueue(seg1);
                    }

                    if (string.IsNullOrEmpty(intent_value))
                    {
                        intent_value = WitContants.no_answer_response;
                    }

                    reply_builder.Append(intent_value);

                    if (m_SegwayList.Count > 0)
                    {
                        m_segway = m_SegwayList.Dequeue();
                        reply_builder.Append("\n" + m_segway.Intent_AskToDo);
                    }

                    m_currentIntent = null;
                    return(reply_builder.ToString());
                }

                if (findRequiredField.Count > 0)
                {
                    m_currentIntentQuestion       = findRequiredField[0];
                    m_currentIntentQuestion.Value = "";

                    reply_builder.Append(m_currentIntentQuestion.QuestionIfMissing);
                }
                else
                {
                    reply_builder.Append("Processing.");
                }
            }
            return(reply_builder.ToString());
        }
 static IntentManager()
 {
     m_DefinitionList = IntentDefinition.GetIntentDefinitions();
 }