This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Add Text component and currency component
- Loading branch information
Showing
7 changed files
with
104 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { IGenericComponent } from "../@types"; | ||
import { IAPIRawDateTimeComponent } from "../@types/api"; | ||
|
||
export class DateTimeComponent implements IGenericComponent { | ||
public type: "header" | "body" = "body"; | ||
public fallbackValue: string = new Date().toString(); | ||
|
||
setType(type: "body" | "header"): this { | ||
this.type = type; | ||
|
||
return this; | ||
} | ||
|
||
setFallbackValue(fallbackValue: string | Date): this { | ||
this.fallbackValue = fallbackValue.toString(); | ||
|
||
return this; | ||
} | ||
|
||
// For some reason, I can't get this to work and the whatsapp reference documentation doesn't even mention this | ||
// I will remove it and test it later | ||
/* setDate(date: Date) { | ||
this.date = date; | ||
return this; | ||
} */ | ||
|
||
toAPIObject(): IAPIRawDateTimeComponent { | ||
return { | ||
type: this.type, | ||
parameters: [ | ||
{ | ||
type: "date_time", | ||
date_time: { | ||
fallback_value: this.fallbackValue, | ||
/* component: { | ||
calendar: "GREGORIAN", | ||
day_of_month: this.date.getDate(), | ||
day_of_week: this.date.getDay(), | ||
month: this.date.getMonth(), | ||
hour: this.date.getHours(), | ||
minute: this.date.getMinutes(), | ||
year: this.date.getFullYear(), | ||
}, See comment above */ | ||
}, | ||
}, | ||
], | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { IGenericComponent } from "../@types"; | ||
|
||
export class TextComponent implements IGenericComponent { | ||
public type: "body" | "header" | "button" = "body"; | ||
public text = ""; | ||
|
||
setType(type: "body" | "header" | "button"): this { | ||
this.type = type; | ||
|
||
return this; | ||
} | ||
|
||
setText(text: string): this { | ||
this.text = text; | ||
|
||
return this; | ||
} | ||
|
||
toAPIObject(): any { | ||
return { type: this.type, parameters: [{ type: "text", text: this.text }] }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters