Skip to content

Commit

Permalink
Added implementation of carousel, coupon and catalog message
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldwight committed Sep 19, 2023
1 parent 3b41a83 commit e6229dd
Show file tree
Hide file tree
Showing 2 changed files with 217 additions and 1 deletion.
74 changes: 73 additions & 1 deletion WhatsappBusiness.CloudApi/Interfaces/IWhatsAppBusinessClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,79 @@ public interface IWhatsAppBusinessClient
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>WhatsAppResponse</returns>
WhatsAppResponse SendMPMTemplate(MultiProductTemplateMessageRequest multiProductTemplateMessageRequest, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default);
#endregion

/// <summary>
/// Send Catalog Template Message
/// </summary>
/// <param name="catalogTemplateMessageRequest">CatalogTemplateMessageRequest object</param>
/// <param name="cloudApiConfig">Custom WhatsAppBusinessCloudApiConfig</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>WhatsAppResponse</returns>
Task<WhatsAppResponse> SendCatalogMessageTemplateAsync(CatalogTemplateMessageRequest catalogTemplateMessageRequest, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default);

/// <summary>
/// Send Catalog Template Message
/// </summary>
/// <param name="catalogTemplateMessageRequest">CatalogTemplateMessageRequest object</param>
/// <param name="cloudApiConfig">Custom WhatsAppBusinessCloudApiConfig</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>WhatsAppResponse</returns>
WhatsAppResponse SendCatalogMessageTemplate(CatalogTemplateMessageRequest catalogTemplateMessageRequest, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default);

/// <summary>
/// Send Catalog Message
/// </summary>
/// <param name="catalogMessageRequest">CatalogMessageRequest object</param>
/// <param name="cloudApiConfig">Custom WhatsAppBusinessCloudApiConfig</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>WhatsAppResponse</returns>
Task<WhatsAppResponse> SendCatalogMessageAsync(CatalogMessageRequest catalogMessageRequest, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default);

/// <summary>
/// Send Catalog Message
/// </summary>
/// <param name="catalogMessageRequest">CatalogMessageRequest object</param>
/// <param name="cloudApiConfig">Custom WhatsAppBusinessCloudApiConfig</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>WhatsAppResponse</returns>
WhatsAppResponse SendCatalogMessage(CatalogMessageRequest catalogMessageRequest, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default);

/// <summary>
/// Send Carousel Template Message
/// </summary>
/// <param name="carouselTemplateMessageRequest">CarouselTemplateMessageRequest object</param>
/// <param name="cloudApiConfig">Custom WHatsAppBusinessCloudApiConfig</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>WhatsAppResponse</returns>
Task<WhatsAppResponse> SendCarouselMessageTemplateAsync(CarouselTemplateMessageRequest carouselTemplateMessageRequest, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default);

/// <summary>
/// Send Carousel Template Message
/// </summary>
/// <param name="carouselTemplateMessageRequest">CarouselTemplateMessageRequest object</param>
/// <param name="cloudApiConfig">Custom WHatsAppBusinessCloudApiConfig</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>WhatsAppResponse</returns>
WhatsAppResponse SendCarouselMessageTemplate(CarouselTemplateMessageRequest carouselTemplateMessageRequest, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default);

/// <summary>
/// Send Coupon Code Template Message
/// </summary>
/// <param name="couponCodeTemplateMessageRequest">CouponCodeTemplateMessageRequest object</param>
/// <param name="cloudApiConfig">Custom WhatsAppBusinessCloudApiConfig</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>WhatsAppResponse</returns>
Task<WhatsAppResponse> SendCouponCodeMessageTemplateAsync(CouponCodeTemplateMessageRequest couponCodeTemplateMessageRequest, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default);

/// <summary>
/// Send Coupon Code Template Message
/// </summary>
/// <param name="couponCodeTemplateMessageRequest">CouponCodeTemplateMessageRequest object</param>
/// <param name="cloudApiConfig">Custom WhatsAppBusinessCloudApiConfig</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>WhatsAppResponse</returns>
WhatsAppResponse SendCouponCodeMessageTemplate(CouponCodeTemplateMessageRequest couponCodeTemplateMessageRequest, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default);
#endregion

