Skip to content

Commit 0eca172

Browse files
authored
Merge pull request #247 from Secreto31126/limited-time-offer
Added Limited-Time Offer component
2 parents 56575b9 + 16a3a86 commit 0eca172

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

EXAMPLES/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ the most basic methods or features.
4343
- [Complex template with reply buttons](template.md#complex-template-with-reply-buttons)
4444
- [Complex template with call to action url](template.md#complex-template-with-call-to-action-url)
4545
- [Complex template with Carousel](template.md#complex-template-with-carousel)
46+
- [Complex template with Limited-Time Offer](template.md#complex-template-with-limited-time-offer)
4647
- [OTP prefab template](template.md#otp-prefab-template)

EXAMPLES/template.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ import {
169169
URLComponent
170170
} from "whatsapp-api-js/messages";
171171

172-
const template_multi_product_message = new Template(
172+
const template_carousel_message = new Template(
173173
"template_name",
174174
"en",
175175
new BodyComponent(new BodyParameter("PROMO10")),
@@ -186,6 +186,25 @@ const template_multi_product_message = new Template(
186186
);
187187
```
188188

189+
## Complex template with Limited-Time Offer
190+
191+
```ts
192+
import {
193+
Template,
194+
LTOComponent,
195+
URLComponent,
196+
CopyComponent
197+
} from "whatsapp-api-js/messages";
198+
199+
const template_limited_time_offer_message = new Template(
200+
"template_name",
201+
"en",
202+
new LTOComponent(1696622508595),
203+
new CopyComponent("PROMO10"),
204+
new URLComponent("?code=PROMO10&product=1")
205+
);
206+
```
207+
189208
## OTP prefab template
190209

191210
```ts
@@ -205,3 +224,4 @@ https://whatsappapijs.web.app/classes/messages.CopyComponent.html
205224
https://whatsappapijs.web.app/classes/messages.CatalogComponent.html
206225
https://whatsappapijs.web.app/classes/messages.MPMComponent.html
207226
https://whatsappapijs.web.app/classes/messages.CarouselComponent.html
227+
https://whatsappapijs.web.app/classes/messages.LTOComponent.html

src/messages/template.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,3 +849,57 @@ export class CarouselCard implements ClientBuildableMessageComponent {
849849
return this;
850850
}
851851
}
852+
853+
/**
854+
* Components API object
855+
*
856+
* @group Template
857+
*/
858+
export class LTOComponent implements ClientBuildableMessageComponent {
859+
/**
860+
* The type of the component
861+
*/
862+
readonly type = "limited_time_offer";
863+
/**
864+
* The parameters of the component
865+
*/
866+
readonly parameters: [
867+
{
868+
type: "limited_time_offer";
869+
limited_time_offer: {
870+
expiration_time_ms: number;
871+
};
872+
}
873+
];
874+
875+
/**
876+
* Builds a limited-time offer component for a Template message
877+
*
878+
* @param expiration - Offer code expiration time as a UNIX timestamp in milliseconds
879+
* @throws If expiration is negative
880+
*/
881+
constructor(expiration: number) {
882+
if (expiration < 0) {
883+
throw new Error(
884+
"Expiration time must be a positive Unix timestamp"
885+
);
886+
}
887+
888+
this.parameters = [
889+
{
890+
type: "limited_time_offer",
891+
limited_time_offer: {
892+
expiration_time_ms: expiration
893+
}
894+
}
895+
];
896+
}
897+
898+
/**
899+
* @override
900+
* @internal
901+
*/
902+
_build() {
903+
return this;
904+
}
905+
}

0 commit comments

Comments
 (0)