コード例 #1
0
ファイル: TwilioHelper.cs プロジェクト: rastographics/bvcms
        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);
        }
コード例 #2
0
        //		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);
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: brizzle/TwilioCore
 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");
 }
コード例 #5
0
        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}";
            }
        }
コード例 #6
0
        public IEnumerable <VoipPhone> GetExistingPhoneNumbers()
        {
            var result = IncomingPhoneNumberResource.Read(client: client);

            return(result.Select(r => new TwilioPhone(client)
            {
                Id = r.Sid, Number = r.PhoneNumber.ToString()
            }));
        }
コード例 #7
0
ファイル: TwilioProvider.cs プロジェクト: ztcyun/AppServer
        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()
            }));
        }
コード例 #8
0
 public async Task <IncomingPhoneNumberResource> PurchasePhoneNumberAsync(
     string phoneNumber, string applicationSid)
 {
     return(await IncomingPhoneNumberResource.CreateAsync(
                voiceApplicationSid : applicationSid,
                phoneNumber : new PhoneNumber(phoneNumber),
                client : _client
                ));
 }
コード例 #9
0
    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");
    }
コード例 #10
0
        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> >();
        }
コード例 #11
0
ファイル: TwilioUtil.cs プロジェクト: tarikub/opFaceMask
        public static void DeleteNumber(string phoneSID)
        {
            var accountSid = ConfigUtil.GetEnvironmentVariable("accountSid");
            var authToken  = ConfigUtil.GetEnvironmentVariable("authToken");

            TwilioClient.Init(accountSid, authToken);

            IncomingPhoneNumberResource.Delete(
                pathSid: phoneSID
                );
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: papyr/CCM-MAY-2020
        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());
        }
コード例 #13
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("33"));

        Console.WriteLine(number.Sid);
    }
コード例 #14
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.Fetch("PN2a0747eba6abf96b7e3c3ff0b4530f6e");

        Console.WriteLine(number.PhoneNumber);
    }
コード例 #15
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);

        IncomingPhoneNumberResource.Update(
            "PN2a0747eba6abf96b7e3c3ff0b4530f6e",
            voiceUrl: new Uri("http://demo.twilio.com/docs/voice.xml"),
            smsUrl: new Uri("http://demo.twilio.com/docs/sms.xml"));
    }
コード例 #16
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.Fetch("PN2a0747eba6abf96b7e3c3ff0b4530f6e");

        Console.WriteLine(number.PhoneNumber);
    }
コード例 #17
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(phoneNumber: new PhoneNumber("33"));

        Console.WriteLine(number.Sid);
    }
コード例 #18
0
        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)
            });
        }
コード例 #19
0
        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);
        }
コード例 #20
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);
    }
コード例 #21
0
ファイル: fetch-default.5.x.cs プロジェクト: sekharfly/twilio
    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);
    }
コード例 #22
0
 public void BuyPhoneNumber(string number)
 {
     try
     {
         IncomingPhoneNumberResource.Create(
             phoneNumber: new PhoneNumber(number),
             client: _client
             );
     }
     catch (Exception e)
     {
         throw new NotificationException(e.Message, e);
     }
 }
コード例 #23
0
        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);
        }
コード例 #24
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);

        IncomingPhoneNumberResource.Update(
            "PN2a0747eba6abf96b7e3c3ff0b4530f6e",
            voiceUrl: new Uri("http://demo.twilio.com/docs/voice.xml"),
            smsUrl: new Uri("http://demo.twilio.com/docs/sms.xml"));
    }
コード例 #25
0
ファイル: TwilioProvider.cs プロジェクト: ztcyun/AppServer
        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)
            });
        }
コード例 #26
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.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);
    }
コード例 #28
0
        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);
        }
コード例 #29
0
        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);
        }
コード例 #30
0
    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);
    }