Ejemplo n.º 1
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            var services = builder.Services;

            var retryPolicy = HttpPolicyExtensions
                              .HandleTransientHttpError()
                              .RetryAsync(3);

            services.AddHttpClient <EskomService>(h =>
            {
                h.BaseAddress = new Uri("http://loadshedding.eskom.co.za");
            })
            .AddPolicyHandler(retryPolicy);

            var twilioSid       = Environment.GetEnvironmentVariable("TwilioAccountSid");
            var twilioAuthToken = Environment.GetEnvironmentVariable("TwilioAuthToken");
            var cred            = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{twilioSid}:{twilioAuthToken}"));
            var twilioSettings  = new TwilioSettings
            {
                Sid = twilioSid
            };

            services.AddSingleton(twilioSettings);
            services.AddHttpClient <TwilioService>(h =>
            {
                h.BaseAddress = new Uri("https://api.twilio.com");
                h.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", cred);
            })
            .AddPolicyHandler(retryPolicy);
        }
Ejemplo n.º 2
0
 public CartController(IUnitOfWork unitOfWork, IEmailSender emailSender, UserManager <IdentityUser> userManager, IOptions <TwilioSettings> twilioOptions)
 {
     _unitOfWork    = unitOfWork;
     _emailSender   = emailSender;
     _userManager   = userManager;
     _twilioOptions = twilioOptions.Value;
 }
Ejemplo n.º 3
0
            public static string GenerateCapabilityToken(string sessionAspNetId, string twilioClientId)
            {
                TwilioSettings twilioSettings = new TwilioSettings();

                //generate new capability token; used for client-side connectivity directly to twilio servers
                var capability = new Twilio.TwilioCapability(twilioSettings.TwilioAccountSid, twilioSettings.TwilioAuthToken);
                capability.AllowClientIncoming(twilioClientId);
                capability.AllowClientOutgoing(twilioSettings.TwilioApplicationSid);
                string capabilityToken = capability.GenerateToken();

                //try to find existing client
                Entity.Client client = Entity.Client.FindOneByTwilioClientId(twilioClientId);
                if (client == null)
                    client = Entity.Client.FindOneBySessionAspNetId(sessionAspNetId);
                if (client == null)
                    client = new Entity.Client();

                //associate the capability token with the client
                client.ClientSessionAspNetId = sessionAspNetId;
                client.ClientTwilioClientId = twilioClientId;
                client.ClientTwilioClientToken = capabilityToken;
                client.Save();

                if (log.IsDebugEnabled) { log.Debug("GenerateCapabilityToken." + (client == null ? "null" : client.ToJsonString())); }

                return capabilityToken;
            }
Ejemplo n.º 4
0
        public VideoService(TwilioSettings twilioOptions)
        {
            _twilioSettings =
                twilioOptions
                ?? throw new ArgumentNullException(nameof(twilioOptions));

            TwilioClient.Init(_twilioSettings.AccountSid, _twilioSettings.AuthToken);
        }
Ejemplo n.º 5
0
        public VideoService(Microsoft.Extensions.Options.IOptions <TwilioSettings> twilioOptions)
        {
            _twilioSettings =
                twilioOptions?.Value
                ?? throw new ArgumentNullException(nameof(twilioOptions));

            TwilioClient.Init(_twilioSettings.ApiKey, _twilioSettings.ApiSecret);
        }
        public MainWindow()
        {
            var twilioSettings = new TwilioSettings
            {
                AccountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"),
                AuthToken  = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN")
            };

            TwilioClient.Init(twilioSettings.AccountSid, twilioSettings.AuthToken);
            InitializeComponent();
        }
Ejemplo n.º 7
0
 public HomeController(ILogger <HomeController> logger, IConfiguration config, IOptions <TwilioSettings> twilioOptions,
                       TwilioSettings twilioSettings, IOptions <SocialLoginSettings> socialLoginOptions)
 {
     _logger             = logger;
     _config             = config;
     _twilioOptions      = twilioOptions;
     _socialLoginOptions = socialLoginOptions;
     //_twilioSettings = new TwilioSettings();
     //config.GetSection("Twilio").Bind(_twilioSettings);
     _twilioSettings = twilioSettings;
 }
 public AuthenticationController(UserManager <IdentityUser> userManager, SignInManager <IdentityUser> signInManager, IOptions <ApplicationSettings> appSettings, IUnitOfWork repository, IOptions <TwilioSettings> twilioSettings, ILog logger, IStringLocalizer <Resource> localizer)
 {
     _userManager        = userManager;
     _singInManager      = signInManager;
     this.appSettings    = appSettings;
     this.repository     = repository;
     twilioSettings1     = twilioSettings;
     this.logger         = logger;
     this.localizer      = localizer;
     _appSettings        = appSettings.Value;
     this.twilioSettings = twilioSettings.Value;
 }
