private static void WebhookServerInitialization(IApplicationBuilder app, IConsumerOnlyCredentials consumerOnlyCredentials) { Plugins.Add <WebhooksPlugin>(); WebhookConfiguration = new WebhookConfiguration(consumerOnlyCredentials); app.UseTweetinviWebhooks(WebhookConfiguration); }
public async Task <IWebhookEnvironmentDTO[]> GetAllWebhooksAsync(IConsumerOnlyCredentials consumerCredentials) { var query = "https://api.twitter.com/1.1/account_activity/all/webhooks.json"; var result = _twitterAccessor.ExecuteQuery <IGetAllWebhooksResultDTO>(query, HttpMethod.GET, consumerCredentials, null); result?.Environments?.ForEach(environment => { environment.ConsumerCredentials = consumerCredentials; }); return(await Task.FromResult(result?.Environments)); }
/// <summary> /// Set the current thread credentials based on application only credentials. /// To execute http requests, application only credentials needs a bearer token. /// Setting the initializeBearerToken to true will initialize your credentials so that they are ready to be used. /// </summary> public static ITwitterCredentials SetApplicationOnlyCredentials(IConsumerOnlyCredentials consumerOnlyCredentials, bool initializeBearerToken = false) { Credentials = new TwitterCredentials(consumerOnlyCredentials.ConsumerKey, consumerOnlyCredentials.ConsumerSecret); Credentials.ApplicationOnlyBearerToken = consumerOnlyCredentials.ApplicationOnlyBearerToken; if (initializeBearerToken) { InitializeApplicationOnlyCredentials(Credentials); } return(Credentials); }
public async Task <IWebhookSubcriptionListDTO> GetListOfSubscriptionsAsync( string webhookEnvironmentName, IConsumerOnlyCredentials credentials) { var query = $"https://api.twitter.com/1.1/account_activity/all/{webhookEnvironmentName}/subscriptions/list.json"; var result = _twitterAccessor.ExecuteQuery(query, HttpMethod.GET, credentials); var subscriptions = _jsonObjectConverter.DeserializeObject <IWebhookSubcriptionListDTO>(result.Text); return(await Task.FromResult(subscriptions)); }
public AccountActivityRequestHandler( IWebhookDispatcher dispatcher, IWebhooksRoutes routes, IWebhooksHelper webhooksHelper, IFactory <AccountActivityStream> accountActivityStreamFactory, ITwitterClient client) { _dispatcher = dispatcher; _accountActivityStreamFactory = accountActivityStreamFactory; _router = new WebhookRouter(dispatcher, routes, webhooksHelper); _consumerOnlyCredentials = new ConsumerOnlyCredentials(client.Credentials); }
public async Task <bool> TryRouteRequestAsync(IWebhooksRequest request, IConsumerOnlyCredentials credentials) { var isCrcChallenge = _webhooksHelper.IsCrcChallenge(request); if (isCrcChallenge) { return(await _webhooksRoutes.TryToReplyToCrcChallengeAsync(request, credentials).ConfigureAwait(false)); } var jsonBody = await request.GetJsonFromBodyAsync().ConfigureAwait(false); _webhookDispatcher.WebhookMessageReceived(new WebhookMessage(jsonBody)); return(await Task.FromResult(true).ConfigureAwait(false)); }
private static async Task SubscribeToAllAccountActivities( IConsumerOnlyCredentials consumerOnlyCredentials, IWebhookEnvironmentDTO environment) { // If you wish to subscribe to the different account activity events you can do the following var subscriptions = await Webhooks.GetListOfSubscriptionsAsync(environment.Name, consumerOnlyCredentials); subscriptions.Subscriptions.ForEach(subscription => { var activityStream = Stream.CreateAccountActivityStream(subscription.UserId); activityStream.JsonObjectReceived += (sender, args) => { Console.WriteLine("json received : " + args.Json); }; WebhookConfiguration.AddActivityStream(activityStream); }); }
private static async Task RegisterAccountActivities(IConsumerOnlyCredentials consumerOnlyCredentials) { var webhookEnvironments = await Webhooks.GetAllWebhookEnvironmentsAsync(consumerOnlyCredentials); webhookEnvironments.ForEach(async environment => { var webhookEnvironment = new RegistrableWebhookEnvironment(environment) { Credentials = consumerOnlyCredentials }; WebhookConfiguration.AddWebhookEnvironment(webhookEnvironment); await SubscribeToAllAccountActivities(consumerOnlyCredentials, environment); }); }
public async Task <IGetWebhookSubscriptionsCountResultDTO> CountNumberOfSubscriptionsAsync( IConsumerOnlyCredentials credentials) { var query = "https://api.twitter.com/1.1/account_activity/subscriptions/count.json"; var result = _twitterAccessor.ExecuteQuery(query, HttpMethod.GET, credentials, null); if (result.StatusCode == 32) { return(null); } var subscriptionsCount = _jsonObjectConverter.DeserializeObject <IGetWebhookSubscriptionsCountResultDTO>(result.Text); return(await Task.FromResult(subscriptionsCount)); }
private async Task ReplyToCrcChallengeRequestAsync(string crcToken, IWebhooksRequest request, IConsumerOnlyCredentials credentials) { var crcResponseInfo = _webhooksHelper.CreateCrcResponseToken(crcToken, credentials.ConsumerSecret); await request.WriteInResponseAsync(crcResponseInfo.Json, crcResponseInfo.ContentType).ConfigureAwait(false); }
public async Task <bool> TryToReplyToCrcChallengeAsync(IWebhooksRequest request, IConsumerOnlyCredentials credentials) { var crcToken = request.GetQuery()["crc_token"]; if (crcToken.IsNullOrEmpty()) { return(false); } await ReplyToCrcChallengeRequestAsync(crcToken[0], request, credentials).ConfigureAwait(false); return(true); }
public T ExecuteQuery <T>(string query, HttpMethod method, IConsumerOnlyCredentials credentials, HttpContent httpContent) where T : class { return(ExecuteQuery <T>(query, method, new TwitterCredentials(credentials), httpContent)); }
// Consumer Credentials public IWebRequestResult ExecuteQuery(string query, HttpMethod method, IConsumerOnlyCredentials credentials, HttpContent httpContent) { return(ExecuteQuery(query, method, new TwitterCredentials(credentials), httpContent)); }
public static async Task <IWebhookSubcriptionListDTO> GetListOfSubscriptionsAsync(string webhookEnvironmentName, IConsumerOnlyCredentials credentials) { return(await WebhookController.GetListOfSubscriptionsAsync(webhookEnvironmentName, credentials)); }
public static async Task <IGetWebhookSubscriptionsCountResultDTO> CountNumberOfSubscriptionsAsync(IConsumerOnlyCredentials consumerCredentials) { return(await WebhookController.CountNumberOfSubscriptionsAsync(consumerCredentials)); }
public WebhookConfiguration(IConsumerOnlyCredentials consumerOnlyCredentials) : this() { ConsumerOnlyCredentials = consumerOnlyCredentials; }
public static async Task <IWebhookEnvironmentDTO[]> GetAllWebhookEnvironmentsAsync(IConsumerOnlyCredentials consumerCredentials) { return(await WebhookController.GetAllWebhooksAsync(consumerCredentials)); }
public static IWebRequestResult ExecuteConsumerQuery(string query, HttpMethod method, IConsumerOnlyCredentials credentials) { return(Accessor.ExecuteQuery(query, method, credentials, null)); }