private static void UpdateLogicProviderSender(CommandLineConfig config) { var client = GetApi(config); var logicProviderConfig = client.GetLogicProviderConfiguration( providerConfigurationId: config.ProviderConfigurationId, subscriptionId: config.SubscriptionId); Log.Information( "Updating subscription {SubscriptionId} logic SMS provider {ProviderConfigId} from {OldSender} to {NewSender}", config.SubscriptionId, config.ProviderConfigurationId, logicProviderConfig.Configuration.Sender, config.LogicProviderSender); logicProviderConfig.Configuration.Sender = config.LogicProviderSender; var updateResult = client.UpdateLogicProviderConfiguration( subscriptionId: config.SubscriptionId, request: new LogicProviderConfigLogicProviderConfigurationRequest( displayName: logicProviderConfig.DisplayName, configuration: logicProviderConfig.Configuration), providerConfigurationId: logicProviderConfig.ProviderConfigurationId); Log.Information("Updating the Logic Provider responded result {@Result}", updateResult); }
private static Guid CreateLogicConfiguration(CommandLineConfig config) { var client = GetApi(config); var resultLogicProvider = client.CreateLogicProviderConfiguration( subscriptionId: config.SubscriptionId, request: new LogicProviderConfigurationRequestLogicProviderConfig( displayName: "SmsClientSampleLogicProvider", configuration: new LogicProviderConfig( description: "Logic Provider Test", smsServiceWindow: null))); Log.Information("Created provider config {@ProviderConfig}", resultLogicProvider); return((resultLogicProvider as ProviderConfigurationResponseLogicProviderConfig)?.ProviderConfigurationId ?? Guid.Empty); }
private static Guid SendBulkSms(CommandLineConfig config) { var client = GetApi(config); var sendSmsResult = client.SendBulkSms( subscriptionId: config.SubscriptionId, request: new SendBulkSmsRequest( toPhoneNumbers: CommandLineConfig.ToPhoneNumbers(), body: config.SmsBody, callbackUrl: $"{config.CallbackUri}", providerConfigurationId: config.ProviderConfigurationId, userData: config.UserData)); Log.Information("Sent bulk SMS and got result {@Result}", sendSmsResult); return((sendSmsResult as SendBulkSmsResponse)?.SmsMessageId ?? Guid.Empty); }
private static Guid CreateFakeConfiguration(CommandLineConfig config) { var client = GetApi(config); var createdConfiguration = client.CreateFakeSmsProviderConfiguration( subscriptionId: config.SubscriptionId, request: new FakeProviderConfigurationRequest( displayName: "My Fake Config", configuration: new FakeProviderConfig( fromPhoneNumber: "+61411000000", smsServiceWindow: null))); Log.Information("Created provider config {@ProviderConfig}", createdConfiguration); return((createdConfiguration as FakeProviderConfigProviderConfigurationResponse)?.ProviderConfigurationId ?? Guid.Empty); }
private static Guid CreateLinkMobilityProviderConfiguration(CommandLineConfig config) { var client = GetApi(config); var resultLinkMobilityProvider = client.CreateLinkMobilityProviderConfiguration( subscriptionId: config.SubscriptionId, request: new LinkMobilityProviderConfigProviderConfigurationRequest( displayName: "SmsClientSampleLinkMobility", new LinkMobilityProviderConfig( apiKey: config.LinkMobilityApiKey, sender: config.LinkMobilitySender), new SendTestSmsRequest( toPhoneNumber: config.ToPhoneNumber, body: config.SmsBody))); Log.Information("Created provider config {@ProviderConfig}", resultLinkMobilityProvider); return((resultLinkMobilityProvider as LinkMobilityProviderConfigProviderConfigurationResponse)?.ProviderConfigurationId ?? Guid.Empty); }
private static void GetSms(CommandLineConfig config) { var client = GetApi(config); if (config.SmsMessageId == Guid.Empty) { throw new Exception("You must specify an SMS ID with `--SmsMessageId=00000000-0000-0000-0000-000000000000`"); } if (config.SubscriptionId == Guid.Empty) { throw new Exception("You must specify a subscription with `--SubscriptionId=00000000-0000-0000-0000-000000000000`"); } var response = client.GetSms(config.SubscriptionId, config.SmsMessageId); Log.Information("Got SMS response: {@Sms}", response); }
private static ISmsClient GetApi(CommandLineConfig config) { if (string.IsNullOrEmpty(config.BearerToken)) { throw new Exception("You must specify a bearer token with `--BearerToken={YourToken}`"); } var credentials = new TokenCredentials(config.BearerToken); var client = new SmsClient(credentials); if (config.SmsApiBaseUri != null) { client.BaseUri = config.SmsApiBaseUri; } Log.Information("Created API with Base URI {BaseUri}", client.BaseUri); return(client); }
private static void SendSmsBatch(CommandLineConfig config) { var client = GetApi(config); var requestCorrelationId = $"|{Guid.NewGuid()}"; var customHeaders = new Dictionary <string, List <string> > { { "Request-Id", new List <string> { requestCorrelationId } }, }; var results = Enumerable .Range(1, config.NumberOfMessages) .AsParallel() .WithExecutionMode(ParallelExecutionMode.ForceParallelism) .WithDegreeOfParallelism(config.NumberOfThreads) .Select(i => client.SendSmsWithHttpMessagesAsync( subscriptionId: config.SubscriptionId, request: new SendSmsRequest( toPhoneNumber: config.ToPhoneNumber, body: config.SmsBody, callbackUrl: $"{config.CallbackUri}", providerConfigurationId: config.ProviderConfigurationId), customHeaders: customHeaders)) .Select(task => task.GetAwaiter().GetResult()) .ToArray(); var summary = new { RequestCorrelationId = requestCorrelationId, NumberOfMessages = results.Count(), StatusCodeCounts = results .GroupBy(r => r.Response.StatusCode) .Select(g => new { HttpStatusCode = g.Key, TotalCount = g.Count(), First3 = g.Take(3).Select(ResponseAsLogable).ToArray(), }) .ToArray(), }; Log.Information("Sent SMS with results {@Results}", summary); }
private static Guid CreateLinkMobilityCgiProviderConfiguration(CommandLineConfig config) { var client = GetApi(config); var resultLinkMobilityCgiProvider = client.CreateLinkMobilityCgiProviderConfiguration( subscriptionId: config.SubscriptionId, request: new LinkMobilityCgiProviderConfigProviderConfigurationRequest( displayName: "SmsClientSampleLinkMobilityCgi", new LinkMobilityCgiProviderConfig( userName: config.LinkMobilityCgiUserName, password: config.LinkMobilityCgiPassword, platformId: config.LinkMobilityCgiPlatformId, platformPartnerId: config.LinkMobilityCgiPlatformPartnerId, source: config.LinkMobilityCgiSource, smsServiceWindow: null), new SendTestSmsRequest( toPhoneNumber: config.ToPhoneNumber, body: config.SmsBody))); Log.Information("Created provider config {@ProviderConfig}", resultLinkMobilityCgiProvider); return((resultLinkMobilityCgiProvider as LinkMobilityCgiProviderConfigProviderConfigurationResponse)?.ProviderConfigurationId ?? Guid.Empty); }
private static Guid CreateTwilioConfiguration(CommandLineConfig config) { var client = GetApi(config); var resultTwilioProvider = client.CreateTwilioProviderConfiguration( subscriptionId: config.SubscriptionId, request: new TwilioProviderConfigProviderConfigurationRequest( displayName: "SmsClientSampleTwilio", new TwilioProviderConfig( username: config.TwilioUsername, password: config.TwilioPassword, accountSid: config.TwilioAccountSid, fromProperty: config.TwilioFromProperty, smsServiceWindow: null), new SendTestSmsRequest( toPhoneNumber: config.ToPhoneNumber, body: config.SmsBody))); Log.Information("Created provider config {@ProviderConfig}", resultTwilioProvider); return((resultTwilioProvider as TwilioProviderConfigProviderConfigurationResponse)?.ProviderConfigurationId ?? Guid.Empty); }