Replies: 7 comments
-
what about making buttons like something like a discord.js Embed class, so its acts like a builder |
Beta Was this translation helpful? Give feedback.
-
@MoonLGH I don't want to have to force users to use a whole class structure for an object without any methods. There are a lot of standards that are people are used to and I want to make open-wa accessible to the most types of devs out there. You can implement this on your own though: interface Button {
id: string,
text: string
}
class WButton implements Button{
id: string;
text: string;
constructor(id : string, text : string) {
this.id = id;
this.text = text
}
}
console.log(JSON.stringify(new WButton("id_1","Press"))) Might look into this for v5 if there's a large enough community demand for it. |
Beta Was this translation helpful? Give feedback.
-
how about there is a builder class and it accepts both Button and object |
Beta Was this translation helpful? Give feedback.
-
thinking about class ButtonBuilder implements Button {
id: string;
text: string;
constructor(id: string, text: string) {
this.id = id;
this.text = text;
}
setText(text: string) {
this.text = text;
}
setId(id: string) {
this.id = id;
}
toJson() {
if (!this.text || !this.id){
throw 'please put a valid text and id of the button';
}
return { text: this.text, id: this.id };
}
} then public async sendButtons(to: ChatId, body : string | LocationButtonBody, buttons : ButtonBuilder[]|Button[], title ?: string, footer ?: string) : Promise<boolean | MessageId> {
if(buttons[0] instancesOf WButton){
buttons = buttons.map((b) => b.toJson());
}
return await this.pup(
({ to, body, buttons, title, footer }) => {
return WAPI.sendButtons(to, body, buttons, title, footer);
},
{ to, body, buttons, title, footer }
) as Promise<boolean | MessageId>;
} |
Beta Was this translation helpful? Give feedback.
-
that way it accept both |
Beta Was this translation helpful? Give feedback.
-
@MoonLGH bring this up in the buttons channel so if people are interested in using a builder pattern. As long as the builder class implements the button interface then it should work without the change to |
Beta Was this translation helpful? Give feedback.
-
just made #2707 pr, tell me something if something wrong |
Beta Was this translation helpful? Give feedback.
-
SendButtons
feels so off when it says it accept Button[] but instead it accept an object
Beta Was this translation helpful? Give feedback.
All reactions