Skip to content

Commit

Permalink
Fix #96
Browse files Browse the repository at this point in the history
Added base template message creation object
  • Loading branch information
gabrieldwight committed Jun 25, 2024
1 parent 40af827 commit 63d51fc
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 19 deletions.
34 changes: 26 additions & 8 deletions WhatsappBusiness.CloudApi/Interfaces/IWhatsAppBusinessClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,14 +1241,32 @@ public interface IWhatsAppBusinessClient
/// <returns>Template Message Creation Response</returns>
Task<TemplateMessageCreationResponse> CreateTemplateMessageAsync(string whatsAppBusinessAccountId, object template, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default);

/// <summary>
/// Create Whatsapp template message
/// </summary>
/// <param name="whatsAppBusinessAccountId">Whatsapp Business Account Id</param>
/// <param name="template">Message template type</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Template Message Creation Response</returns>
TemplateMessageCreationResponse CreateTemplateMessage(string whatsAppBusinessAccountId, object template, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default);
/// <summary>
/// Create Whatsapp template message
/// </summary>
/// <param name="whatsAppBusinessAccountId">Whatsapp Business Account Id</param>
/// <param name="template">Message template type</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Template Message Creation Response</returns>
Task<TemplateMessageCreationResponse> CreateTemplateMessageAsync(string whatsAppBusinessAccountId, BaseCreateTemplateMessageRequest template, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default);

/// <summary>
/// Create Whatsapp template message
/// </summary>
/// <param name="whatsAppBusinessAccountId">Whatsapp Business Account Id</param>
/// <param name="template">Message template type</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Template Message Creation Response</returns>
TemplateMessageCreationResponse CreateTemplateMessage(string whatsAppBusinessAccountId, BaseCreateTemplateMessageRequest template, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default);

/// <summary>
/// Create Whatsapp template message
/// </summary>
/// <param name="whatsAppBusinessAccountId">Whatsapp Business Account Id</param>
/// <param name="template">Message template type</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Template Message Creation Response</returns>
TemplateMessageCreationResponse CreateTemplateMessage(string whatsAppBusinessAccountId, object template, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default);

/// <summary>
/// Get Whatsapp template message by namespace
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace WhatsappBusiness.CloudApi.Messages.Requests
{
public class BaseCreateTemplateMessageRequest
{
[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("category")]
public string Category { get; set; }

[JsonProperty("allow_category_change", NullValueHandling = NullValueHandling.Ignore)]
public bool? AllowCategoryChange { get; set; }

[JsonProperty("language")]
public string Language { get; set; }

[JsonProperty("library_template_name", NullValueHandling = NullValueHandling.Ignore)]
public string? LibraryTemplateName { get; set; }

[JsonProperty("LIBRARY_TEMPLATE_BUTTON_INPUTS", NullValueHandling = NullValueHandling.Ignore)]
public List<object>? LibraryTemplateButtonInputs { get; set; }

[JsonProperty("components")]
public List<object> Components { get; set; }
}
}
56 changes: 46 additions & 10 deletions WhatsappBusiness.CloudApi/WhatsAppBusinessClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,32 @@ public async Task<TemplateMessageCreationResponse> CreateTemplateMessageAsync(st
return await WhatsAppBusinessPostAsync<TemplateMessageCreationResponse>(template, formattedWhatsAppEndpoint, cancellationToken);
}

/// <summary>
/// <summary>
/// Create Whatsapp template message
/// </summary>
/// <param name="whatsAppBusinessAccountId">Whatsapp Business Account Id</param>
/// <param name="template">Message template type</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Template Message Creation Response</returns>
public TemplateMessageCreationResponse CreateTemplateMessage(string whatsAppBusinessAccountId, object template, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default)
public async Task<TemplateMessageCreationResponse> CreateTemplateMessageAsync(string whatsAppBusinessAccountId, BaseCreateTemplateMessageRequest template, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default)
{
if (cloudApiConfig is not null)
{
_whatsAppConfig = cloudApiConfig;
}

var formattedWhatsAppEndpoint = WhatsAppBusinessRequestEndpoint.CreateTemplateMessage.Replace("{{WABA-ID}}", whatsAppBusinessAccountId);
return await WhatsAppBusinessPostAsync<TemplateMessageCreationResponse>(template, formattedWhatsAppEndpoint, cancellationToken);
}

/// <summary>
/// Create Whatsapp template message
/// </summary>
/// <param name="whatsAppBusinessAccountId">Whatsapp Business Account Id</param>
/// <param name="template">Message template type</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Template Message Creation Response</returns>
public TemplateMessageCreationResponse CreateTemplateMessage(string whatsAppBusinessAccountId, object template, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default)
{
if (cloudApiConfig is not null)
{
Expand All @@ -342,14 +360,32 @@ public TemplateMessageCreationResponse CreateTemplateMessage(string whatsAppBusi
return WhatsAppBusinessPostAsync<TemplateMessageCreationResponse>(template, formattedWhatsAppEndpoint, cancellationToken).GetAwaiter().GetResult();
}

/// <summary>
/// To delete media, make a DELETE call to the ID of the media you want to delete.
/// </summary>
/// <param name="mediaId">ID for the media to send a media message or media template message to your customers.</param>
/// <param name="isMediaOwnershipVerified">Verify the media ownership using PHONE_NUMBER_ID</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>BaseSuccessResponse</returns>
public BaseSuccessResponse DeleteMedia(string mediaId, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, bool isMediaOwnershipVerified = false, CancellationToken cancellationToken = default)
/// <summary>
/// Create Whatsapp template message
/// </summary>
/// <param name="whatsAppBusinessAccountId">Whatsapp Business Account Id</param>
/// <param name="template">Message template type</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Template Message Creation Response</returns>
public TemplateMessageCreationResponse CreateTemplateMessage(string whatsAppBusinessAccountId, BaseCreateTemplateMessageRequest template, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default)
{
if (cloudApiConfig is not null)
{
_whatsAppConfig = cloudApiConfig;
}

var formattedWhatsAppEndpoint = WhatsAppBusinessRequestEndpoint.CreateTemplateMessage.Replace("{{WABA-ID}}", whatsAppBusinessAccountId);
return WhatsAppBusinessPostAsync<TemplateMessageCreationResponse>(template, formattedWhatsAppEndpoint, cancellationToken).GetAwaiter().GetResult();
}

/// <summary>
/// To delete media, make a DELETE call to the ID of the media you want to delete.
/// </summary>
/// <param name="mediaId">ID for the media to send a media message or media template message to your customers.</param>
/// <param name="isMediaOwnershipVerified">Verify the media ownership using PHONE_NUMBER_ID</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>BaseSuccessResponse</returns>
public BaseSuccessResponse DeleteMedia(string mediaId, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, bool isMediaOwnershipVerified = false, CancellationToken cancellationToken = default)
{
if (cloudApiConfig is not null)
{
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.32</Version>
<Version>1.0.33</Version>
</PropertyGroup>

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

0 comments on commit 63d51fc

Please sign in to comment.