Skip to content

Commit

Permalink
Merge pull request DaggieBlanqx#25 from alexcraviotto/main
Browse files Browse the repository at this point in the history
sendTemplate implemented
  • Loading branch information
DaggieBlanqx authored Sep 9, 2023
2 parents fafce75 + 40e4869 commit f2f6bb3
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ class WhatsappCloud {
}
};

this._mustHaveTemplateName = (templateName) => {
if (!templateName) {
throw new Error('"templateName" is required in making a request');
}
};
this._mustHaveComponents = (components) => {
if (!components) {
throw new Error('"components" is required in making a request');
}
};
this._mustHaveLanguageCode = (languageCode) => {
if (!languageCode) {
throw new Error('"languageCode" is required in making a request');
}
};
this._mustHaveMessageId = (messageId) => {
if (!messageId) {
throw new Error('"messageId" is required in making a request');
Expand Down Expand Up @@ -244,6 +259,33 @@ class WhatsappCloud {

return response;
}
async sendTemplate({templateName,languageCode,components,recipientPhone} ) {
this._mustHaverecipientPhone(recipientPhone);
this._mustHaveTemplateName(templateName);
this._mustHaveComponents(components)
this._mustHaveLanguageCode(languageCode)
let body = {
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": recipientPhone,
"type": "template",
"template": {
"name": templateName,
"language": {
"code": languageCode
},
"components": components
}
};

let response = await this._fetchAssistant({
url: '/messages',
method: 'POST',
body,
});

return response;
}

async markMessageAsRead({ message_id }) {
try {
Expand Down

0 comments on commit f2f6bb3

Please sign in to comment.