예제 #1
0
        public bool SendUnsubscribeRequest(string mobileNumber, int subscriptionServiceID, out string returnMessage)
        {
            bool hasSent = false;
            SubscriptionServiceInfo subscriptionService = new SubscriptionServiceInfo(subscriptionServiceID);

            returnMessage = string.Empty;
            if (subscriptionService != null && subscriptionService.Id > 0 && !string.IsNullOrEmpty(subscriptionService.UnsubscribeKeyword))
            {
                CQueueWrapper cq     = new CQueueWrapper(subscriptionService.RequestQueue);
                CXMLCapsule   xmlcap = new CXMLCapsule();

                xmlcap.SetParameter("INPUTMECHANISM", "20", true);//USSD input mechanism.
                xmlcap.SetParameter("SOURCEADDRESS", mobileNumber, true);
                xmlcap.SetParameter("SHORTMESSAGE", subscriptionService.UnsubscribeKeyword, true);
                cq.Send(xmlcap);
                returnMessage = String.Format("An unsubscribe request has been sent for {0}. A confirmation SMS will be sent to you when successful", subscriptionService.Name);
                hasSent       = true;
            }
            else
            {
                if (subscriptionService == null || subscriptionService.Id < 0)
                {
                    returnMessage = "Subscription service does not exist.";
                }
                else if (String.IsNullOrEmpty(subscriptionService.UnsubscribeKeyword))
                {
                    returnMessage = "Unsubscribe keyword is not set up";
                }
            }

            return(hasSent);
        }
예제 #2
0
        void Menu_ThirdPartyCommunicationEvent(object sender, MenuItem currentMenuItem)
        {
            if (currentMenuItem.IsSMS.HasValue)
            {
                if (currentMenuItem.IsSMS.Value)
                {
                    string communicationFeedback;
                    var recipients = currentMenuItem.ThirdPartyCommunicationRecipients.Replace(" ","").Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    string commsText = String.Format("{0}; Mobile Number: {1}", currentMenuItem.ThirdPartyCommunicationText,Session.MSISDN);
                    foreach (var number in recipients)
                    {
                        exactmobile.ussdcommon.MenuCommunication.SendCommunication(Session.Campaign.CampaignID, currentMenuItem.MenuId, Session.USSDTransactionID, MenuItem.CommunicationType.SMS, ussdcommon.utility.CommonUtility.ReturnNetworkID(number.Trim()), number.Trim(), commsText, (Session.USSDNumber.HasValue ? Convert.ToString(Session.USSDNumber.Value) : ""), currentMenuItem.WaitForHTTPResponse,false, out communicationFeedback);
                        
                    }
                }
                else
                {
                    string smtpServer;
                    if (!ussdcommon.utility.CommonUtility.TryGetAppSettings("SMTPServer", true, out smtpServer))
                        smtpServer = "192.168.1.110";
                    
                    CXMLCapsule capsule = new CXMLCapsule();

                    capsule.SetParameter("Sender", "*****@*****.**", true);
                    capsule.SetParameter("Recipients", currentMenuItem.ThirdPartyCommunicationRecipients.Replace(" ", ""), true);
                    capsule.SetParameter("Subject", "Exact USSD Notification Campaign #" + Session.Campaign.CampaignID.ToString(), true);
                    capsule.SetParameter("Priority", "2", true);
                    capsule.SetParameter("SMTPServer", smtpServer, true);                    
                    capsule.SetParameter("Body", string.Format("{0}. Mobile Number: {1}",currentMenuItem.ThirdPartyCommunicationText,Session.MSISDN), true);
                    capsule.SetParameter("BodyFormat", "", true);
                    capsule.SetParameter("CarbonCopies", "", true);
                    capsule.SetParameter("BlindCarbonCopies", "", true);

                    CQueueWrapper mailQueue = new CQueueWrapper("EmailOutQ");
                    mailQueue.Send(capsule);                    
                }
            }
        }
