Skip to content

Conversation

@kzu
Copy link
Member

@kzu kzu commented Sep 20, 2025

Breaking change: we now require invoking UseWhatsApp on the functions app builder. We throw an exception if we detect it's misisng:

var builder = FunctionsApplication.CreateBuilder(args);
builder.ConfigureFunctionsWebApplication();
builder.UseWhatsApp();

When the user's handler pipeline was non-trivial to spin-up, webhook responses were delayed until the full DI graph for it was built.

We now instead make that dependency fully lazy so that the webhook can respond immediately and send the typing/read indicators as needed right-away.

Both pipeline runner and handler are changed to Func accordingly, and we had to bring the function context accessor to properly retrieve the instances from the right container at run-time in the isolated worker model.

@kzu kzu added the enhancement New feature or request label Sep 20, 2025
@kzu kzu requested a review from Copilot September 20, 2025 23:15
@kzu kzu enabled auto-merge (rebase) September 20, 2025 23:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements lazy initialization for WhatsApp webhook handlers to improve initial response times. The key change shifts from eager dependency resolution to lazy factory-based resolution, allowing webhooks to respond immediately while deferring handler pipeline initialization until needed.

  • Introduces mandatory UseWhatsApp() call on the functions application builder (breaking change)
  • Converts handler and pipeline runner dependencies to Func<T> factory delegates for lazy initialization
  • Adds function context accessor middleware to enable proper dependency resolution in isolated worker model

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
WhatsAppServiceCollectionExtensions.cs Adds validation for required middleware and registers lazy factory delegates
WhatsAppApplicationBuilderExtensions.cs New extension method to configure required WhatsApp middleware
FunctionContextAccessor.cs New middleware implementation for accessing function context in isolated worker
TaskSchedulerProcessor.cs Updates to use lazy factory for pipeline runner
PipelineRunner.cs Updates to use lazy factory for handler resolution
AzureFunctionsWebhook.cs Updates to use lazy factory for handler resolution
AzureFunctionsProcessors.cs Updates to use lazy factory for pipeline runner
AzureFunctionsConsole.cs Updates to use lazy factory for handler resolution
Program.cs Sample showing required UseWhatsApp() call
readme.md Documentation update for new required setup step

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@kzu
Copy link
Member Author

kzu commented Sep 20, 2025

70 passed 70 passed 20 skipped

🧪 Details on Ubuntu 24.04.3 LTS

from dotnet-retest v0.7.2 on .NET 9.0.9 with 💜 by @devlooped

Breaking change: we now *require* invoking UseWhatsApp on the functions app builder. We throw an exception if we detect it's misisng:

```
var builder = FunctionsApplication.CreateBuilder(args);
builder.ConfigureFunctionsWebApplication();
builder.UseWhatsApp();
```

When the user's handler pipeline was non-trivial to spin-up, webhook responses were delayed until the full DI graph for it was built.

We now instead make that dependency fully lazy so that the webhook can respond immediately and send the typing/read indicators as needed right-away.

Both pipeline runner and handler are changed to Func<T> accordingly, and we had to bring the function context accessor to properly retrieve the instances from the right container at run-time in the isolated worker model.
@kzu kzu merged commit b1323ee into main Sep 20, 2025
7 checks passed
@kzu kzu deleted the dev/middleware branch September 20, 2025 23:39
@devlooped devlooped locked and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants