/// <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; } }
/// <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; } }
public void SendSMS(string message, string recipientPhoneNo) { try { Sms sms = new Sms(); sms.RecepientPhoneNo = recipientPhoneNo; sms.Message = message; NexmoResponse response = _smsEngine.Send(sms); } catch (Exception) { //suppress the error (some email address might be incorrectly entered); } }
public ActionResult RedactWithId(string id, string product, string type) { if (product == RedactModel.RedactProduct.verifySdk.ToString()) { product = "verify-sdk"; } if (product == RedactModel.RedactProduct.numberInsight.ToString()) { product = "number-insight"; } try { NexmoResponse result = null; if (product == RedactModel.RedactProduct.sms.ToString() && type == RedactModel.RedactType.na.ToString()) { ViewBag.redactResult = "ERROR: Need to add a type for SMS"; } else if (product == "sms") { result = RedactSender.RedactWithIdAndType(id, product, type); } else { result = RedactSender.RedactWithId(id, product); } if (result != null && result.Status == System.Net.HttpStatusCode.NoContent) { ViewBag.redactResult = "Redact request handled successfully"; } else if (result != null) { ViewBag.redactResult = string.Format("Redact request failed got error code: {0}", result); } } catch (Exception e) { ViewBag.redactResult = "Error processing redact request"; } return(View("Index")); }