diff --git a/packages/conversation/src/models/v1/choice-item/choice-item.ts b/packages/conversation/src/models/v1/choice-item/choice-item.ts index 63aef533..5af2fb52 100644 --- a/packages/conversation/src/models/v1/choice-item/choice-item.ts +++ b/packages/conversation/src/models/v1/choice-item/choice-item.ts @@ -1,12 +1,12 @@ import { MediaMessageItem } from '../media-message'; -export interface ChoiceItem { +export interface ChoiceItemWrapper { /** A message component for interactive messages, containing a choice. */ - choice: ChoiceItemItem; + choice: ChoiceItem; } -export interface ChoiceItemItem { +export interface ChoiceItem { /** Required parameter. Title for the choice item. */ title: string; diff --git a/packages/conversation/src/models/v1/choice-item/index.ts b/packages/conversation/src/models/v1/choice-item/index.ts index 9bb775aa..b9fdc728 100644 --- a/packages/conversation/src/models/v1/choice-item/index.ts +++ b/packages/conversation/src/models/v1/choice-item/index.ts @@ -1 +1 @@ -export type { ChoiceItem, ChoiceItemItem } from './choice-item'; +export type { ChoiceItemWrapper, ChoiceItem } from './choice-item'; diff --git a/packages/conversation/src/models/v1/helper.ts b/packages/conversation/src/models/v1/helper.ts index 724a58b2..75b577f0 100644 --- a/packages/conversation/src/models/v1/helper.ts +++ b/packages/conversation/src/models/v1/helper.ts @@ -8,6 +8,8 @@ import { MediaMessage, MediaMessageItem } from './media-message'; import { TemplateMessage, TemplateMessageItem } from './template-message'; import { ListMessage, ListMessageItem } from './list-message'; import { V2TemplateTranslation } from './v2-template-translation'; +import { ChoiceItem, ChoiceItemWrapper } from './choice-item'; +import { ProductItem, ProductItemWrapper } from './product-item'; export const messageBuilder = { card: (cardMessageItem: CardMessageItem): CardMessage => { @@ -178,6 +180,19 @@ export const templateV2Helper = { }, }; +export const listSectionHelper = { + buildChoiceItem: (choiceItem: ChoiceItem): ChoiceItemWrapper => { + return { + choice: choiceItem, + }; + }, + buildProductItem: (productItem: ProductItem): ProductItemWrapper => { + return { + product: productItem, + }; + }, +}; + export const enum MessageType { CARD = 'CardMessage', CAROUSEL = 'CarouselMessage', diff --git a/packages/conversation/src/models/v1/index.ts b/packages/conversation/src/models/v1/index.ts index 89982cdf..a391a3ec 100644 --- a/packages/conversation/src/models/v1/index.ts +++ b/packages/conversation/src/models/v1/index.ts @@ -17,6 +17,7 @@ export * from './channel-recipient-identity'; export * from './channel-specific-contact-message'; export * from './channel-specific-message'; export * from './choice'; +export * from './choice-item'; export * from './choice-message'; export * from './choice-response-message'; export * from './client-credentials'; @@ -62,7 +63,7 @@ export * from './media-carousel-message'; export * from './media-message'; export * from './merge-contact-request'; export * from './message-retry-settings'; -export * from './product'; +export * from './product-item'; export * from './product-response-message'; export * from './error-detail'; export * from './lookup-capability-request'; diff --git a/packages/conversation/src/models/v1/list-section/list-section.ts b/packages/conversation/src/models/v1/list-section/list-section.ts index 2c621dae..99bffca0 100644 --- a/packages/conversation/src/models/v1/list-section/list-section.ts +++ b/packages/conversation/src/models/v1/list-section/list-section.ts @@ -1,5 +1,5 @@ -import { ChoiceItem } from '../choice-item'; -import { Product } from '../product'; +import { ChoiceItemWrapper } from '../choice-item'; +import { ProductItemWrapper } from '../product-item'; /** * Section for interactive WhatsApp messages containing ListItem @@ -9,5 +9,5 @@ export interface ListSection { /** Optional parameter. Title for list section. */ title?: string; /** List of ListItems */ - items?: ChoiceItem[] | Product[]; + items?: ChoiceItemWrapper[] | ProductItemWrapper[]; } diff --git a/packages/conversation/src/models/v1/product-item/index.ts b/packages/conversation/src/models/v1/product-item/index.ts new file mode 100644 index 00000000..8783476e --- /dev/null +++ b/packages/conversation/src/models/v1/product-item/index.ts @@ -0,0 +1 @@ +export type { ProductItemWrapper, ProductItem } from './product-item'; diff --git a/packages/conversation/src/models/v1/product/product.ts b/packages/conversation/src/models/v1/product-item/product-item.ts similarity index 94% rename from packages/conversation/src/models/v1/product/product.ts rename to packages/conversation/src/models/v1/product-item/product-item.ts index b6882ccf..9ac69e15 100644 --- a/packages/conversation/src/models/v1/product/product.ts +++ b/packages/conversation/src/models/v1/product-item/product-item.ts @@ -1,7 +1,7 @@ /** * A message component for interactive messages, containing a product. */ -export interface Product { +export interface ProductItemWrapper { /** A message component for interactive messages, containing a product. */ product?: ProductItem; diff --git a/packages/conversation/src/models/v1/product-response-message/product-response-message.ts b/packages/conversation/src/models/v1/product-response-message/product-response-message.ts index eeb8c41e..bc974dd6 100644 --- a/packages/conversation/src/models/v1/product-response-message/product-response-message.ts +++ b/packages/conversation/src/models/v1/product-response-message/product-response-message.ts @@ -1,4 +1,4 @@ -import { ProductItem } from '../product'; +import { ProductItem } from '../product-item'; /** * Represents an interactive WhatsApp message containing ProductItem objects diff --git a/packages/conversation/src/models/v1/product/index.ts b/packages/conversation/src/models/v1/product/index.ts deleted file mode 100644 index 510807c8..00000000 --- a/packages/conversation/src/models/v1/product/index.ts +++ /dev/null @@ -1 +0,0 @@ -export type { Product, ProductItem } from './product'; diff --git a/packages/conversation/tests/messages-mocks.ts b/packages/conversation/tests/messages-mocks.ts index 294f64a5..3b22953e 100644 --- a/packages/conversation/tests/messages-mocks.ts +++ b/packages/conversation/tests/messages-mocks.ts @@ -168,6 +168,34 @@ export const templateMessage: Conversation.TemplateMessage = { template_message: templateMessageItem, }; +export const strawberryChoiceDetails: Conversation.ChoiceItem = { + title: 'Strawberry', + postback_data: 'Strawberry postback', +}; + +export const blueberryChoiceDetails: Conversation.ChoiceItem = { + title: 'Blueberry', + postback_data: 'Blueberry postback', +}; + +export const chocolateChoiceDetails: Conversation.ChoiceItem = { + title: 'Chocolate', + postback_data: 'Chocolate postback', +}; + +export const vanillaChoiceDetails: Conversation.ChoiceItem = { + title: 'Vanilla', + postback_data: 'Vanilla postback', +}; + +export const bookProductDetails: Conversation.ProductItem = { + id: '2351786092', + marketplace: 'bashi-bouzouk', + item_price: 12, + currency: 'EUR', + quantity: 1, +}; + export const listMessageItem: Conversation.ListMessageItem = { title: 'Choose your icecream flavor', description: 'The best icecream in town!', @@ -175,35 +203,15 @@ export const listMessageItem: Conversation.ListMessageItem = { { title: 'Fruit flavors', items: [ - { - choice: { - title: 'Strawberry', - postback_data: 'Strawberry postback', - }, - }, - { - choice: { - title: 'Blueberry', - postback_data: 'Blueberry postback', - }, - }, + Conversation.listSectionHelper.buildChoiceItem(strawberryChoiceDetails), + Conversation.listSectionHelper.buildChoiceItem(blueberryChoiceDetails), ], }, { title: 'Other flavors', items: [ - { - choice: { - title: 'Chocolate', - postback_data: 'Chocolate postback', - }, - }, - { - choice: { - title: 'Vanilla', - postback_data: 'Vanilla postback', - }, - }, + Conversation.listSectionHelper.buildChoiceItem(chocolateChoiceDetails), + Conversation.listSectionHelper.buildChoiceItem(vanillaChoiceDetails), ], }, ], diff --git a/packages/conversation/tests/models/v1/helper.test.ts b/packages/conversation/tests/models/v1/helper.test.ts index e68fd1cd..fd4c61ec 100644 --- a/packages/conversation/tests/models/v1/helper.test.ts +++ b/packages/conversation/tests/models/v1/helper.test.ts @@ -18,6 +18,8 @@ import { templateMessageItem, textMessageItem, textMessage, + strawberryChoiceDetails, + bookProductDetails, } from '../../messages-mocks'; describe('Conversation models helpers', () => { @@ -249,4 +251,31 @@ describe('Conversation models helpers', () => { }); }); + describe('List Section helper', () => { + it('should build a ChoiceItemWrapper', () => { + const strawberryChoiceItem: Conversation.ChoiceItemWrapper = { + choice: { + title: 'Strawberry', + postback_data: 'Strawberry postback', + }, + }; + const builtItemWrapper = Conversation.listSectionHelper.buildChoiceItem(strawberryChoiceDetails); + expect(builtItemWrapper).toEqual(strawberryChoiceItem); + }); + + it('should build a ProductItemWrapper', () => { + const bookProductItem: Conversation.ProductItemWrapper = { + product: { + id: '2351786092', + marketplace: 'bashi-bouzouk', + item_price: 12, + currency: 'EUR', + quantity: 1, + }, + }; + const builtItemWrapper = Conversation.listSectionHelper.buildProductItem(bookProductDetails); + expect(builtItemWrapper).toEqual(bookProductItem); + }); + }); + });