#region Two step verification code function
/// <summary>
Expand Down
144 changes: 144 additions & 0 deletions WhatsappBusiness.CloudApi/WhatsAppBusinessClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,150 @@ public WhatsAppResponse SendMPMTemplate(MultiProductTemplateMessageRequest multi
return WhatsAppBusinessPostAsync<WhatsAppResponse>(multiProductTemplateMessageRequest, formattedWhatsAppEndpoint, cancellationToken).GetAwaiter().GetResult();
}

/// <summary>
/// Send Catalog Template Message
/// </summary>
/// <param name="catalogTemplateMessageRequest">CatalogTemplateMessageRequest object</param>
/// <param name="cloudApiConfig">Custom WhatsAppBusinessCloudApiConfig</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>WhatsAppResponse</returns>
public async Task<WhatsAppResponse> SendCatalogMessageTemplateAsync(CatalogTemplateMessageRequest catalogTemplateMessageRequest, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default)
{
if (cloudApiConfig is not null)
{
_whatsAppConfig = cloudApiConfig;
}

var formattedWhatsAppEndpoint = WhatsAppBusinessRequestEndpoint.SendMessage.Replace("{{Phone-Number-ID}}", _whatsAppConfig.WhatsAppBusinessPhoneNumberId);
return await WhatsAppBusinessPostAsync<WhatsAppResponse>(catalogTemplateMessageRequest, formattedWhatsAppEndpoint, cancellationToken);
}

/// <summary>
/// Send Catalog Template Message
/// </summary>
/// <param name="catalogTemplateMessageRequest">CatalogTemplateMessageRequest object</param>
/// <param name="cloudApiConfig">Custom WhatsAppBusinessCloudApiConfig</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>WhatsAppResponse</returns>
public WhatsAppResponse SendCatalogMessageTemplate(CatalogTemplateMessageRequest catalogTemplateMessageRequest, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default)
{
if (cloudApiConfig is not null)
{
_whatsAppConfig = cloudApiConfig;
}

var formattedWhatsAppEndpoint = WhatsAppBusinessRequestEndpoint.SendMessage.Replace("{{Phone-Number-ID}}", _whatsAppConfig.WhatsAppBusinessPhoneNumberId);
return WhatsAppBusinessPostAsync<WhatsAppResponse>(catalogTemplateMessageRequest, formattedWhatsAppEndpoint, cancellationToken).GetAwaiter().GetResult();
}

/// <summary>
/// Send Catalog Message
/// </summary>
/// <param name="catalogMessageRequest">CatalogMessageRequest object</param>
/// <param name="cloudApiConfig">Custom WhatsAppBusinessCloudApiConfig</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>WhatsAppResponse</returns>
public async Task<WhatsAppResponse> SendCatalogMessageAsync(CatalogMessageRequest catalogMessageRequest, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default)
{
if (cloudApiConfig is not null)
{
_whatsAppConfig = cloudApiConfig;
}

var formattedWhatsAppEndpoint = WhatsAppBusinessRequestEndpoint.SendMessage.Replace("{{Phone-Number-ID}}", _whatsAppConfig.WhatsAppBusinessPhoneNumberId);
return await WhatsAppBusinessPostAsync<WhatsAppResponse>(catalogMessageRequest, formattedWhatsAppEndpoint, cancellationToken);
}

/// <summary>
/// Send Catalog Message
/// </summary>
/// <param name="catalogMessageRequest">CatalogMessageRequest object</param>
/// <param name="cloudApiConfig">Custom WhatsAppBusinessCloudApiConfig</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>WhatsAppResponse</returns>
public WhatsAppResponse SendCatalogMessage(CatalogMessageRequest catalogMessageRequest, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default)
{
if (cloudApiConfig is not null)
{
_whatsAppConfig = cloudApiConfig;
}

var formattedWhatsAppEndpoint = WhatsAppBusinessRequestEndpoint.SendMessage.Replace("{{Phone-Number-ID}}", _whatsAppConfig.WhatsAppBusinessPhoneNumberId);
return WhatsAppBusinessPostAsync<WhatsAppResponse>(catalogMessageRequest, formattedWhatsAppEndpoint, cancellationToken).GetAwaiter().GetResult();
}