Ejemplo n.º 9
0
        public TwilioSmsServiceTests()
        {
            var builder = new ConfigurationBuilder()
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddEnvironmentVariables();
            var configuration = builder.Build();

            _options = new TwilioSettings
            {
                AccountSid = configuration["TWILIO_TEST_ACCOUNT_SID"],
                AuthToken  = configuration["TWILIO_TEST_AUTH_TOKEN"]
            };
        }
Ejemplo n.º 10
0
 public HomeController(IMarketForecaster marketForecaster,
                       IOptions <StripeSettings> stripeOptions,
                       IOptions <SendGridSettings> sendGridOptions,
                       IOptions <TwilioSettings> twilioOptions,
                       IOptions <WazeForecastSettings> wazeOptions)
 {
     homeVM = new HomeVM();
     this._marketForecaster = marketForecaster;
     _stripeOptions         = stripeOptions.Value;
     _sendGridOptions       = sendGridOptions.Value;
     _twilioOptions         = twilioOptions.Value;
     _wazeOptions           = wazeOptions.Value;
 }
Ejemplo n.º 11
0
        public Authy(IHttpClientFactory clientFactory, ILoggerFactory loggerFactory, UserManager <GearUser> identityUserManager, IWritableOptions <TwilioSettings> options, IHttpContextAccessor accessor, ICountryService countryService)
        {
            _identityUserManager = identityUserManager;
            _accessor            = accessor;
            _countryService      = countryService;
            _twilioSettings      = options.Value;
            _logger = loggerFactory.CreateLogger <Authy>();

            _client             = clientFactory.CreateClient();
            _client.BaseAddress = new Uri("https://api.authy.com");
            _client.DefaultRequestHeaders.Add("Accept", "application/json");
            _client.DefaultRequestHeaders.Add("user-agent", "Gear Application");
            _client.DefaultRequestHeaders.Add("X-Authy-API-Key", _twilioSettings.AuthyApiKey);
        }
Ejemplo n.º 12
0
        public static TwilioSmsGateway Create(TwilioSettings settings)
        {
            if (string.IsNullOrWhiteSpace(settings.AccountSid))
            {
                throw new ArgumentNullException(nameof(settings.AccountSid));
            }
            if (string.IsNullOrWhiteSpace(settings.ApiToken))
            {
                throw new ArgumentNullException(nameof(settings.ApiToken));
            }
            if (string.IsNullOrWhiteSpace(settings.Sender))
            {
                throw new ArgumentNullException(nameof(settings.Sender));
            }

            return(new TwilioSmsGateway(settings));
        }
 public HomeController(
     IMarketForecaster marketForecaster,
     // IOptions<StripeSettings> stripeOptions,
     IOptions <SendGridSettings> sendGridOptions,
     IOptions <TwilioSettings> twilioOptions,
     IOptions <WazeForecastSettings> wazeOptions,
     ICreditValidator creditValidator
     )
 {
     homeVM            = new HomeVM();
     _marketForecaster = marketForecaster;
     //_stripeOptions is commented because we are using it with ACTION INJECTION instead constructor Injection.
     //_stripeOptions = stripeOptions.Value;
     _sendGridOptions = sendGridOptions.Value;
     _twilioOptions   = twilioOptions.Value;
     _wazeOptions     = wazeOptions.Value;
     _creditValidator = creditValidator;
 }
Ejemplo n.º 14
0
        public HomeController(IMarketForecaster marketForecaster, ILogger <HomeController> logger,
                              ICreditValidator creditValidator,
                              ApplicationDbContext context,

                              IOptions <WazeForecastSettings> wazeForecast,
                              IOptions <StripeSettings> stripe,
                              IOptions <SendGridSettings> sendGrid,
                              IOptions <TwilioSettings> twilio)
        {
            _context = context;

            _creditValidator  = creditValidator;
            _marketForecaster = marketForecaster;
            _logger           = logger;
            _wazeForecast     = wazeForecast.Value;
            _stripeOptions    = stripe.Value;
            _sendGridOptions  = sendGrid.Value;
            _twilioOptions    = twilio.Value;
        }