예제 #3
0
        public static bool SendCommunication(int ussdCampaignID, int menuID, long ussdTransactionID, MenuItem.CommunicationType communicationType, int mobileNetworkID, string mobileNumber, string communicationText, string ussdNumber, bool waitForResponse, bool sendHTTPResponseBySMS, out string response)
        {
            bool hasSent = false;

            try
            {
                response = null;
                switch (communicationType)
                {
                case MenuItem.CommunicationType.SM2HTTP:
                    long transactionID = -1;
                    try
                    {
                        if (AddHTTPTransaction(ussdCampaignID, ussdTransactionID, menuID, mobileNumber, null, out transactionID))
                        {
                            StringBuilder url = new StringBuilder(communicationText);
                            url.AppendFormat("&MSISDN={0}&DESTADDRESS={1}&REFERENCE={2}", HttpUtility.UrlEncode(mobileNumber), HttpUtility.UrlEncode(ussdNumber), HttpUtility.UrlEncode(transactionID.ToString()));

                            UpdateHTTPTransaction(transactionID, url.ToString(), null, null, null, null);
                            WebResponse webResponse       = null;
                            string      webResponseString = string.Empty;
                            if (!waitForResponse)
                            {
                                var webRequest = HttpWebRequest.Create(url.ToString());
                                webRequest.Method = "GET";

                                var asyncStateObject = new AsyncHTTPRequestStateObject()
                                {
                                    Request                 = webRequest
                                    , TransactionID         = transactionID
                                    , MenuID                = menuID
                                    , MobileNetworkID       = mobileNetworkID
                                    , MobileNumber          = mobileNumber
                                    , USSDCampaignID        = ussdCampaignID
                                    , USSDNumber            = ussdNumber
                                    , USSDTransactionID     = ussdTransactionID
                                    , SendHTTPResponseBySMS = sendHTTPResponseBySMS
                                };


                                IAsyncResult asyncResult = webRequest.BeginGetResponse(new AsyncCallback(PerformAsynchronousHTTPRequestCallback), asyncStateObject);

                                System.Threading.ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new System.Threading.WaitOrTimerCallback(AsynchronousHTTPRequestTimeoutCallback), asyncStateObject, asyncStateObject.Request.Timeout, true);
                                return(true);
                            }
                            else
                            {
                                try
                                {
                                    var webRequest = HttpWebRequest.Create(url.ToString());
                                    webRequest.Method = "GET";
                                    webResponse       = webRequest.GetResponse();

                                    using (var streamReader = new StreamReader(webResponse.GetResponseStream()))
                                        webResponseString = streamReader.ReadToEnd();

                                    UpdateHTTPTransaction(transactionID, null, null, null, webResponseString, null);
                                }
                                finally
                                {
                                    if (webResponse != null)
                                    {
                                        webResponse.Close();
                                    }
                                }
                                string clientMessage   = string.Empty;
                                string clientReference = string.Empty;

                                XmlDocument responseXMLDoc = new XmlDocument();
                                responseXMLDoc.LoadXml(webResponseString);

                                if (TryGetXMLElement(responseXMLDoc, new string[] { "SM", "Message" }, out clientMessage))
                                {
                                    response = clientMessage;
                                    UpdateHTTPTransaction(transactionID, null, null, clientMessage, null, null);
                                }
                                if (TryGetXMLElement(responseXMLDoc, new string[] { "SessionReference", "RefNo" }, out clientReference))
                                {
                                    UpdateHTTPTransaction(transactionID, null, clientReference, null, null, null);
                                }

                                if (sendHTTPResponseBySMS && !String.IsNullOrEmpty(clientMessage))
                                {
                                    MenuCommunication.SendCommunication(ussdCampaignID, menuID, ussdTransactionID, MenuItem.CommunicationType.SMS, mobileNetworkID, mobileNumber, clientMessage, ussdNumber, false, false, out response);
                                    response = null;
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (transactionID > 0)
                        {
                            UpdateHTTPTransaction(transactionID, null, null, null, null, ex.ToString());
                        }
                    }
                    break;

                case MenuItem.CommunicationType.SMS:
                case MenuItem.CommunicationType.MMS:
                    CQueueWrapper commsSendQueue = null;

                    if (communicationType == MenuItem.CommunicationType.MMS)
                    {
                        commsSendQueue = new CQueueWrapper("EXACTUSSDMMSCOMMUNICATIONQ");
                    }
                    else if (communicationType == MenuItem.CommunicationType.SMS)
                    {
                        commsSendQueue = new CQueueWrapper("EXACTUSSDSMSCOMMUNICATIONQ");
                    }

                    CXMLCapsule commsCapsule = new CXMLCapsule();
                    commsCapsule.SetParameter("USSDTransactionID", ussdTransactionID.ToString(), true);
                    commsCapsule.SetParameter("USSDCampaignID", ussdCampaignID.ToString(), true);
                    commsCapsule.SetParameter("USSDMenuID", menuID.ToString(), true);
                    commsCapsule.SetParameter("MobileNumber", mobileNumber, true);
                    commsCapsule.SetParameter("MobileNetworkID", mobileNetworkID.ToString(), true);
                    commsCapsule.SetParameter("CommunicationText", communicationText, true);
                    commsCapsule.SetParameter("CommunicationTypeID", Convert.ToInt32(communicationType).ToString(), true);
                    commsCapsule.SetParameter("USSDNumber", ussdNumber, true);
                    if (commsSendQueue != null)
                    {
                        commsSendQueue.Send(commsCapsule);
                        hasSent = true;
                    }
                    break;
                }
            }
            finally
            {
            }
            return(hasSent);
        }