Esempio n. 1
0
        private void RegisterNumber()
        {
            try
            {
                var addNewNumber = twilio.AddOutgoingCallerId(phoneTextBox.Text, phoneTextBox.Text, null, null);

                /*
                 * If number is valid, it gets called and a six digit code is displayed.
                 * The user is required to enter that code to finish registration
                 */
                if (addNewNumber.RestException == null)
                {
                    MessageBox.Show("Please enter " + addNewNumber.ValidationCode + " in the call you receive from +1 415-723-400");
                }
                else
                {
                    throw new CustomException("Number does not exist");
                    MessageBox.Show(addNewNumber.RestException.Message);
                }
            }
            catch (CustomException)
            {
                MessageBox.Show("Number is invalid, failed to register");
            }
        }
        public void ShouldAddNewOutgoingCallerId()
        {
            var client = new TwilioRestClient(Credentials.AccountSid, Credentials.AuthToken);
            var result = client.AddOutgoingCallerId("", "", null, null);

            Assert.IsNotNull(result);
            Assert.IsNull(result.RestException);
            Assert.IsNotNull(result.ValidationCode);
            Assert.Fail();
        }
        public void ShouldAddNewOutgoingCallerId()
        {
            var client = new TwilioRestClient(Credentials.AccountSid, Credentials.AuthToken);
            var result = client.AddOutgoingCallerId("", "", null, null);

            Assert.IsNotNull(result);
            Assert.IsNull(result.RestException);
            Assert.IsNotNull(result.ValidationCode);
            Assert.Fail();
        }
Esempio n. 4
0
        /// <summary>
        /// Ova metoda se ne koristi u aplikaciji zbog toga što se ne koristi premium twilio račun
        /// </summary>
        /// <param name="brojMobitela"></param>
        public void DodajBrojNaTwilio(string brojMobitela)
        {
            var twilio = new TwilioRestClient(AccountSid, AuthToken);
            var result = twilio.AddOutgoingCallerId(brojMobitela, "Mobitel", null, null);

            if (result.RestException != null)
            {
                Console.WriteLine(result.RestException.Message);
            }
        }
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/user/account
        string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        string AuthToken  = "your_auth_token";
        var    twilio     = new TwilioRestClient(AccountSid, AuthToken);

        var callerId = twilio.AddOutgoingCallerId("+12349013030", "My Home Phone Number", null, null);

        Console.WriteLine(callerId.ValidationCode);
    }
        public void ShouldUpdateOutgoingCallerId()
        {
            var client           = new TwilioRestClient(Credentials.AccountSid, Credentials.AuthToken);
            var originalCallerId = client.AddOutgoingCallerId("", "", null, null);

            var result = client.UpdateOutgoingCallerIdName("", "");

            Assert.IsNotNull(result);
            Assert.IsNull(result.RestException);
            Assert.IsNotNull(result.Sid);
            Assert.Fail();
        }
        public void ShouldUpdateOutgoingCallerId()
        {
            var client = new TwilioRestClient(Credentials.AccountSid, Credentials.AuthToken);
            var originalCallerId = client.AddOutgoingCallerId("", "", null, null);

            var result = client.UpdateOutgoingCallerIdName("", "");

            Assert.IsNotNull(result);
            Assert.IsNull(result.RestException);
            Assert.IsNotNull(result.Sid);            
            Assert.Fail();
        }
Esempio n. 8
0
        protected void btnSendCellCode_Click(object sender, EventArgs e)
        {
            HelperMethods.ActivityTracker.Track("Sent A Verification Code to a Mobile Phone", (int)UserActionEnum.Clicked);

            //Clear Labels
            lblVerifyCell.Text         = "";
            lblVerifyCellConflict.Text = "";

            try
            {
                TwilioRestClient client =
                    new TwilioRestClient(ConfigurationManager.AppSettings["TwilioSID"],
                                         ConfigurationManager.AppSettings["TwilioTOKEN"]);

                string twilioId = ConfigurationManager.AppSettings["TwilioID"];

                string CELL   = txtVerifyCell.Text;
                string userId = HttpContext.Current.Session["UserId"].ToString();

                if (userId != null)
                {
                    // Query database
                    AspNetUser user = db.AspNetUsers.Where(u => u.Id == userId).SingleOrDefault();

                    if (user.PhoneNumber != txtVerifyCell.Text)
                    {
                        lblVerifyCell.Text = "You Must First Add Your Mobile to your Contact Information before you can Verify it.";
                    }
                    else if (user.PhoneNumber == txtVerifyCell.Text)
                    {
                        // verify and then add phone number entered
                        var callerId = client.AddOutgoingCallerId(CELL, user.UserName + " Cell", null, null);

                        if (callerId.RestException != null)
                        {
                            if (callerId.RestException.Message == "Phone number is already verified.")
                            {
                                lblVerifyCellConflict.Text = callerId.RestException.Message;

                                user.PhoneNumberConfirmed = true;

                                db.Entry(user).State = System.Data.Entity.EntityState.Modified;

                                db.SaveChanges();

                                LogFile.WriteToFile("UserSettings.aspx.cs", "btnSendCellCode_Click", callerId.RestException.Message, "Number already verified with twilio.", "HPSErrorLog.txt");
                            }
                            else
                            {
                                user.PhoneNumberConfirmed = false;

                                db.Entry(user).State = System.Data.Entity.EntityState.Modified;

                                db.SaveChanges();

                                lblVerifyCellConflict.Text = callerId.RestException.Message;
                                LogFile.WriteToFile("UserSettings.aspx.cs", "btnSendCellCode_Click", callerId.RestException.Message, "Error when trying to verify mobile number.", "HPSErrorLog.txt");
                            }
                        }
                        else
                        {
                            // display code to user for them to enter on their phone
                            txtVerifyCellCode.Text = callerId.ValidationCode;

                            user.PhoneNumberConfirmed = true;

                            db.Entry(user).State = System.Data.Entity.EntityState.Modified;

                            db.SaveChanges();
                        }
                    }
                }
                else
                {
                    lblVerifyCell.Text = "Could not find your information in the database, Please refresh the page and try again.";
                }
            }
            catch (DataException dx)
            {
                lblVerifyCell.Text += " An error occured try again. If the problem persists contact your administrator.<br>";
                LogFile.WriteToFile("UserSettings.aspx.cs", "btnSendCellCode_Click", dx, "Data error when searching for user with the entered phone number.", "HPSErrorLog.txt");
            }
            catch (Exception ex)
            {
                lblVerifyCell.Text += " An error occured try again. If the problem persists contact your administrator.<br>";
                LogFile.WriteToFile("UserSettings.aspx.cs", "btnSendCellCode_Click", ex, "error when trying to find user and create rest client.", "HPSErrorLog.txt");
            }
        }