Skip to content

Commit

Permalink
template generico
Browse files Browse the repository at this point in the history
  • Loading branch information
frkr committed Jan 15, 2024
1 parent bcf6562 commit 9561fc5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,38 @@ export async function sendMenu(auth: WAAuth, waid: string, menu: MenuRequest): P

return defaultFetch(auth, content);
}

export function templateGeneric(telefone: string, templ: string, namespace: string = null, ...args: string[]): MessageObjectRequest {
const ret: MessageObjectRequest = {
recipient_type: "individual",
messaging_product: "whatsapp",
to: telefone,
type: "template",
template: {
namespace: namespace,
name: templ,
language: {code: "pt_BR"},
components: [
{
type: 'body',
parameters: []
},
]
}
};
if (!namespace) {
delete ret.template.namespace;
}
if (!args || args.length === 0) {
delete ret.template.components;
} else {
ret.template.components[0].parameters = args.map(item => {
return {
type: 'text',
text: item,
};
});
}

return ret;
}

0 comments on commit 9561fc5

Please sign in to comment.