Exemple #1
0
        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);
        }
    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
        // 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);
    }
Exemple #4
0
    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);
    }
        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 void BuyPhoneNumber(string number)
 {
     try
     {
         IncomingPhoneNumberResource.Create(
             phoneNumber: new PhoneNumber(number),
             client: _client
             );
     }
     catch (Exception e)
     {
         throw new NotificationException(e.Message, e);
     }
 }
Exemple #7
0
        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)
            });
        }
Exemple #8
0
        public void TestCreateResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.Created,
                         "{\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"address_requirements\": \"none\",\"address_sid\": \"ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"api_version\": \"2010-04-01\",\"beta\": false,\"capabilities\": {\"voice\": true,\"sms\": false,\"mms\": true,\"fax\": false},\"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\": \"friendly_name\",\"identity_sid\": \"RIaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"origin\": \"origin\",\"phone_number\": \"+18089255327\",\"sid\": \"PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"sms_application_sid\": \"APaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"sms_fallback_method\": \"GET\",\"sms_fallback_url\": \"https://example.com\",\"sms_method\": \"GET\",\"sms_url\": \"https://example.com\",\"status_callback\": \"https://example.com\",\"status_callback_method\": \"GET\",\"trunk_sid\": null,\"uri\": \"/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json\",\"voice_application_sid\": \"APaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"voice_caller_id_lookup\": false,\"voice_fallback_method\": \"GET\",\"voice_fallback_url\": \"https://example.com\",\"voice_method\": \"GET\",\"voice_url\": \"https://example.com\",\"bundle_sid\": \"BUaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"voice_receive_mode\": \"voice\",\"status\": \"in-use\",\"subresource_uris\": {\"assigned_add_ons\": \"/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/AssignedAddOns.json\",\"local\": \"/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/Local.json\",\"mobile\": \"/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/Mobile.json\",\"toll_free\": \"/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/TollFree.json\"}}"
                         ));

            var response = IncomingPhoneNumberResource.Create(client: twilioRestClient);

            Assert.NotNull(response);
        }
Exemple #9
0
        public static string ProvisionNumber(string phoneNumber)
        {
            var accountSid = ConfigUtil.GetEnvironmentVariable("accountSid");
            var authToken  = ConfigUtil.GetEnvironmentVariable("authToken");

            TwilioClient.Init(accountSid, authToken);

            var incomingPhoneNumber = IncomingPhoneNumberResource.Create(
                phoneNumber: new Twilio.Types.PhoneNumber(phoneNumber)
                );

            UpdateNumber(incomingPhoneNumber);

            return(incomingPhoneNumber.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);

        var incomingPhoneNumber = IncomingPhoneNumberResource.Create(
            phoneNumber: new Twilio.Types.PhoneNumber("+15005550000")
            );

        Console.WriteLine(incomingPhoneNumber.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.Create(
            phoneNumber: new Twilio.Types.PhoneNumber("+4759440374"),
            pathAccountSid: "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
            );

        Console.WriteLine(incomingPhoneNumber.Sid);
    }
        public void TestCreateResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.Created,
                         "{\"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.Create(client: twilioRestClient);

            Assert.NotNull(response);
        }
    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(
            friendlyName: "My Company Line",
            voiceUrl: new Uri("http://demo.twilio.com/docs/voice.xml"),
            phoneNumber: new PhoneNumber("+15105647903"),
            voiceMethod: HttpMethod.Get);

        Console.WriteLine(number.Sid);
    }
Exemple #14
0
    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(
            friendlyName: "My Company Line",
            voiceUrl: new Uri("http://demo.twilio.com/docs/voice.xml"),
            phoneNumber: new PhoneNumber("+15105647903"),
            voiceMethod: HttpMethod.Get);

        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 tollFreeAvailableNumbers = TollFreeResource.Read("US", contains: "STORM");

        // Purchase the first number on the list
        var firstNumber         = tollFreeAvailableNumbers.First();
        var incomingPhoneNumber = IncomingPhoneNumberResource.Create(
            phoneNumber: firstNumber.PhoneNumber);

        Console.WriteLine(incomingPhoneNumber.Sid);
    }
Exemple #16
0
    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 localAvailableNumbers = LocalResource.Read("US",
                                                       excludeLocalAddressRequired: true);

        // Purchase the first number on the list
        var firstNumber         = localAvailableNumbers.First();
        var incomingPhoneNumber = IncomingPhoneNumberResource.Create(
            phoneNumber: firstNumber.PhoneNumber);

        Console.WriteLine(incomingPhoneNumber.Sid);
    }
Exemple #17
0
        public IncomingPhoneNumberResource CreateNumber(string phoneNumber)
        {
            try
            {
                IncomingPhoneNumberResource number = IncomingPhoneNumberResource.Create(
                    phoneNumber: new PhoneNumber($"+{phoneNumber}"),
                    voiceUrl: new Uri("http://demo.twilio.com/docs/voice.xml"),
                    smsUrl: new Uri("http://demo.twilio.com/test/url/voice.xml"));

                return(number);
            }
            catch (Twilio.Exceptions.ApiException ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }

            return(null);
        }
Exemple #18
0
    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 mobileAvailableNumbers = MobileResource.Read("GB");

        // Purchase the first number on the list
        var firstNumber         = mobileAvailableNumbers.First();
        var incomingPhoneNumber = IncomingPhoneNumberResource.Create(
            phoneNumber: firstNumber.PhoneNumber);

        Console.WriteLine(incomingPhoneNumber.Sid);
    }
Exemple #19
0
    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(
            friendlyName: "My Company Line",
            phoneNumber: new Twilio.Types.PhoneNumber("+15105647903"),
            voiceMethod: Twilio.Http.HttpMethod.Get,
            voiceUrl: new Uri("http://demo.twilio.com/docs/voice.xml")
            );

        Console.WriteLine(incomingPhoneNumber.Sid);
    }
Exemple #20
0
        public bool ProvisionNumber(string country, string number)
        {
            TwilioClient.Init(Config.NumberProviderConfig.TwilioAccountSid, Config.NumberProviderConfig.TwilioAuthToken);

            try
            {
                var incomingPhoneNumber = IncomingPhoneNumberResource.Create(phoneNumber: new PhoneNumber(number),
                                                                             smsUrl: new Uri(Config.NumberProviderConfig.TwilioApiUrl),
                                                                             smsMethod: "GET",
                                                                             voiceUrl: new Uri(Config.NumberProviderConfig.TwilioVoiceApiUrl),
                                                                             voiceMethod: "GET");
            }
            catch
            {
                return(false);
            }

            return(true);
        }
    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);

        const string nearLatLong           = "37.840699,-122.461853";
        var          localAvailableNumbers = LocalResource.Read("US",
                                                                nearLatLong: nearLatLong,
                                                                distance: 50,
                                                                contains: "555",
                                                                inRegion: "CA");

        var firstNumber         = localAvailableNumbers.First();
        var incomingPhoneNumber = IncomingPhoneNumberResource.Create(
            phoneNumber: firstNumber.PhoneNumber);

        Console.WriteLine(incomingPhoneNumber.Sid);
    }
        public void TestCreateRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Post,
                Twilio.Rest.Domain.Api,
                "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers.json",
                ""
                );

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                IncomingPhoneNumberResource.Create(client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }
    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);

        const string nearLatLong           = "37.840699,-122.461853";
        var          localAvailableNumbers = LocalResource.Read("US",
                                                                nearLatLong: nearLatLong,
                                                                distance: 50,
                                                                contains: "555",
                                                                inRegion: "CA");

        var firstNumber         = localAvailableNumbers.First();
        var incomingPhoneNumber = IncomingPhoneNumberResource.Create(
            phoneNumber: firstNumber.PhoneNumber);

        Console.WriteLine(incomingPhoneNumber.Sid);
    }
Exemple #24
0
        public void PrintTwilMessage()
        {
            string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
            string authToken  = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

            TwilioClient.Init(accountSid, authToken);

            var incomingPhoneNumber = IncomingPhoneNumberResource.Create(
                phoneNumber: new Twilio.Types.PhoneNumber("+15005550006"),
                voiceUrl: new Uri("http://demo.twilio.com/docs/voice.xml"));

            var message = MessageResource.Create(
                body: "This is the ship that made the Kessel Run in fourteen parsecs?",
                from: new Twilio.Types.PhoneNumber("+15005550006"),
                to: new Twilio.Types.PhoneNumber("+14126136129")
                );

            Console.WriteLine(message.Body);
            Console.WriteLine(message.To);
            Console.WriteLine(message.Direction);
            Console.WriteLine(message.ApiVersion);
        }
        public void AssignNumber(string phone)
        {
            var replyUrl = _configuration["Twilio:MessageReceiverUrl"];

            IncomingPhoneNumberResource.Create(phoneNumber: new PhoneNumber(phone), smsMethod: HttpMethod.Post, smsUrl: new Uri(replyUrl));
        }