Skip to content

Commit

Permalink
Fix for #84 to pass a template object to create a template message
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldwight committed Apr 29, 2024
1 parent ffe23a0 commit 4ef42a5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
52 changes: 43 additions & 9 deletions WhatsappBusiness.CloudApi/WhatsAppBusinessClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public async Task<BaseSuccessResponse> CreateWABASubscriptionAsync(string whatsA
public async Task<TemplateMessageCreationResponse> CreateTemplateMessageAsync(string whatsAppBusinessAccountId, object template, CancellationToken cancellationToken = default)
{
var formattedWhatsAppEndpoint = WhatsAppBusinessRequestEndpoint.CreateTemplateMessage.Replace("{{WABA-ID}}", whatsAppBusinessAccountId);
return await WhatsAppBusinessPostAsync<TemplateMessageCreationResponse>(formattedWhatsAppEndpoint, cancellationToken);
return await WhatsAppBusinessPostAsync<TemplateMessageCreationResponse>(template, formattedWhatsAppEndpoint, cancellationToken);
}

/// <summary>
Expand All @@ -219,7 +219,7 @@ public async Task<TemplateMessageCreationResponse> CreateTemplateMessageAsync(st
public TemplateMessageCreationResponse CreateTemplateMessage(string whatsAppBusinessAccountId, object template, CancellationToken cancellationToken = default)
{
var formattedWhatsAppEndpoint = WhatsAppBusinessRequestEndpoint.CreateTemplateMessage.Replace("{{WABA-ID}}", whatsAppBusinessAccountId);
return WhatsAppBusinessPostAsync<TemplateMessageCreationResponse>(formattedWhatsAppEndpoint, cancellationToken).GetAwaiter().GetResult();
return WhatsAppBusinessPostAsync<TemplateMessageCreationResponse>(template, formattedWhatsAppEndpoint, cancellationToken).GetAwaiter().GetResult();
}

/// <summary>
Expand Down Expand Up @@ -966,13 +966,47 @@ public TemplateByNameResponse GetTemplateByName(string whatsAppBusinessAccountId
return WhatsAppBusinessGetAsync<TemplateByNameResponse>(formattedWhatsAppEndpoint, cancellationToken).GetAwaiter().GetResult();
}

/// <summary>
/// List all the current app subscriptions to a given WhatsApp Business Account.
/// </summary>
/// <param name="whatsAppBusinessAccountId">Your WhatsApp Business Account (WABA) ID.</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>SubscribedAppsResponse</returns>
public SubscribedAppsResponse GetWABASubscribedApps(string whatsAppBusinessAccountId, CancellationToken cancellationToken = default)
/// <summary>
/// Get All templates for the whatsapp business account
/// </summary>
/// <param name="whatsAppBusinessAccountId">Whatsapp Business Account Id</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>TemplateResponse</returns>
public async Task<TemplateResponse> GetAllTemplatesAsync(string whatsAppBusinessAccountId, CancellationToken cancellationToken = default)
{
var builder = new StringBuilder();

builder.Append(WhatsAppBusinessRequestEndpoint.GetAllTemplateMessage);
builder.Replace("{{WABA-ID}}", whatsAppBusinessAccountId);

var formattedWhatsAppEndpoint = builder.ToString();
return await WhatsAppBusinessGetAsync<TemplateResponse>(formattedWhatsAppEndpoint, cancellationToken);
}

/// <summary>
/// Get All templates for the whatsapp business account
/// </summary>
/// <param name="whatsAppBusinessAccountId">Whatsapp Business Account Id</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>TemplateResponse</returns>
public TemplateResponse GetAllTemplates(string whatsAppBusinessAccountId, CancellationToken cancellationToken = default)
{
var builder = new StringBuilder();

builder.Append(WhatsAppBusinessRequestEndpoint.GetAllTemplateMessage);
builder.Replace("{{WABA-ID}}", whatsAppBusinessAccountId);

var formattedWhatsAppEndpoint = builder.ToString();
return WhatsAppBusinessGetAsync<TemplateResponse>(formattedWhatsAppEndpoint, cancellationToken).GetAwaiter().GetResult();
}

/// <summary>
/// List all the current app subscriptions to a given WhatsApp Business Account.
/// </summary>
/// <param name="whatsAppBusinessAccountId">Your WhatsApp Business Account (WABA) ID.</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>SubscribedAppsResponse</returns>
public SubscribedAppsResponse GetWABASubscribedApps(string whatsAppBusinessAccountId, CancellationToken cancellationToken = default)
{
var formattedWhatsAppEndpoint = WhatsAppBusinessRequestEndpoint.GetSubscribedApps.Replace("{{WABA-ID}}", whatsAppBusinessAccountId);
return WhatsAppBusinessGetAsync<SubscribedAppsResponse>(formattedWhatsAppEndpoint, cancellationToken).GetAwaiter().GetResult();
Expand Down
2 changes: 2 additions & 0 deletions WhatsappBusiness.CloudApi/WhatsAppBusinessRequestEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ public static class WhatsAppBusinessRequestEndpoint

public static string GetTemplateNamespace { get; private set; } = "{{WABA-ID}}?fields=message_template_namespace";

public static string GetAllTemplateMessage { get; private set; } = "{{WABA-ID}}/message_templates";

public static string CreateTemplateMessage { get; private set; } = "{{WABA-ID}}/message_templates";

public static string DeleteTemplateMessage { get; private set; } = "{{WABA-ID}}/message_templates?hsm_id={{HSM_ID}}&name={{NAME}}";
Expand Down
2 changes: 1 addition & 1 deletion WhatsappBusiness.CloudApi/WhatsappBusiness.CloudApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<RepositoryUrl>https://github.com/gabrieldwight/Whatsapp-Business-Cloud-Api-Net</RepositoryUrl>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<Version>1.0.27</Version>
<Version>1.0.28</Version>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' or '$(TargetFramework)' == 'netstandard2.1'">
Expand Down

0 comments on commit 4ef42a5

Please sign in to comment.