Skip to content

Commit 9d9c938

Browse files
committed
Improved readability of Template components build
1 parent ecc1531 commit 9d9c938

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

types/template.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,9 @@ class Template {
2323
if (!name) throw new Error("Template must have a name");
2424
if (!language) throw new Error("Template must have a language");
2525

26-
const temp = [];
27-
for (let component of components) {
28-
if (component instanceof ButtonComponent) temp.push(...component.build());
29-
else temp.push(component);
30-
}
31-
components = temp;
32-
3326
this.name = name;
3427
this.language = language instanceof Language ? language : new Language(language);
35-
if (components) this.components = components;
28+
if (components) this.components = components.map(c => c.build ? c.build() : c).flat();;
3629

3730
this._ = "template";
3831
}
@@ -233,7 +226,7 @@ class Parameter {
233226
* For Document parameter, only PDF documents are supported for document-based message templates.
234227
*
235228
* @param {(Text|Currency|DateTime|Image|Document|Video)} parameter The parameter to be used in the template
236-
* @param {String} [whoami] The parent component, used to check if a Text object is too long. Can be either 'header' or 'body'
229+
* @param {String} whoami The parent component, used to check if a Text object is too long. Can be either 'header' or 'body'
237230
* @throws {Error} If parameter is not provided
238231
* @throws {Error} If parameter is a Text and the parent component (whoami) is "header" and the text over 60 characters
239232
* @throws {Error} If parameter is a Text and the parent component (whoami) is "body" and the text over 1024 characters

0 commit comments

Comments
 (0)