Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var builder = new  ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile($"appsettings.local.json", optional: true) // for storing actual information
            ;
            IConfigurationRoot configuration = builder.Build();
            string             Account       = (configuration.GetSection("TwilioSettings:Account").Value);
            string             Token         = (configuration.GetSection("TwilioSettings:Token").Value);
            string             username      = (configuration.GetSection("TwilioSettings:Username").Value);
            string             password      = (configuration.GetSection("TwilioSettings:Password").Value);
            string             phoneNumber   = (configuration.GetSection("TwilioSettings:DefaultNumber").Value);

            TwilioClient.Init(Account, Token);
            var    from        = new Twilio.Types.PhoneNumber(phoneNumber);
            var    to          = new PhoneNumber("+19725239489");
            string MessageBody = "Join Earth's mightiest heroes. Like Kevin Bacon.";

            var message = MessageResource.Create(body: "Join Earth's mightiest heroes. Like Kevin Bacon.", from: from, to: to);

            Console.WriteLine($"{message.Sid}  - {message.Status}");
            var call = CallResource.Create(to, from, url: new Uri("http://demo.twilio.com/docs/voice.xml"));

            Console.WriteLine($"{call.Sid}  - {call.Status}");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Метод принимающий номер телефона абонента и отправляющий на него коде верификации
        /// </summary>
        /// <param name="phoneNumber">в качестве параметра передается действующий номер</param>
        public void VerificationCodeSender(string phoneNumber)
        {
            string AccountSid       = "AC8342d8d4276f3b549f9f2ca00a2c0d0a";
            string AuthToken        = "1b0da09f5ad619addd9a972e0f9cede3";
            string Message          = string.Empty;
            string VerificationCode = string.Empty;

            this.VerificationCode = Path.GetRandomFileName().ToUpper().Remove(6);     //генерация рандомного 6-ти значного кода верификации
            this.VerificationCode = this.VerificationCode.Replace(".", "");
            TwilioClient.Init(AccountSid, AuthToken);

            var to      = new Twilio.Types.PhoneNumber(phoneNumber);
            var from    = new Twilio.Types.PhoneNumber("+14842355664");
            var message = MessageResource.Create(
                to: to,
                from: from,
                body: this.VerificationCode);
        }
Exemplo n.º 3
0
        public void GenerateMessages(string firstName, string contactPhoneNum)
        {
            string message = String.Format("Happy Birthday {0} from {1} {2}! Call me at {3} to plan a lunch sometime.", firstName, fromFirstName, fromLastName, callBackPhoneNumber);

            try
            {
                var to   = new Twilio.Types.PhoneNumber(contactPhoneNum);
                var from = new Twilio.Types.PhoneNumber(fromNumber);

                var messages = MessageResource.Create(
                    to: to,
                    from: from,
                    body: message);
            }
            catch (Exception ex)
            {
                log.LogInformation($"{DateTime.Now} : {ex.ToString()}");
            }
        }