public IActionResult Index() { TwilioClient.Init(_settings.AccountSid, _settings.AuthToken); try { var type = new List <string> { "carrier" }; foreach (var phoneNumber in phoneNumbers_2) { var phoneNumberResource = PhoneNumberResource.Fetch( type: type, pathPhoneNumber: new PhoneNumber(phoneNumber) ); Debug.WriteLine(phoneNumber); foreach (var carrier in phoneNumberResource.Carrier) { Debug.WriteLine(carrier.Key); Debug.WriteLine(carrier.Value); } } } catch (Exception e) { Debug.WriteLine(e); } return(Ok()); }
public static void Main(string[] args) { // Get your Account SID and Auth Token from twilio.com/console // To set up environmental variables, see http://twil.io/secure const string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); const string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN"); TwilioClient.Init(accountSid, authToken); var addOns = new List <string> { "payfone_tcpa_compliance" }; var addOnsData = new Dictionary <string, object> { { "payfone_tcpa_compliance.RightPartyContactedDate", "20160101" } }; var phoneNumberFetcher = PhoneNumberResource.Fetcher(new PhoneNumber("+16502530000")); phoneNumberFetcher.addOns = addOns; phoneNumberFetcher.addOnsData = addOnsData; var number = phoneNumberFetcher.Fetch(); Console.WriteLine(number.addOns); }
public static void Main(string[] args) { // Find your Account SID and Auth Token at twilio.com/console // To set up environmental variables, see http://twil.io/secure const string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); const string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN"); TwilioClient.Init(accountSid, authToken); try { // Look up a phone number in E.164 format var phoneNumber = PhoneNumberResource.Fetch( new PhoneNumber("+15108675310"), type: new List <string> { "carrier" }); Console.WriteLine(phoneNumber.Carrier["name"]); Console.WriteLine(phoneNumber.Carrier["type"]); } catch (ApiException e) { if (e.Status == 404) { Console.WriteLine("No carrier information"); } else { Console.WriteLine(e.ToString()); } } }
/// <summary> /// Validate a Phone Number Async using Twilio API. /// </summary> /// <param name="configuration"> The Configuration which will be provided to the twilio api. Ex.(Sid, AuthorizationToken)</param> /// <param name="phoneNumber">The phone number who will be Validated</param> /// <param name="messageBody"> The Content of the message body</param> /// <returns>True if the send operation succeed false otherwise</returns> public async Task ValidatePhoneNumberAsync(ISmsRequestConfiguration configuration, string phoneNumber) { try { TwilioClient.Init(configuration.AccountSid, configuration.AuthorizationToken); var result = await PhoneNumberResource.FetchAsync( pathPhoneNumber : new PhoneNumber(phoneNumber) ); } catch (ApiException ex) { Log.Error(ex, ex.Message, ex); } catch (CertificateValidationException ex) { Log.Error(ex, ex.Message, ex); } catch (RestException ex) { Log.Error(ex, ex.Message, ex); } catch (TwilioException ex) { Log.Error(ex, ex.Message, ex); } catch (Exception ex) { Log.Error(ex, ex.Message, ex); } }
public static void Main(string[] args) { // Get your Account SID and Auth Token from twilio.com/console const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); var addOns = new List <string> { "payfone_tcpa_compliance" }; var addOnsData = new Dictionary <string, object> { { "payfone_tcpa_compliance.RightPartyContactedDate", "20160101" } }; var phoneNumberFetcher = PhoneNumberResource.Fetcher(new PhoneNumber("+16502530000")); phoneNumberFetcher.addOns = addOns; phoneNumberFetcher.addOnsData = addOnsData; var number = phoneNumberFetcher.Fetch(); Console.WriteLine(number.addOns); }
public bool LookupPhone(string phone) { logger.LogInformation($"Validating #{phone} with API lookup."); PhoneNumberResource lookupResult; try { lookupResult = PhoneNumberResource.Fetch( pathPhoneNumber: new Twilio.Types.PhoneNumber(phone) ); } catch (ApiException) { logger.LogError("ApiException caught while attempting to lookup phone number."); return(false); } if (string.IsNullOrEmpty(lookupResult.PhoneNumber.ToString())) { logger.LogWarning($"Phone number {phone} failed lookup validation."); return(false); } logger.LogInformation($"Phone number {phone} passed lookup validation."); return(true); }
static void Main(string[] args) { // Find your Account Sid and Token at twilio.com/console // DANGER! This is insecure. See http://twil.io/secure const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); var addOns = new List <string> { "payfone_tcpa_compliance" }; var addOnsData = new Dictionary <string, Object>() { { "payfone_tcpa_compliance.right_party_contacted_date", 20160101 } }; var phoneNumber = PhoneNumberResource.Fetch( addOns: addOns, addOnsData: addOnsData, pathPhoneNumber: new Twilio.Types.PhoneNumber("+16502530000") ); Console.WriteLine(phoneNumber.AddOns); }
public static void Main(string[] args) { // Find your Account SID and Auth Token at twilio.com/console const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); var phoneNumber = PhoneNumberResource.Fetch( new PhoneNumber("+15108675310"), type: new List <string> { "carrier" }); var mcc = phoneNumber.Carrier["mobile_country_code"]; var mnc = phoneNumber.Carrier["mobile_network_code"]; var countryCode = phoneNumber.CountryCode; var countries = CountryResource.Fetch(countryCode); var prices = countries .OutboundSmsPrices .Where(price => price.Mcc.Equals(mcc) && price.Mnc.Equals(mnc)) .SelectMany(price => price.Prices); foreach (var price in prices) { Console.WriteLine($"Country {countryCode}"); Console.WriteLine($"Current price {price.BasePrice}"); Console.WriteLine($"Current price {price.CurrentPrice}"); } }
public async Task OnConfiguredAsync(App app, string id, ConfiguredIntegration configured, ConfiguredIntegration?previous, CancellationToken ct) { var accountSid = AccountSidProperty.GetString(configured); if (string.IsNullOrWhiteSpace(accountSid)) { return; } var authToken = AuthTokenProperty.GetString(configured); if (string.IsNullOrWhiteSpace(authToken)) { return; } var phoneNumber = PhoneNumberProperty.GetNumber(configured); if (phoneNumber == 0) { return; } try { var client = clientPool.GetServer(accountSid, authToken); await PhoneNumberResource.FetchAsync(ConvertPhoneNumber(phoneNumber), client : client); } catch { throw new ValidationException(Texts.Twilio_ErrorInvalidConfig); } }
private static PhoneNumberLookupResult BuildPhoneNumberLookupResult(PhoneNumberResource phoneNumberResource) { if (phoneNumberResource == null) { return(PhoneNumberLookupResult.FailedLookup); } var phoneNumberType = PhoneNumberType.Unknown; if (phoneNumberResource.Carrier != null) { var type = phoneNumberResource.Carrier["type"]; if (!string.IsNullOrEmpty(type)) { switch (type) { case "landline": phoneNumberType = PhoneNumberType.Landline; break; case "mobile": phoneNumberType = PhoneNumberType.Mobile; break; case "voip": phoneNumberType = PhoneNumberType.Voip; break; } } } return(new PhoneNumberLookupResult(phoneNumberResource.PhoneNumber.ToString(), phoneNumberType)); }
private bool RegisterNotifcation(ref DAL.Notification notification) { List <string> _NotificationMessage = new List <string>(); if (!isNotificationValid(ref notification, ref _NotificationMessage)) { TempData["NotificationMessage"] = _NotificationMessage; return(false); } else if (!isNotificationExist(notification, ref _NotificationMessage)) { notification.Num_Vol = ""; TempData["NotificationMessage"] = _NotificationMessage; return(false); } var phoneNumber = PhoneNumberResource.Fetch( countryCode: "US", pathPhoneNumber: new Twilio.Types.PhoneNumber(notification.Num_Phone) ); notification.Num_Phone = phoneNumber.PhoneNumber.ToString(); notification.Date_Notification = DateTime.Now; _APP.AddNotification(notification); _NotificationMessage.Add("L'inscription au vols est enregistrer."); TempData["NotificationMessage"] = _NotificationMessage; return(true); }
public override bool IsValid(object value) { //Get the configuration from App.config string accountSid = ConfigurationManager.AppSettings["Twilio.accountSid"].ToString(); string authToken = ConfigurationManager.AppSettings["Twilio.authToken"].ToString(); string validCultures = ConfigurationManager.AppSettings["Twilio.validCultures"].ToString(); //Obtain an array of string with the supported cultures string[] cultureList = validCultures.Split(','); TwilioClient.Init(accountSid, authToken); bool result = false; foreach (string culture in cultureList) { try { //Try to validate the number with the current cultures var phoneNumber = PhoneNumberResource.Fetch( countryCode: culture, pathPhoneNumber: new Twilio.Types.PhoneNumber(value.ToString()) ); result = true; break; } catch { } } return(result); }
public static void Main(string[] args) { // Find your Account SID and Auth Token at twilio.com/console const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); try { // Look up a phone number in E.164 format var phoneNumber = PhoneNumberResource.Fetch( new PhoneNumber("+15108675310"), type: new List <string> { "carrier" }); Console.WriteLine(phoneNumber.Carrier["name"]); Console.WriteLine(phoneNumber.Carrier["type"]); } catch (ApiException e) { if (e.Status == 404) { Console.WriteLine("No carrier information"); } else { Console.WriteLine(e.ToString()); } } }
private string GetCountry(string number) { const string accountSid = "####"; const string authToken = "####"; TwilioClient.Init(accountSid, authToken); var type = new List <string> { "carrier" }; try { var phoneNumber = PhoneNumberResource.Fetch( type: type, pathPhoneNumber: new Twilio.Types.PhoneNumber(number) ); return(phoneNumber.CountryCode); } catch (System.Exception) { // return default country code if number not found return("US"); } }
public static void Main(string[] args) { // Find your Account SID and Auth Token at twilio.com/console // To set up environmental variables, see http://twil.io/secure const string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); const string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN"); TwilioClient.Init(accountSid, authToken); var phoneNumber = PhoneNumberResource.Fetch( new PhoneNumber("+15108675310"), type: new List <string> { "carrier" }); var mcc = phoneNumber.Carrier["mobile_country_code"]; var mnc = phoneNumber.Carrier["mobile_network_code"]; var countryCode = phoneNumber.CountryCode; var countries = CountryResource.Fetch(countryCode); var prices = countries .OutboundSmsPrices .Where(price => price.Mcc.Equals(mcc) && price.Mnc.Equals(mnc)) .SelectMany(price => price.Prices); foreach (var price in prices) { Console.WriteLine($"Country {countryCode}"); Console.WriteLine($"Current price {price.BasePrice}"); Console.WriteLine($"Current price {price.CurrentPrice}"); } }
static void Main(string[] args) { // Find your Account Sid and Token at twilio.com/console const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); var addOns = new List <string> { "payfone_tcpa_compliance" }; var addOnsData = new Dictionary <string, Object>() { { "payfone_tcpa_compliance.right_party_contacted_date", 20160101 } }; var type = new List <string> { "carrier" }; var phoneNumber = PhoneNumberResource.Fetch( addOns: addOns, addOnsData: addOnsData, type: type, pathPhoneNumber: new Twilio.Types.PhoneNumber("+15108675310") ); Console.WriteLine(phoneNumber.CallerName); }
public async Task <PhoneNrInfo> GetPhoneNrInfo(string phoneNr) { // https://www.twilio.com/docs/lookup/quickstart PhoneNumberResource phoneNumber = null; var isValid = false; try { phoneNumber = await PhoneNumberResource.FetchAsync( client : lookUpClient, pathPhoneNumber : new Twilio.Types.PhoneNumber(phoneNr), type : new List <string> { "carrier" } ); isValid = true; } catch (ApiException ex) { isValid = false; } var r = new PhoneNrInfo { IsValid = isValid, CountryCode = phoneNumber?.CountryCode, NationalFormat = phoneNumber?.NationalFormat, PhoneNr = phoneNumber?.PhoneNumber.ToString(), TypeOfNumber = getTypeOfNr(phoneNumber) }; PhoneNrInfo.TypeOfNumberEnum getTypeOfNr(PhoneNumberResource phNrResource) { if (phNrResource?.Carrier == null) { return(PhoneNrInfo.TypeOfNumberEnum.Unknown); } else if (phNrResource.Carrier.TryGetValue("type", out var type)) { if (type == "mobile") { return(PhoneNrInfo.TypeOfNumberEnum.Mobile); } else { return(PhoneNrInfo.TypeOfNumberEnum.Other); } } else { return(PhoneNrInfo.TypeOfNumberEnum.Unknown); } }; return(r); }
public object Post([FromBody] LookupRequest request) { var lookupData = PhoneNumberResource.Fetch( type: new List <string> { "carrier" }, pathPhoneNumber: new Twilio.Types.PhoneNumber($"{request.CountryCode}{request.PhoneNumber}") ); return(Ok(new { info = lookupData })); }
private static void UpdateData() { List <Liaison> liaisons = new List <Liaison>(); using (var _db = new ApplicationdbContect(Properties.Settings.Default.ConnectionString)) { liaisons = _db.Liaisons.Where(x => x.TwilioNumbersTableId != null).ToList(); foreach (var i in liaisons) { TwilioClient.Init(Properties.Settings.Default.TwilioAccountSid, Properties.Settings.Default.TwilioAuthToken); //var availablePhoneNumberCountry = AvailablePhoneNumberCountryResource.Fetch( // pathCountryCode: "US" // ); //Console.WriteLine(); #region Check Phone Number info friendly name etc var type = new List <string> { "carrier" }; var phoneNumber = PhoneNumberResource.Fetch( type: type, pathPhoneNumber: new Twilio.Types.PhoneNumber(i.TwilioCallerId) ); Console.WriteLine(phoneNumber.Carrier); Console.WriteLine(phoneNumber.NationalFormat); Console.WriteLine(phoneNumber.PhoneNumber); #endregion #region Map existing number in twilio table if (phoneNumber != null) { TwilioNumbersTable tn = new TwilioNumbersTable(); tn.FriendlyPhoneNumer = phoneNumber.NationalFormat; tn.MobilePhoneNumber = phoneNumber.PhoneNumber.ToString(); tn.Status = true; tn.CreatedOn = DateTime.Now; tn.CreatedBy = "bcbfb545-1d9e-40a5-b823-3616c5fc4050"; _db.TwilioNumbersTable.Add(tn); _db.SaveChanges(); i.TwilioNumbersTableId = tn.Id; i.UpdatedBy = "bcbfb545-1d9e-40a5-b823-3616c5fc4050"; i.UpdatedOn = DateTime.Now; _db.Entry(i).State = System.Data.Entity.EntityState.Modified; _db.SaveChanges(); } #endregion } } }
public string CheckPhoneNumber(string inputNumber) { TwilioClient.Init(TwilioAccountSid, TwilioAuthToken); var phoneNumber = PhoneNumberResource.Fetch( new PhoneNumber(inputNumber), type: new List <string> { "carrier" }); return(phoneNumber.PhoneNumber.ToString()); }
public static void Main(string[] args) { // Find your Account SID and Auth Token at twilio.com/console const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); var phoneNumber = PhoneNumberResource.Fetch(new PhoneNumber("+4402077651182")); Console.WriteLine(phoneNumber.NationalFormat); }
public static void Main(string[] args) { // Find your Account SID and Auth Token at twilio.com/console const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); var phoneNumber = PhoneNumberResource.Fetch(new PhoneNumber("(510) 867-5310"), "US"); Console.WriteLine(phoneNumber.PhoneNumber); }
public TwiMLResult Response() { var phoneNumber = PhoneNumberResource.Fetch( countryCode: "US", pathPhoneNumber: new Twilio.Types.PhoneNumber(Request.Form["From"]) ); string requestBody = Request.Form["Body"]; var requestPhone = phoneNumber.PhoneNumber.ToString(); var response = twilloInstance.GetResponse(requestBody, requestPhone); return(TwiML(response)); }
static void Main(string[] args) { // Find your Account Sid and Token at twilio.com/console const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); PhoneNumberResource.Delete( pathServiceSid: "MG2172dd2db502e20dd981ef0d67850e1a", pathSid: "PN557ce644e5ab84fa21cc21112e22c485" ); }
public static void Main(string[] args) { // Find your Account SID and Auth Token at twilio.com/console // To set up environmental variables, see http://twil.io/secure const string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); const string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN"); TwilioClient.Init(accountSid, authToken); var phoneNumber = PhoneNumberResource.Fetch(new PhoneNumber("+4402077651182")); Console.WriteLine(phoneNumber.NationalFormat); }
static void Main(string[] args) { // Find your Account Sid and Token at twilio.com/console const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); PhoneNumberResource.Delete( pathServiceSid: "KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", pathSid: "PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ); }
static void Main(string[] args) { // Find your Account SID and Auth Token at twilio.com/console const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; const string pathServiceSid = "MG2172dd2db502e20dd981ef0d67850e1a"; const string phoneNumberSid = "PN557ce644e5ab84fa21cc21112e22c485"; TwilioClient.Init(accountSid, authToken); var phoneNumber = PhoneNumberResource.Create(pathServiceSid, phoneNumberSid); Console.WriteLine(phoneNumber.Sid); }
static void Main(string[] args) { // Find your Account Sid and Token at twilio.com/console const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); var phoneNumber = PhoneNumberResource.Fetch( pathPhoneNumber: new Twilio.Types.PhoneNumber("+4402077651182") ); Console.WriteLine(phoneNumber.CallerName); }
static void Main(string[] args) { // Find your Account Sid, Auth Token and Proxy Service sid at twilio.com/console const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; const string proxyServiceSid = "KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string twilioPhoneNumberSid = "PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; TwilioClient.Init(accountSid, authToken); var proxyNumber = PhoneNumberResource.Create(proxyServiceSid, twilioPhoneNumberSid); Console.WriteLine(proxyNumber.Sid); }
static void Main(string[] args) { // Find your Account Sid and Token at twilio.com/console // DANGER! This is insecure. See http://twil.io/secure const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); PhoneNumberResource.Delete( pathTrunkSid: "TRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", pathSid: "PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ); }