public static List <TwilioNumber> GetUnusedNumberList() { List <TwilioNumber> available = new List <TwilioNumber>(); Init(DbUtil.Db); var numbers = IncomingPhoneNumberResource.Read().ToList(); var used = (from number in DbUtil.Db.SMSNumbers join g in DbUtil.Db.SMSGroups on number.GroupID equals g.Id where g.IsDeleted == false select number).ToList(); for (var iX = numbers.Count - 1; iX > -1; iX--) { if (used.Any(n => n.Number == numbers[iX].PhoneNumber.ToString())) { numbers.RemoveAt(iX); } } foreach (var item in numbers) { var newNum = new TwilioNumber(); newNum.Name = item.FriendlyName; newNum.Number = item.PhoneNumber.ToString(); available.Add(newNum); } return(available); }
// public static List<IncomingPhoneNumber> GetNumberList() // { // TwilioClient.Init( GetSid(), GetToken() ); // // ResourceSet<IncomingPhoneNumberResource> number = IncomingPhoneNumberResource.Read(); // string text = number.First().PhoneNumber.ToString(); // // var twilio = new TwilioRestClient( GetSid(), GetToken() ); // var numbers = twilio.ListIncomingPhoneNumbers(); // // return numbers.IncomingPhoneNumbers; // } public static List <TwilioNumber> GetUnusedNumberList() { List <TwilioNumber> available = new List <TwilioNumber>(); TwilioClient.Init(GetSid(), GetToken()); var numbers = IncomingPhoneNumberResource.Read().ToList(); var used = (from e in DbUtil.Db.SMSNumbers select e).ToList(); for (var iX = numbers.Count - 1; iX > -1; iX--) { if (used.Any(n => n.Number == numbers[iX].PhoneNumber.ToString())) { numbers.RemoveAt(iX); } } foreach (var item in numbers) { var newNum = new TwilioNumber(); newNum.Name = item.FriendlyName; newNum.Number = item.PhoneNumber.ToString(); available.Add(newNum); } return(available); }
public IncomingPhoneNumberResource Hop( string twilioAccountSid, string relaySid, ILogging logging) { var original = IncomingPhoneNumberResource.Fetch(relaySid); string relayPhoneNumber = original.PhoneNumber.ToString(); logging.Log($"Releasing phone number {relayPhoneNumber} {relaySid}"); IncomingPhoneNumberResource.Delete(relaySid); var localAvailableNumbers = LocalResource.Read("US"); var desiredNumber = localAvailableNumbers.First(); logging.Log($"Purchasing new phone number {desiredNumber.PhoneNumber}"); var newNumber = IncomingPhoneNumberResource.Create( twilioAccountSid, desiredNumber.PhoneNumber, smsMethod: original.SmsMethod, smsUrl: original.SmsUrl); logging.Log($"New phone number purchased {newNumber.PhoneNumber} {newNumber.Sid}"); return(newNumber); }
public void ReadIncomingPhoneNumberResource(IncomingPhoneNumberResource resource) { Console.WriteLine($"\r\nAccount SID: {resource.AccountSid}"); Console.WriteLine($"SID: {resource.Sid}"); Console.WriteLine($"Friendly Name: {resource.FriendlyName}"); Console.WriteLine($"Phone Number: {resource.PhoneNumber}\r\n"); }
private void buttonSearch_Click(object sender, EventArgs e) { richTextBoxOutput.Text = ""; comboBoxNumbers.Enabled = false; // Check to see if the entry boxes have values in them if (textBoxSID.Text == "" || textBoxToken.Text == "") { richTextBoxOutput.Text = "Neither the SID or Token for the Twilio account has been provided.\r\n" + "If you do not have them please create a Twilio account at https://www.twilio.com to recieve them."; return; } // Make sure the TwilioClient initialisation and number retrieval is successful try { TwilioClient.Init(textBoxSID.Text, textBoxToken.Text); var list = IncomingPhoneNumberResource.Read(); // Now show the retrieved numbers _numbers.Clear(); comboBoxNumbers.Items.Clear(); foreach (var number in list) { _numbers.Add(number.PhoneNumber.ToString()); comboBoxNumbers.Items.Add(number.PhoneNumber.ToString()); } comboBoxNumbers.Enabled = true; } catch (Exception ex) { richTextBoxOutput.Text = $"A {ex.GetType()} has been thrown with the message:\r\n{ex.Message}"; } }
public IEnumerable <VoipPhone> GetExistingPhoneNumbers() { var result = IncomingPhoneNumberResource.Read(client: client); return(result.Select(r => new TwilioPhone(client) { Id = r.Sid, Number = r.PhoneNumber.ToString() })); }
public IEnumerable <VoipPhone> GetExistingPhoneNumbers() { var result = IncomingPhoneNumberResource.Read(client: client); return(result.Select(r => new TwilioPhone(client, AuthContext, TenantUtil, SecurityContext, BaseCommonLinkUtility) { Id = r.Sid, Number = r.PhoneNumber.ToString() })); }
public async Task <IncomingPhoneNumberResource> PurchasePhoneNumberAsync( string phoneNumber, string applicationSid) { return(await IncomingPhoneNumberResource.CreateAsync( voiceApplicationSid : applicationSid, phoneNumber : new PhoneNumber(phoneNumber), client : _client )); }
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); IncomingPhoneNumberResource.Delete(pathSid: "PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); }
public void Setup() { _mockRestClient = new Mock <IRestClient>(); var phoneNumber = IncomingPhoneNumberResource.FromJson("{}"); _mockRestClient.Setup(x => x.PurchasePhoneNumberAsync(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(phoneNumber); _mockRepository = new Mock <IRepository <LeadSource> >(); }
public static void DeleteNumber(string phoneSID) { var accountSid = ConfigUtil.GetEnvironmentVariable("accountSid"); var authToken = ConfigUtil.GetEnvironmentVariable("authToken"); TwilioClient.Init(accountSid, authToken); IncomingPhoneNumberResource.Delete( pathSid: phoneSID ); }
private static void CountTotalPhoneCreatedontwilio() { TwilioClient.Init(Properties.Settings.Default.TwilioAccountSid, Properties.Settings.Default.TwilioAuthToken); var type = new List <string> { "carrier" }; var incomingPhoneNumbers = IncomingPhoneNumberResource.Read(limit: 300).ToList(); Console.WriteLine(incomingPhoneNumbers.Count()); }
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 number = IncomingPhoneNumberResource.Create(phoneNumber: new PhoneNumber("33")); Console.WriteLine(number.Sid); }
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 number = IncomingPhoneNumberResource.Fetch("PN2a0747eba6abf96b7e3c3ff0b4530f6e"); Console.WriteLine(number.PhoneNumber); }
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); IncomingPhoneNumberResource.Update( "PN2a0747eba6abf96b7e3c3ff0b4530f6e", voiceUrl: new Uri("http://demo.twilio.com/docs/voice.xml"), smsUrl: new Uri("http://demo.twilio.com/docs/sms.xml")); }
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 number = IncomingPhoneNumberResource.Fetch("PN2a0747eba6abf96b7e3c3ff0b4530f6e"); Console.WriteLine(number.PhoneNumber); }
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 number = IncomingPhoneNumberResource.Create(phoneNumber: new PhoneNumber("33")); Console.WriteLine(number.Sid); }
public VoipPhone BuyNumber(string phoneNumber) { var newNumber = IncomingPhoneNumberResource.Create( new CreateIncomingPhoneNumberOptions { PathAccountSid = accountSid, PhoneNumber = new PhoneNumber(phoneNumber) }, client); return(new TwilioPhone(client) { Id = newNumber.Sid, Number = phoneNumber.Substring(1) }); }
public static IServiceCollection AddTwilioTextApi(this IServiceCollection services, TextConfig config) { TwilioClient.Init(config.Twilio.AccountSid, config.Twilio.AuthToken); var incoming = IncomingPhoneNumberResource.Fetch(pathSid: config.Twilio.PhoneSid); services.Configure <TextServiceSettings>(options => { options.AlphaCode = config.AlphaCode; options.PhoneNumber = incoming.PhoneNumber.ToString(); }); services.AddScoped <ITextSendService, TwillioTextSendService>(); return(services); }
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 number = IncomingPhoneNumberResource.Create( phoneNumber: new PhoneNumber("+15005550006"), voiceUrl: new Uri("http://demo.twilio.com/docs/voice.xml")); Console.WriteLine(number.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 incomingPhoneNumber = IncomingPhoneNumberResource.Fetch( pathSid: "PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ); Console.WriteLine(incomingPhoneNumber.FriendlyName); }
public void BuyPhoneNumber(string number) { try { IncomingPhoneNumberResource.Create( phoneNumber: new PhoneNumber(number), client: _client ); } catch (Exception e) { throw new NotificationException(e.Message, e); } }
public async Task <string> PurchasePhoneNumber(string phoneNumber) { // Format the phone number // TODO: Allow bad chars to be specificed by caller into the service char[] badChars = { '(', ')', ' ', '-' }; phoneNumber = RemoveBadChars(phoneNumber, badChars); // Purchase a phone number var result = await IncomingPhoneNumberResource.CreateAsync( voiceApplicationSid : _twilioOptions.AppSid, phoneNumber : new PhoneNumber(phoneNumber)); return(result.Sid); }
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); IncomingPhoneNumberResource.Update( "PN2a0747eba6abf96b7e3c3ff0b4530f6e", voiceUrl: new Uri("http://demo.twilio.com/docs/voice.xml"), smsUrl: new Uri("http://demo.twilio.com/docs/sms.xml")); }
public VoipPhone BuyNumber(string phoneNumber) { var newNumber = IncomingPhoneNumberResource.Create( new CreateIncomingPhoneNumberOptions { PathAccountSid = accountSid, PhoneNumber = new PhoneNumber(phoneNumber) }, client); return(new TwilioPhone(client, AuthContext, TenantUtil, SecurityContext, BaseCommonLinkUtility) { Id = newNumber.Sid, Number = phoneNumber.Substring(1) }); }
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 incomingPhoneNumber = IncomingPhoneNumberResource.Fetch( pathSid: "PN2a0747eba6abf96b7e3c3ff0b4530f6e" ); Console.WriteLine(incomingPhoneNumber.FriendlyName); }
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 incomingPhoneNumber = IncomingPhoneNumberResource.Create( phoneNumber: new Twilio.Types.PhoneNumber("+15005550000") ); Console.WriteLine(incomingPhoneNumber.Sid); }
public void TestReadEmptyResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.OK, "{\"end\": 0,\"first_page_uri\": \"/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers.json?PageSize=1&Page=0\",\"incoming_phone_numbers\": [],\"last_page_uri\": \"/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers.json?PageSize=1&Page=2\",\"next_page_uri\": null,\"num_pages\": 3,\"page\": 0,\"page_size\": 1,\"previous_page_uri\": null,\"start\": 0,\"total\": 3,\"uri\": \"/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers.json?PageSize=1\"}" )); var response = IncomingPhoneNumberResource.Read(client: twilioRestClient); Assert.NotNull(response); }
public void TestFetchResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.OK, "{\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"address_requirements\": \"none\",\"address_sid\": \"ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"api_version\": \"2010-04-01\",\"beta\": false,\"capabilities\": {\"mms\": true,\"sms\": false,\"voice\": true},\"date_created\": \"Thu, 30 Jul 2015 23:19:04 +0000\",\"date_updated\": \"Thu, 30 Jul 2015 23:19:04 +0000\",\"emergency_status\": \"Active\",\"emergency_address_sid\": \"ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"friendly_name\": \"(808) 925-5327\",\"identity_sid\": \"RIaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"origin\": \"origin\",\"phone_number\": \"+18089255327\",\"sid\": \"PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"sms_application_sid\": \"\",\"sms_fallback_method\": \"POST\",\"sms_fallback_url\": \"\",\"sms_method\": \"POST\",\"sms_url\": \"\",\"status_callback\": \"\",\"status_callback_method\": \"POST\",\"trunk_sid\": null,\"uri\": \"/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json\",\"voice_application_sid\": \"\",\"voice_caller_id_lookup\": false,\"voice_fallback_method\": \"POST\",\"voice_fallback_url\": null,\"voice_method\": \"POST\",\"voice_url\": null}" )); var response = IncomingPhoneNumberResource.Fetch("PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient); Assert.NotNull(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); var incomingPhoneNumber = IncomingPhoneNumberResource.Create( phoneNumber: new Twilio.Types.PhoneNumber("+4759440374"), pathAccountSid: "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ); Console.WriteLine(incomingPhoneNumber.Sid); }