66using Devlooped . WhatsApp ;
77using Microsoft . Extensions . Configuration ;
88using Microsoft . Extensions . DependencyInjection ;
9- using Microsoft . Extensions . Http . Resilience ;
109
1110namespace Microsoft . Azure . Functions . Worker . Builder ;
1211
@@ -15,19 +14,9 @@ namespace Microsoft.Azure.Functions.Worker.Builder;
1514/// </summary>
1615public static class AzureFunctionsExtensions
1716{
18- /// <summary>
19- /// Configure the WhatsApp handler for Azure Functions.
20- /// </summary>
21- public static IFunctionsWorkerApplicationBuilder UseWhatsApp ( this IFunctionsWorkerApplicationBuilder builder , Func < IServiceProvider , Message , Task > handler )
22- {
23- builder . Services . AddSingleton < IWhatsAppHandler > ( services => new AnonymousWhatsAppHandler ( services , handler ) ) ;
24- ConfigureServices ( builder . Services ) ;
25- return builder ;
26- }
27-
2817 static void ConfigureServices ( IServiceCollection services )
2918 {
30- services . AddHttpClient ( ) . ConfigureHttpClientDefaults ( http => http . AddStandardResilienceHandler ( ) ) ;
19+ services . AddHttpClient ( "whatsapp" ) . AddStandardResilienceHandler ( ) ;
3120 services . AddSingleton < IWhatsAppClient , WhatsAppClient > ( ) ;
3221
3322 if ( services . FirstOrDefault ( x => x . ServiceType == typeof ( QueueServiceClient ) ) == null )
@@ -79,6 +68,26 @@ public static IFunctionsWorkerApplicationBuilder UseWhatsApp<THandler>(this IFun
7968 return builder ;
8069 }
8170
71+ /// <summary>
72+ /// Configure the WhatsApp handler for Azure Functions.
73+ /// </summary>
74+ public static IFunctionsWorkerApplicationBuilder UseWhatsApp ( this IFunctionsWorkerApplicationBuilder builder , Func < IServiceProvider , Message , Task > handler )
75+ {
76+ builder . Services . AddSingleton < IWhatsAppHandler > ( services => new AnonymousWhatsAppHandler ( services , handler ) ) ;
77+ ConfigureServices ( builder . Services ) ;
78+ return builder ;
79+ }
80+
81+ /// <summary>
82+ /// Configure the WhatsApp handler for Azure Functions.
83+ /// </summary>
84+ public static IFunctionsWorkerApplicationBuilder UseWhatsApp ( this IFunctionsWorkerApplicationBuilder builder , Func < Message , Task > handler )
85+ {
86+ builder . Services . AddSingleton < IWhatsAppHandler > ( services => new SimpleAnonymousWhatsAppHandler ( handler ) ) ;
87+ ConfigureServices ( builder . Services ) ;
88+ return builder ;
89+ }
90+
8291 /// <summary>
8392 /// Configure the WhatsApp handler for Azure Functions.
8493 /// </summary>
@@ -160,6 +169,11 @@ public static IFunctionsWorkerApplicationBuilder UseWhatsApp<TService1, TService
160169 return builder ;
161170 }
162171
172+ class SimpleAnonymousWhatsAppHandler ( Func < Message , Task > handler ) : IWhatsAppHandler
173+ {
174+ public Task HandleAsync ( Message message ) => handler ( message ) ;
175+ }
176+
163177 class AnonymousWhatsAppHandler ( IServiceProvider services , Func < IServiceProvider , Message , Task > handler ) : IWhatsAppHandler
164178 {
165179 public Task HandleAsync ( Message message ) => handler ( services , message ) ;
0 commit comments