Ejemplo n.º 15
0
 public TwilioCallController(TwilioSettings TwilioSettings)
 {
     _twilioSettings = TwilioSettings;
 }
Ejemplo n.º 16
0
 public HomeController(IOptions <AppSettings> settings)
 {
     TwilioSettings = settings.Value.TwilioSettings;
 }
Ejemplo n.º 17
0
 public Startup(IConfiguration configuration)
 {
     Configuration       = configuration;
     this.TwilioSettings = configuration.GetSection(nameof(this.TwilioSettings)).Get <TwilioSettings>();
 }
Ejemplo n.º 18
0
 public TwilioSender(IOptions <TwilioSettings> settings)
 {
     _settings = settings.Value;
     Initialize();
 }
Ejemplo n.º 19
0
            //initiate the request to modify the call to be sent to twilio server with appropriate callback url
            private static void InitiateCallModify(Entity.CallBase call, string redirectUrl)
            {
                if (call == null ||
                    string.IsNullOrEmpty(call.CallTwilioId) ||
                    string.IsNullOrEmpty(redirectUrl))
                {
                    return;
                }

                TwilioSettings twilioSettings = new TwilioSettings();

                redirectUrl = string.Format("{0}{1}", twilioSettings.TwilioTwiMLCallbackUrl, redirectUrl);
                var postUrl = string.Format("{0}/Accounts/{1}/Calls/{2}", twilioSettings.TwilioApiVersion, twilioSettings.TwilioAccountSid, call.CallTwilioId);

                if (log.IsDebugEnabled) { log.Debug("InitiateCallModify.postUrl." + postUrl); }

                using (HttpClient httpClient = new HttpClient("https://api.twilio.com/"))
                {
                    HttpUrlEncodedForm frm = new HttpUrlEncodedForm();

                    //add the form fields that twilio expects
                    frm.Add("Method", "POST");
                    frm.Add("Url", redirectUrl);

                    //set the security credentials for the http post
                    httpClient.TransportSettings.Credentials = new NetworkCredential(twilioSettings.TwilioAccountSid, twilioSettings.TwilioAuthToken);

                    //send request to twilio
                    using (HttpResponseMessage httpResp = httpClient.Post(postUrl, frm.CreateHttpContent()))
                    {
                        //don't need to do anything with the response of the http post
                        //twilio sends the response in a seperate http request to the callback url
                    }
                }
            }
Ejemplo n.º 20
0
        public TwilioService(IOptions <TwilioSettings> options)
        {
            _settings = options?.Value;

            InitTwilio();
        }
Ejemplo n.º 21
0
 public TwilioPrankController(DataContext dataContext, IConfiguration config, FileSettings fileSettings, TwilioSettings TwilioSettings, IWebHostEnvironment env) : base(dataContext, config, fileSettings, env)
 {
     _twilioSettings = TwilioSettings;
     hostEnvironment = env;
 }
Ejemplo n.º 22
0
 private TwilioSmsGateway(TwilioSettings settings)
 {
     _settings = settings;
     TwilioClient.Init(settings.AccountSid, settings.ApiToken);
 }
Ejemplo n.º 23
0
 public TwilioService(HttpClient http, TwilioSettings settings)
 {
     _http     = http;
     _settings = settings;
 }
 public OrderController(IUnitOfWork unitofwork, IOptions <TwilioSettings> twilioOptions, ApplicationDbContext db)
 {
     _unitofwork    = unitofwork;
     _twilioOptions = twilioOptions.Value;
     _db            = db;
 }
 public AppController(IAppointmentService appointmentService, IOptions <TwilioSettings> twilioSettings)
 {
     _appointmentService = appointmentService;
     _twilioSettings     = twilioSettings.Value;
 }
Ejemplo n.º 26
0
 public TwilioPhoneNumberLookupService(IOptions <TwilioSettings> twilioSettings, ITwilioWrapper twilioWrapper)
 {
     _twilioSettings = twilioSettings.Value;
     _twilioClient   = new TwilioRestClient(_twilioSettings.Sid, _twilioSettings.Token);
     _twilioWrapper  = twilioWrapper;
 }
Ejemplo n.º 27
0
 public TwilioSmsSender(BaseSettings baseSettings, ILog log)
 {
     _log              = log;
     _twilioSettings   = baseSettings.Twilio;
     _twilioRestClient = new TwilioRestClient(_twilioSettings.AccountSid, _twilioSettings.AuthToken);
 }