public virtual async Task PublishAsync(int?[] tenantIds, string webhookName, object data, bool sendExactSameData = false, WebhookHeader headers = null) { var subscriptions = await _webhookSubscriptionManager.GetAllSubscriptionsOfTenantsIfFeaturesGrantedAsync(tenantIds, webhookName); await PublishAsync(webhookName, data, subscriptions, sendExactSameData, headers); }
private async Task PublishAsync(string webhookName, object data, List <WebhookSubscription> webhookSubscriptions, bool sendExactSameData = false, WebhookHeader headers = null) { if (webhookSubscriptions.IsNullOrEmpty()) { return; } var subscriptionsGroupedByTenant = webhookSubscriptions.GroupBy(x => x.TenantId); foreach (var subscriptionGroupedByTenant in subscriptionsGroupedByTenant) { var webhookInfo = await SaveAndGetWebhookAsync(subscriptionGroupedByTenant.Key, webhookName, data); foreach (var webhookSubscription in subscriptionGroupedByTenant) { var headersToSend = webhookSubscription.Headers; if (headers != null) { if (headers.UseOnlyGivenHeaders)//do not use the headers defined in subscription { headersToSend = headers.Headers; } else { //use the headers defined in subscription. If additional headers has same header, use additional headers value. foreach (var additionalHeader in headers.Headers) { headersToSend[additionalHeader.Key] = additionalHeader.Value; } } } await _backgroundJobManager.EnqueueAsync <WebhookSenderJob, WebhookSenderArgs>(new WebhookSenderArgs { TenantId = webhookSubscription.TenantId, WebhookEventId = webhookInfo.Id, Data = webhookInfo.Data, WebhookName = webhookInfo.WebhookName, WebhookSubscriptionId = webhookSubscription.Id, Headers = headersToSend, Secret = webhookSubscription.Secret, WebhookUri = webhookSubscription.WebhookUri, SendExactSameData = sendExactSameData }); } } }
public virtual void Publish(int?[] tenantIds, string webhookName, object data, bool sendExactSameData = false, WebhookHeader headers = null) { var subscriptions = _webhookSubscriptionManager.GetAllSubscriptionsOfTenantsIfFeaturesGranted(tenantIds, webhookName); Publish(webhookName, data, subscriptions, sendExactSameData, headers); }