/// <summary>
/// Send Carousel Template Message
/// </summary>
/// <param name="carouselTemplateMessageRequest">CarouselTemplateMessageRequest object</param>
/// <param name="cloudApiConfig">Custom WHatsAppBusinessCloudApiConfig</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>WhatsAppResponse</returns>
public async Task<WhatsAppResponse> SendCarouselMessageTemplateAsync(CarouselTemplateMessageRequest carouselTemplateMessageRequest, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default)
{
if (cloudApiConfig is not null)
{
_whatsAppConfig = cloudApiConfig;
}

var formattedWhatsAppEndpoint = WhatsAppBusinessRequestEndpoint.SendMessage.Replace("{{Phone-Number-ID}}", _whatsAppConfig.WhatsAppBusinessPhoneNumberId);
return await WhatsAppBusinessPostAsync<WhatsAppResponse>(carouselTemplateMessageRequest, formattedWhatsAppEndpoint, cancellationToken);
}

/// <summary>
/// Send Carousel Template Message
/// </summary>
/// <param name="carouselTemplateMessageRequest">CarouselTemplateMessageRequest object</param>
/// <param name="cloudApiConfig">Custom WHatsAppBusinessCloudApiConfig</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>WhatsAppResponse</returns>
public WhatsAppResponse SendCarouselMessageTemplate(CarouselTemplateMessageRequest carouselTemplateMessageRequest, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default)
{
if (cloudApiConfig is not null)
{
_whatsAppConfig = cloudApiConfig;
}

var formattedWhatsAppEndpoint = WhatsAppBusinessRequestEndpoint.SendMessage.Replace("{{Phone-Number-ID}}", _whatsAppConfig.WhatsAppBusinessPhoneNumberId);
return WhatsAppBusinessPostAsync<WhatsAppResponse>(carouselTemplateMessageRequest, formattedWhatsAppEndpoint, cancellationToken).GetAwaiter().GetResult();
}

/// <summary>
/// Send Coupon Code Template Message
/// </summary>
/// <param name="couponCodeTemplateMessageRequest">CouponCodeTemplateMessageRequest object</param>
/// <param name="cloudApiConfig">Custom WhatsAppBusinessCloudApiConfig</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>WhatsAppResponse</returns>
public async Task<WhatsAppResponse> SendCouponCodeMessageTemplateAsync(CouponCodeTemplateMessageRequest couponCodeTemplateMessageRequest, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default)
{
if (cloudApiConfig is not null)
{
_whatsAppConfig = cloudApiConfig;
}

var formattedWhatsAppEndpoint = WhatsAppBusinessRequestEndpoint.SendMessage.Replace("{{Phone-Number-ID}}", _whatsAppConfig.WhatsAppBusinessPhoneNumberId);
return await WhatsAppBusinessPostAsync<WhatsAppResponse>(couponCodeTemplateMessageRequest, formattedWhatsAppEndpoint, cancellationToken);
}

/// <summary>
/// Send Coupon Code Template Message
/// </summary>
/// <param name="couponCodeTemplateMessageRequest">CouponCodeTemplateMessageRequest object</param>
/// <param name="cloudApiConfig">Custom WhatsAppBusinessCloudApiConfig</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>WhatsAppResponse</returns>
public WhatsAppResponse SendCouponCodeMessageTemplate(CouponCodeTemplateMessageRequest couponCodeTemplateMessageRequest, WhatsAppBusinessCloudApiConfig? cloudApiConfig = null, CancellationToken cancellationToken = default)
{
if (cloudApiConfig is not null)
{
_whatsAppConfig = cloudApiConfig;
}

var formattedWhatsAppEndpoint = WhatsAppBusinessRequestEndpoint.SendMessage.Replace("{{Phone-Number-ID}}", _whatsAppConfig.WhatsAppBusinessPhoneNumberId);
return WhatsAppBusinessPostAsync<WhatsAppResponse>(couponCodeTemplateMessageRequest, formattedWhatsAppEndpoint, cancellationToken).GetAwaiter().GetResult();
}

/// <summary>
/// You can use this endpoint to change two-step verification code associated with your account. After you change the verification code, future requests like changing the name, must use the new code.
/// You set up two-factor verification and register a phone number in the same API call.
Expand Down

0 comments on commit e6229dd

Please sign in to comment.