diff --git a/WhatsappBusiness.CloudApi/Interfaces/IWhatsAppBusinessClient.cs b/WhatsappBusiness.CloudApi/Interfaces/IWhatsAppBusinessClient.cs index bd48154..abdd887 100644 --- a/WhatsappBusiness.CloudApi/Interfaces/IWhatsAppBusinessClient.cs +++ b/WhatsappBusiness.CloudApi/Interfaces/IWhatsAppBusinessClient.cs @@ -1241,14 +1241,32 @@ public interface IWhatsAppBusinessClient /// Template Message Creation Response Task CreateTemplateMessageAsync(string whatsAppBusinessAccountId, object template, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default); - /// - /// Create Whatsapp template message - /// - /// Whatsapp Business Account Id - /// Message template type - /// Cancellation token - /// Template Message Creation Response - TemplateMessageCreationResponse CreateTemplateMessage(string whatsAppBusinessAccountId, object template, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default); + /// + /// Create Whatsapp template message + /// + /// Whatsapp Business Account Id + /// Message template type + /// Cancellation token + /// Template Message Creation Response + Task CreateTemplateMessageAsync(string whatsAppBusinessAccountId, BaseCreateTemplateMessageRequest template, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default); + + /// + /// Create Whatsapp template message + /// + /// Whatsapp Business Account Id + /// Message template type + /// Cancellation token + /// Template Message Creation Response + TemplateMessageCreationResponse CreateTemplateMessage(string whatsAppBusinessAccountId, BaseCreateTemplateMessageRequest template, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default); + + /// + /// Create Whatsapp template message + /// + /// Whatsapp Business Account Id + /// Message template type + /// Cancellation token + /// Template Message Creation Response + TemplateMessageCreationResponse CreateTemplateMessage(string whatsAppBusinessAccountId, object template, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default); /// /// Get Whatsapp template message by namespace diff --git a/WhatsappBusiness.CloudApi/Messages/Requests/BaseCreateTemplateMessageRequest.cs b/WhatsappBusiness.CloudApi/Messages/Requests/BaseCreateTemplateMessageRequest.cs new file mode 100644 index 0000000..8035813 --- /dev/null +++ b/WhatsappBusiness.CloudApi/Messages/Requests/BaseCreateTemplateMessageRequest.cs @@ -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? LibraryTemplateButtonInputs { get; set; } + + [JsonProperty("components")] + public List Components { get; set; } + } +} diff --git a/WhatsappBusiness.CloudApi/WhatsAppBusinessClient.cs b/WhatsappBusiness.CloudApi/WhatsAppBusinessClient.cs index 9f9f364..e011150 100644 --- a/WhatsappBusiness.CloudApi/WhatsAppBusinessClient.cs +++ b/WhatsappBusiness.CloudApi/WhatsAppBusinessClient.cs @@ -324,14 +324,32 @@ public async Task CreateTemplateMessageAsync(st return await WhatsAppBusinessPostAsync(template, formattedWhatsAppEndpoint, cancellationToken); } - /// + /// /// Create Whatsapp template message /// /// Whatsapp Business Account Id /// Message template type /// Cancellation token /// Template Message Creation Response - public TemplateMessageCreationResponse CreateTemplateMessage(string whatsAppBusinessAccountId, object template, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default) + public async Task 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(template, formattedWhatsAppEndpoint, cancellationToken); + } + + /// + /// Create Whatsapp template message + /// + /// Whatsapp Business Account Id + /// Message template type + /// Cancellation token + /// Template Message Creation Response + public TemplateMessageCreationResponse CreateTemplateMessage(string whatsAppBusinessAccountId, object template, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default) { if (cloudApiConfig is not null) { @@ -342,14 +360,32 @@ public TemplateMessageCreationResponse CreateTemplateMessage(string whatsAppBusi return WhatsAppBusinessPostAsync(template, formattedWhatsAppEndpoint, cancellationToken).GetAwaiter().GetResult(); } - /// - /// To delete media, make a DELETE call to the ID of the media you want to delete. - /// - /// ID for the media to send a media message or media template message to your customers. - /// Verify the media ownership using PHONE_NUMBER_ID - /// Cancellation token - /// BaseSuccessResponse - public BaseSuccessResponse DeleteMedia(string mediaId, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, bool isMediaOwnershipVerified = false, CancellationToken cancellationToken = default) + /// + /// Create Whatsapp template message + /// + /// Whatsapp Business Account Id + /// Message template type + /// Cancellation token + /// Template Message Creation Response + 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(template, formattedWhatsAppEndpoint, cancellationToken).GetAwaiter().GetResult(); + } + + /// + /// To delete media, make a DELETE call to the ID of the media you want to delete. + /// + /// ID for the media to send a media message or media template message to your customers. + /// Verify the media ownership using PHONE_NUMBER_ID + /// Cancellation token + /// BaseSuccessResponse + public BaseSuccessResponse DeleteMedia(string mediaId, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, bool isMediaOwnershipVerified = false, CancellationToken cancellationToken = default) { if (cloudApiConfig is not null) { diff --git a/WhatsappBusiness.CloudApi/WhatsappBusiness.CloudApi.csproj b/WhatsappBusiness.CloudApi/WhatsappBusiness.CloudApi.csproj index e555e07..719c311 100644 --- a/WhatsappBusiness.CloudApi/WhatsappBusiness.CloudApi.csproj +++ b/WhatsappBusiness.CloudApi/WhatsappBusiness.CloudApi.csproj @@ -12,7 +12,7 @@ https://github.com/gabrieldwight/Whatsapp-Business-Cloud-Api-Net enable latest - 1.0.32 + 1.0.33