Example #1
0
        //public void SendSMS(string number, int code)
        //{
        //    string message = string.Format(SmsSender.SmsMessageFormat, code.ToString("D6"));
        //    var twilio = new TwilioRestClient(SmsSender.SID, SmsSender.AuthToken);
        //    SMSMessage sms = twilio.SendSmsMessage("(253) 218-3535", number, message);
        //}

        public void SendSMS(string number, int code)
        {
            PhoneNumbers.PhoneNumber phone = PhoneNumbers.PhoneNumberUtil.GetInstance().Parse(number, "US");
            string numericPhone            = PhoneNumbers.PhoneNumberUtil.GetInstance().Format(phone, PhoneNumbers.PhoneNumberFormat.E164);

            numericPhone.TrimStart('+');

            // Try to send the message in the local language and English
            string regionCode    = PhoneNumbers.PhoneNumberUtil.GetInstance().GetRegionCodeForNumber(phone);
            string messageFormat = SmsSender.SmsMessageFormat.ContainsKey(regionCode) ? SmsSender.SmsMessageFormat[regionCode] : SmsSender.DefaultSmsMessageFormat;
            string message       = string.Format(messageFormat, code.ToString("D6"));

            var           nexmo    = new NexmoAPI();
            NexmoResponse response = nexmo.SendSMS(numericPhone, message);
        }
Example #2
0
        //public void SendSMS(string number, int code)
        //{
        //    string message = string.Format(SmsSender.SmsMessageFormat, code.ToString("D6"));
        //    var twilio = new TwilioRestClient(SmsSender.SID, SmsSender.AuthToken);
        //    SMSMessage sms = twilio.SendSmsMessage("(253) 218-3535", number, message);
        //}
        public void SendSMS(string number, int code)
        {
            PhoneNumbers.PhoneNumber phone = PhoneNumbers.PhoneNumberUtil.GetInstance().Parse(number, "US");
            string numericPhone = PhoneNumbers.PhoneNumberUtil.GetInstance().Format(phone, PhoneNumbers.PhoneNumberFormat.E164);
            numericPhone.TrimStart('+');

            // Try to send the message in the local language and English
            string regionCode = PhoneNumbers.PhoneNumberUtil.GetInstance().GetRegionCodeForNumber(phone);
            string messageFormat = SmsSender.SmsMessageFormat.ContainsKey(regionCode) ? SmsSender.SmsMessageFormat[regionCode] : SmsSender.DefaultSmsMessageFormat;
            string message = string.Format(messageFormat, code.ToString("D6"));

            var nexmo = new NexmoAPI();
            NexmoResponse response = nexmo.SendSMS(numericPhone, message);
        }