Пример #1
0
        public string SendMessage(MoUssdReceiver receiver)
        {
            //// TODO:: Check http session in netcore
            string cacheKey   = "PrevMsg_" + receiver.SessionId;
            bool   clearCache = false;
            string prevMsg    = _configurationHelper.CacheTryGetValueSet(cacheKey, receiver.Message);
            string response   = string.Empty;
            string message    = string.Empty;
            string sessionId  = receiver.SessionId;
            string dialNo     = _configurationHelper.USSDDialNo;

            if (receiver.getMessage() == dialNo)
            {
                message = _configurationHelper.MenuLevel1;
            }
            else if (prevMsg.Contains(_configurationHelper.MenuLevel2) && receiver.getMessage() != "0")
            {
                message = GetSubscriptionConfirmationMenu(receiver, message);
            }
            else if (prevMsg.Contains(_configurationHelper.MenuLevel3) && receiver.getMessage() == "1")//// Subscriptions
            {
                message = "Thanks for subscription. We will notify you every 3 months after draw.\r\n";

                UpdateSubscription(receiver.getAddress(), true);
                clearCache = ClearCache(cacheKey, ref receiver);
            }
            else if (prevMsg.Contains(_configurationHelper.MenuLevel4) && receiver.getMessage() == "1")//// Subscriptions
            {
                message = "You have unsubcribed successfully";
                UpdateSubscription(receiver.getAddress(), false);
                clearCache = ClearCache(cacheKey, ref receiver);
            }
            else if (receiver.getMessage() == "0")
            {
                string responseExitMsg = "Thanks for using our service.";
                message    = responseExitMsg;
                clearCache = ClearCache(cacheKey, ref receiver);
            }
            else
            {
                try
                {
                    message = GetSubscriptionMenu(receiver, prevMsg, message);

                    RunCheckerProcess(receiver, cacheKey, ref clearCache, ref response, ref message, sessionId);
                }
                catch (Exception ex)
                {
                    message = @"Unable to validate.Please try again. Error:" + ex.Message;
                    ClearCache(cacheKey, ref receiver);
                }
            }

            if (!clearCache)
            {
                _configurationHelper.AddCache(cacheKey, message);
            }

            response = loadObjectSender(sessionId, message, receiver);
            return(response);
        }