Ejemplo n.º 1
0
        /// <summary>
        /// Sends SMS to the given number.
        /// </summary>
        /// <param name="phoneNumber">A string containing the phone number for sending SMS.</param>
        /// <param name="msgBody">A string containing message body text.</param>
        /// <param name="isUnicode">if true, message body contains unicode text; otherwise false.(Optional)</param>
        /// <returns>true if SMS is successfully sent; otherwise, false.</returns>
        public override void SendSms(string[] phoneNumber, string msgBody, bool isUnicode = false)
        {
            NexmoClient   nexmoClient   = new NexmoClient(_nexmoApiKey, _nexmoApiSecret);
            NexmoResponse smsResponse   = nexmoClient.SendMessage(phoneNumber[0], NeeoConstants.AppName, msgBody, isUnicode);
            MessageStatus messageStatus = (MessageStatus)Convert.ToUInt16(smsResponse.Messages[0].Status);

            switch (messageStatus)
            {
            case MessageStatus.InvalidMessage:
                LogManager.CurrentInstance.ErrorLogger.LogError(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Nexmo - Phone # : " + phoneNumber[0] + " Status : " + messageStatus.ToString() + ", Description : " + NexmoDictionaries.MessageStatusDescriptionDictionary[(short)messageStatus]);

                throw new ApplicationException(CustomHttpStatusCode.InvalidNumber.ToString("D"));
                break;

            case MessageStatus.Throttled:
            case MessageStatus.MissingParams:
            case MessageStatus.InvalidParams:
            case MessageStatus.InvalidCredentials:
            case MessageStatus.InternalError:
            case MessageStatus.NumberBarred:
            case MessageStatus.PartnerAccountBarred:
            case MessageStatus.PartnerQuotaExceeded:
            case MessageStatus.CommunicationFailed:
            case MessageStatus.InvalidSignature:
            case MessageStatus.InvalidSenderAddress:
                LogManager.CurrentInstance.ErrorLogger.LogError(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Nexmo - Phone # : " + phoneNumber[0] + " Status : " + messageStatus.ToString() + ", Description : " + NexmoDictionaries.MessageStatusDescriptionDictionary[(short)messageStatus]);

                throw new ApplicationException(CustomHttpStatusCode.SmsApiException.ToString("D"));
                break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends sms through primary sms service i.e Nexmo SMS Gateway.
        /// </summary>
        /// <param name="phoneNumber">A string containing the receiving phone number.</param>
        /// <param name="messageBody">A string containing the message body text.</param>
        /// <param name="enableBackupServiceSupport">A bool specifies whether backup service support is enabled or not.</param>
        public static void SendThroughPrimaryApi(string phoneNumber, string messageBody, bool enableBackupServiceSupport = false)
        {
            if (_nexmoApiKey == null)
            {
                _nexmoApiKey = ConfigurationManager.AppSettings[NeeoConstants.NexmoApiKey].ToString();
            }

            if (_nexmoApiSecret == null)
            {
                _nexmoApiSecret = ConfigurationManager.AppSettings[NeeoConstants.NexmoApiSecret].ToString();
            }

            NexmoClient   nexmoClient   = new NexmoClient(_nexmoApiKey, _nexmoApiSecret);
            NexmoResponse smsResponse   = nexmoClient.SendMessage(phoneNumber, NeeoConstants.AppName, messageBody);
            MessageStatus messageStatus = (MessageStatus)Convert.ToUInt16(smsResponse.Messages[0].Status);

            switch (messageStatus)
            {
            case MessageStatus.InvalidMessage:
                LogManager.CurrentInstance.ErrorLogger.LogError(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Nexmo - Phone # : " + phoneNumber + " Status : " + messageStatus.ToString() + ", Description : " + NexmoDictionaries.MessageStatusDescriptionDictionary[(short)messageStatus]);
                if (enableBackupServiceSupport)
                {
                    SendThroughSecondaryApi(phoneNumber, messageBody);
                }
                else
                {
                    throw new ApplicationException(CustomHttpStatusCode.InvalidNumber.ToString("D"));
                }
                break;

            case MessageStatus.Throttled:
            case MessageStatus.MissingParams:
            case MessageStatus.InvalidParams:
            case MessageStatus.InvalidCredentials:
            case MessageStatus.InternalError:
            case MessageStatus.NumberBarred:
            case MessageStatus.PartnerAccountBarred:
            case MessageStatus.PartnerQuotaExceeded:
            case MessageStatus.CommunicationFailed:
            case MessageStatus.InvalidSignature:
            case MessageStatus.InvalidSenderAddress:
                LogManager.CurrentInstance.ErrorLogger.LogError(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Nexmo - Phone # : " + phoneNumber + " Status : " + messageStatus.ToString() + ", Description : " + NexmoDictionaries.MessageStatusDescriptionDictionary[(short)messageStatus]);
                if (enableBackupServiceSupport)
                {
                    SendThroughSecondaryApi(phoneNumber, messageBody);
                }
                else
                {
                    throw new ApplicationException(CustomHttpStatusCode.SmsApiException.ToString("D"));
                }
                break;
            }
        }