Skip to content

Events

Events start a Bird or resume a Checkpoint. Use provider webhooks when the service can push changes, callbacks when a caller registers a supplied URL, and polling when the service must be queried.

The complete samples below compile with common SDK 2.17.0 and .NET 8. They use content examples rather than a TMS. Keep event method names stable after release so existing Birds can find them.

A [Webhook] method without a subscription handler exposes a callback URL after the Bird is published. This complete example accepts a JSON article payload and checks a shared token supplied in the event settings. An optional article ID also makes the event usable as a Checkpoint for one article.

using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Exceptions;
using Blackbird.Applications.Sdk.Common.Invocation;
using Blackbird.Applications.Sdk.Common.Webhooks;
namespace Apps.CallbackExample;
[WebhookList]
public class ArticleCallbacks : BaseInvocable
{
public ArticleCallbacks(InvocationContext context) : base(context) { }
[Webhook("On article ready", Description = "Receive an article for processing")]
public Task<WebhookResponse<ArticlePayload>> OnArticleReady(WebhookRequest request,
[WebhookParameter, Display("Shared token")] string token,
[WebhookParameter, Display("Article ID")] string? articleId = null)
{
if (string.IsNullOrWhiteSpace(token))
throw new PluginMisconfigurationException("Set a shared token for this callback.");
var supplied = request.Headers.FirstOrDefault(x =>
x.Key.Equals("Authorization", StringComparison.OrdinalIgnoreCase)).Value ?? "";
if (!CryptographicOperations.FixedTimeEquals(
Encoding.UTF8.GetBytes(supplied), Encoding.UTF8.GetBytes(token)))
return Ignore(HttpStatusCode.Unauthorized);
ArticlePayload? article;
try
{
article = JsonSerializer.Deserialize<ArticlePayload>(request.Body?.ToString() ?? "",
new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
}
catch (JsonException) { return Ignore(HttpStatusCode.BadRequest); }
if (article is null || string.IsNullOrWhiteSpace(article.Id))
return Ignore(HttpStatusCode.BadRequest);
if (articleId is not null && article.Id != articleId)
return Ignore(HttpStatusCode.NoContent);
return Task.FromResult(new WebhookResponse<ArticlePayload>
{
Result = article,
ReceivedWebhookRequestType = WebhookRequestType.Default
});
}
private static Task<WebhookResponse<ArticlePayload>> Ignore(HttpStatusCode status)
=> Task.FromResult(new WebhookResponse<ArticlePayload>
{
ReceivedWebhookRequestType = WebhookRequestType.Preflight,
HttpResponseMessage = new HttpResponseMessage(status)
});
}
public class ArticlePayload
{
[Display("Article ID")]
public string Id { get; set; } = string.Empty;
[Display("Title")]
public string Title { get; set; } = string.Empty;
[Display("Request ID")]
public string? RequestId { get; set; }
}

Send Authorization: <shared-token> to this sample callback; it does not use a Bearer prefix. Keep the token secret and use your provider’s signed-payload verification when implementing its webhook contract. Register the URL from the published Bird; retrieve it again after republishing or changing the event. Callback URL ownership and rotation follow the platform’s subscription lifecycle.

A synchronous webhook with no custom response returns 204 No Content by default. Preflight suppresses a Flight, for example for an irrelevant article, an authentication rejection, or a verification handshake.

For automatic registration, supply an IWebhookEventHandler type in the [Webhook] attribute. Implement SubscribeAsync to register values["payloadUrl"] at the provider, and UnsubscribeAsync to remove that subscription. Use the supplied credential providers to authenticate both operations. Match the registration, removal, and signature-verification logic to the provider’s API.

Keep any provider subscription identity recoverable so removal deletes the intended subscription. See the Template App handlers for provider-client structure.

Add the marker interface IAsyncWebhookHandler to the class carrying [WebhookList] when the provider can accept an immediate acknowledgement. Blackbird returns 202 Accepted first and processes the payload through a subscription-scoped queue afterwards. A subscription may serve several Birds.

The method still parses the payload and returns event outputs, but its HttpResponseMessage cannot change the response already sent to the provider. Keep a synchronous handler for verification challenges that need a calculated response. The authentication rejection in the callback sample above relies on a synchronous response.

Implement IAsyncValidatableWebhookEventHandler alongside IWebhookEventHandler when a provider subscription can expire or disappear. Its ValidateSubscription method receives the credentials and subscription values and returns a WebhookSubscriptionValidationResponse.

Query the provider’s subscription state. Return IsValid = true for a working subscription; otherwise return IsValid = false and an actionable Message. Blackbird suspends the Bird and records that message in its log and notification. See the validation frequency.

A task may complete just before the Checkpoint subscribes. Implement IAfterSubscriptionWebhookEventHandler<T> and OnWebhookSubscribedAsync to read the current object state immediately after subscribing. Return the matching completion when it already happened. Keep the same object-ID filters in this initial check and in later webhook processing.

Polling receives persisted memory and returns updated memory, a result, and FlyBird. Initialize a baseline on the first trigger poll so publishing does not replay old content. For a Checkpoint, also check whether the specified object has already reached its required state.

This complete sample uses a local article fixture to demonstrate detecting new IDs. Replace ReadArticles with a paginated, authenticated provider query for a real App.

using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Invocation;
using Blackbird.Applications.Sdk.Common.Polling;
namespace Apps.PollingExample;
[PollingEventList]
public class ArticlePolling : BaseInvocable
{
public ArticlePolling(InvocationContext context) : base(context) { }
[PollingEvent("On articles created", "Find newly created articles"), MultipleEvents]
public Task<PollingEventResponse<ArticleMemory, List<Article>>> OnArticlesCreated(
PollingEventRequest<ArticleMemory> request)
{
var current = ReadArticles();
var previousIds = request.Memory?.KnownIds.ToHashSet();
var added = previousIds is null ? new List<Article>()
: current.Where(article => !previousIds.Contains(article.Id)).ToList();
return Task.FromResult(new PollingEventResponse<ArticleMemory, List<Article>>
{
FlyBird = added.Count > 0,
Memory = new ArticleMemory { KnownIds = current.Select(x => x.Id).ToList() },
Result = added
});
}
private static List<Article> ReadArticles() =>
[new Article { Id = "article-1", Title = "Product launch" }];
}
public class ArticleMemory
{
public List<string> KnownIds { get; set; } = [];
}
public class Article
{
[Display("Article ID")]
public string Id { get; set; } = string.Empty;
[Display("Title")]
public string Title { get; set; } = string.Empty;
}

For larger providers, use an update timestamp or cursor rather than reading all content at every poll. Advance the cursor only after the relevant pages have been fetched successfully. Keep enough overlap and deduplication to handle records sharing a timestamp. See polling limits.

The [MultipleEvents] attribute on the polling sample starts one Flight per returned article when used as a trigger. An empty list starts no Flights. At a Checkpoint, the items remain a list. The attribute also works on webhook methods that return a list.

Test malformed payloads, rejected authentication, irrelevant object IDs, and a matching event. For polling, check the first-call baseline, an unchanged second poll, a new item, and provider pagination. Test the already-completed case before relying on an event as a Checkpoint. See the minimal App test harness for local invocation.