Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sticker id feature update #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,20 @@ await Whatsapp.sendContact({
});
```

#### Send stickers to the recipient

```js
await Whatsapp.sendSimpleButtons({
recipientPhone: 'your recipient phone number here',
message: `How may I help you today`,
sticker: [
{
id: 'banana_12',
},
],
});
```

##### Generate a QR code which can be scanned by a recipient:

```js
Expand Down
73 changes: 52 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ class WhatsappCloud {

this._mustHaveTemplateName = (templateName) => {
if (!templateName) {
throw new Error('"templateName" is required in making a request');
throw new Error(
'"templateName" is required in making a request'
);
}
};
this._mustHaveComponents = (components) => {
Expand All @@ -133,7 +135,9 @@ class WhatsappCloud {
};
this._mustHaveLanguageCode = (languageCode) => {
if (!languageCode) {
throw new Error('"languageCode" is required in making a request');
throw new Error(
'"languageCode" is required in making a request'
);
}
};
this._mustHaveMessageId = (messageId) => {
Expand Down Expand Up @@ -259,23 +263,28 @@ class WhatsappCloud {

return response;
}
async sendTemplate({templateName,languageCode,components,recipientPhone} ) {
async sendTemplate({
templateName,
languageCode,
components,
recipientPhone,
}) {
this._mustHaverecipientPhone(recipientPhone);
this._mustHaveTemplateName(templateName);
this._mustHaveComponents(components)
this._mustHaveLanguageCode(languageCode)
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
}
messaging_product: 'whatsapp',
recipient_type: 'individual',
to: recipientPhone,
type: 'template',
template: {
name: templateName,
language: {
code: languageCode,
},
components: components,
},
};

let response = await this._fetchAssistant({
Expand Down Expand Up @@ -321,10 +330,11 @@ class WhatsappCloud {
async sendSimpleButtons({ recipientPhone, message, listOfButtons }) {
this._mustHaveMessage(message);
this._mustHaverecipientPhone(recipientPhone);

if(!listOfButtons) throw new Error('listOfButtons cannot be empty');
if(listOfButtons.length > 3) throw new Error('listOfButtons cannot be bigger than 3 elements');


if (!listOfButtons) throw new Error('listOfButtons cannot be empty');
if (listOfButtons.length > 3)
throw new Error('listOfButtons cannot be bigger than 3 elements');

let validButtons = listOfButtons
.map((button) => {
if (!button.title) {
Expand Down Expand Up @@ -895,7 +905,28 @@ class WhatsappCloud {
return response;
}

async sendSticker({ message, recipientPhone }) {}
async sendSticker({ message, recipientPhone, media_id }) {
this._mustHaverecipientPhone(recipientPhone);
this._mustHaveComponents(message);

let body = {
messaging_product: 'whatsapp',
recipient_type: 'individual',
to: recipientPhone,
type: 'sticker',
sticker: {
id: media_id,
},
};

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

return response;
}

async getUserProfile({ recipientPhone }) {}

Expand Down