Skip to content

Commit 9103096

Browse files
committed
In development, run in a separate thread from webhook
The webhook needs to return almost immediately always, otherwise WhatsApp will start duplicating the calls.
1 parent a43a15c commit 9103096

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/WhatsApp/AzureFunctionsWebhook.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,25 @@ public async Task<IActionResult> Message([HttpTrigger(AuthorizationLevel.Anonymo
133133
await message.React(functionOptions.ReactOnMessage).SendAsync(whatsapp).Ignore();
134134

135135
if (hosting.IsDevelopment())
136-
// Process inline to speed up local devloop
137-
await runner.ProcessAsync(json);
136+
{
137+
// Avoid enqueing to speed up local devloop
138+
_ = Task.Run(async () =>
139+
{
140+
try
141+
{
142+
await runner.ProcessAsync(json);
143+
}
144+
catch (Exception e)
145+
{
146+
logger.LogError(e, "Failed to process message");
147+
}
148+
});
149+
}
138150
else
151+
{
139152
// Otherwise, enqueue the message processing
140153
await messageProcessor.EnqueueAsync(json);
154+
}
141155
}
142156
else
143157
{

0 commit comments

Comments
 (0)