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

add function to send stickers #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
40 changes: 33 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,6 @@ class WhatsappCloud {

async sendImage({ recipientPhone, caption, file_path, file_name, url }) {
this._mustHaverecipientPhone(recipientPhone);
if (file_path && url) {
throw new Error(
'You can only send an image in your "file_path" or an image in a publicly available "url". Provide either "file_path" or "url".'
);
}

if (!file_path && !url) {
throw new Error(
'You must send an image in your "file_path" or an image in a publicly available "url". Provide either "file_path" or "url".'
Expand Down Expand Up @@ -853,7 +847,39 @@ class WhatsappCloud {
return response;
}

async sendSticker({ message, recipientPhone }) {}
async sendSticker({ recipientPhone, caption, file_path, file_name, url }) {
this._mustHaverecipientPhone(recipientPhone);
if (!file_path && !url) {
throw new Error('You must provide a sticker in your "file_path" or a sticker in a publicly available "url"');
}

let body = {
messaging_product: 'whatsapp',
recipient_type: 'individual',
to: recipientPhone,
type: 'sticker',
sticker: {
caption: caption || "",
}
};
if (file_path) {
let uploadedSticker = await this._uploadMedia({
file_path,
file_name,
});
body['sticker']['id'] = uploadedSticker.media_id;
} else {
body['sticker']['link'] = url;
}

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

return response;
}

async getUserProfile({ recipientPhone }) {}

Expand Down