gabrieldwight / Whatsapp-Business-Cloud-Api-Net

This is C# wrapper of whatsapp business cloud api for .NET
MIT License
298 stars 119 forks source link

Error on CreateTemplateMessageAsync #84

Closed tiagoserra closed 5 months ago

tiagoserra commented 5 months ago

Describe the bug When calling the CreateTemplateMessageAsync method, I receive an error WhatsappBusinessCloudAPIException: (#100) The parameter name is required.

Upon checking the code and implementation, I noticed that there is no body being sent in the request.

My call:

 var templateData = new
 {
     name = "teste_nome_template_01",
     category = "MARKETING",
     allow_category_change = false,
     language = "en_US",
     components = new List<object>()
     {
         new
         {
             type = "BODY",
             text = "Test",
             parameters = new[]
             {
                 new { type = "text", text = "test 01" }
             }
         },
         new
         {
             type = "BUTTONS",
             buttons= new List<object>()
             {
               new {
                 type = "PHONE_NUMBER",
                 text = "Call",
                 phone_number= "********************"
               }
             }
         },
         new
         {
             type = "FOOTER",
             text = "footer template"
         }
     }
 };

 var results = await _whatsAppBusinessClient.CreateTemplateMessageAsync("********************", templateData);

I believe the issue might be due to calling the WhatsAppBusinessPostAsync method without passing the template parameter, which due to overload, ends up invoking the wrong method.

 public async Task<TemplateMessageCreationResponse> CreateTemplateMessageAsync(string whatsAppBusinessAccountId, object template, CancellationToken cancellationToken = default(CancellationToken))
 {
     string whatsAppBusinessEndpoint = WhatsAppBusinessRequestEndpoint.CreateTemplateMessage.Replace("{{WABA-ID}}", whatsAppBusinessAccountId);
     return await WhatsAppBusinessPostAsync<TemplateMessageCreationResponse>(whatsAppBusinessEndpoint, cancellationToken);
 }
gabrieldwight commented 5 months ago

Hi, I have pushed the fix to pass the template parameter when calling the POST request.

tiagoserra commented 5 months ago

It's working