示例#1
0
        private string GetSubscriptionMenu(MoUssdReceiver receiver, string prevMsg, string message)
        {
            if (prevMsg == _configurationHelper.MenuLevel1 && receiver.getMessage() != "0")
            {
                if (receiver.getMessage().ToUpper().StartsWith(_configurationHelper.SmsKeyword))
                {
                    message = _configurationHelper.MenuLevel2;
                }
                else
                {
                    throw new Exception("Invalid Format.");
                }
            }

            return(message);
        }
示例#2
0
        private string GetSubscriptionConfirmationMenu(MoUssdReceiver receiver, string message)
        {
            if (receiver.getMessage() == "1") //// Subscribe
            {
                message = _configurationHelper.MenuLevel3;
            }
            else if (receiver.getMessage() == "2") //// unsubscribe
            {
                message = _configurationHelper.MenuLevel4;
            }
            else if (receiver.getMessage() == "3") //// add more
            {
                message = _configurationHelper.MenuLevel1;
            }

            return(message);
        }
示例#3
0
        private void RunCheckerProcess(MoUssdReceiver receiver, string cacheKey, ref bool clearCache, ref string response, ref string message, string sessionId)
        {
            var numbers = receiver.getMessage();

            if (string.IsNullOrEmpty(sessionId))// for SMS check
            {
                string smsKeyword            = _configurationHelper.SmsKeyword;
                string subscriptionKeyword   = _configurationHelper.SubscriptionKeyword;
                string unSubscriptionKeyword = _configurationHelper.UnSubscriptionKeyword;

                if (numbers.ToUpper().Trim().Contains(subscriptionKeyword))
                {
                    string chargeAmount = _configurationHelper.SubscriptionChargeAmount;
                    UpdateSubscription(receiver.SourceAddress, true);
                    message    = _configurationHelper.SubscriptionConfirmMsg + _configurationHelper.UnSubscriptionMsg;
                    response   = loadObjectSender(sessionId, message, receiver, chargeAmount);
                    clearCache = ClearCache(cacheKey, ref receiver);
                }
                else if (numbers.ToUpper().Trim().Contains(unSubscriptionKeyword))
                {
                    UpdateSubscription(receiver.SourceAddress, false);
                    message = _configurationHelper.UnSubscriptionConfirmMsg;
                }
                else if (numbers.ToUpper().Trim().Contains(smsKeyword))
                {
                    message = _configurationHelper.SMSLevel1;
                    message = CheckPBNumbers(numbers) + "\r\n" + message;
                }
                else
                {
                    message = receiver.getMessage();
                }
            }
            else
            {
                message = CheckPBNumbers(numbers) + "\r\n" + message;
            }
        }
示例#4
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);
        }