A simple project for registering and handling Calendly event webhooks.
- Add
CalendlyEventWebhook
reference to your project. - Use the
IServiceCollection.AddCalendlyEventWebhook
method in theConfigureServices
method of yourStartup
class.
This will add services required for creating/removing webhook subscriptions and handling Calendly requests. - Use the
IEndpointRouteBuilder.MapCalendlyWebhook
method in theConfigure
method of yourStartup
class.
This will map the route specified inWebhook.CallbackUrl
configuration property to a middleware that handles requests from Calendly. - Add configuration to your configuration file (e.g.
appsettings.json
). - Implement
IEventCancellationHandler
,IEventReschedulingHandler
, andIEventCreationHandler
interfaces whose methods will be called when a matching event is sent from Calendly.
Example:
Host.CreateDefaultBuilder(args)
.ConfigureWebHost(
webHost =>
{
webHost.Configure(
app =>
{
app.UseRouting();
app.UseEndpoints(endpoints => endpoints.MapCalendlyWebhook());
});
})
.ConfigureServices(
(context, services) =>
{
services.AddRouting();
services.AddCalendlyEventWebhook(context.Configuration);
});
internal class EventCancellationHandler : IEventCancellationHandler
{
private readonly ILogger<EventCancellationHandler> _logger;
public EventCancellationHandler(ILogger<EventCancellationHandler> logger)
{
_logger = logger;
}
public Task<bool> Handle(CalendlyResourceIdentifier id)
{
_logger.LogInformation("Event {EventId} cancelled", id.Id);
return Task.FromResult(true);
}
}
The configuration object must be placed in CalendlyEventWebhook
section. The following settings are available:
AccessToken
(required) - the Personal Access Token used to authenticate with CalendlyScope
-User
(default) orOrganisation
- dictates whether the webhook subscriptions should be scoped to a user or the whole organisationWebhook
object:CallbackUrl
(required) - the URL which will be used by Calendly to publish event updatesSigningKey
- secret key shared between your application and Calendly used to verify origin of incoming requestsCleanupAllExistingWebhooks
-false
(default) ortrue
- iftrue
, all existing webhook subscriptions will be removed from CalendlySkipWebhookCreation
-false
(default) ortrue
- iftrue
, no webhook subscription will be created for givenCallbackUrl
EventCreation
-false
(default) ortrue
- iftrue
, the webhook subscription will include event creation events
Webhook subscription creation/removal will happen at the startup of your application thanks to an IHostedService
worker.
If both CleanupAllExistingWebhooks
and SkipWebhookCreation
are set to true
the worker will not be registered with
the DI container.
The dependency on Newtonsoft.Json
allows (de)serializing custom enum member values.