New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

whatsapp-business

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

whatsapp-business - npm Package Compare versions

Comparing version 1.0.4 to 1.1.1

LICENSE

11

dist/package.json
{
"name": "whatsapp-business",
"author": "MarcosNicolau",
"version": "1.0.4",
"version": "1.1.1",
"description": "This is the common configuration for node js project with typescript I always do",

@@ -17,2 +17,6 @@ "licenses": [

],
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"tag": "latest"
},
"scripts": {

@@ -25,3 +29,4 @@ "build": "tsc",

"dependencies": {
"axios": "^0.27.2"
"axios": "^0.27.2",
"form-data": "^4.0.0"
},

@@ -31,2 +36,4 @@ "devDependencies": {

"@commitlint/config-conventional": "^17.0.0",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@semantic-release/npm": "^9.0.1",

@@ -33,0 +40,0 @@ "@types/jest": "^27.5.1",

4

dist/src/client.d.ts

@@ -20,5 +20,5 @@ import { Message, SendMessageResponse, GetBusinessPhoneNumberResponse, RequestPhoneNumberVerificationCodeArgs, VerifyPhoneNumberArgs, RegisterPhoneArgs, SetUpTwoFactorAuthArgs, DefaultResponse, BusinessProfile, BusinessProfileFieldsQuery, UpdateBusinessProfilePayload, GetMediaResponse, UploadMediaPayload, UploadMediaResponse, BusinessPhoneNumber } from "./types";

updateBusinessProfile(payload: UpdateBusinessProfilePayload): Promise<DefaultResponse>;
uploadMedia(payload: Omit<UploadMediaPayload, "messaging_product">): Promise<UploadMediaResponse>;
uploadMedia({ file, type }: Omit<UploadMediaPayload, "messaging_product">): Promise<UploadMediaResponse>;
getMedia(id: string): Promise<GetMediaResponse>;
deleteMedia(id: string): void;
deleteMedia(id: string): Promise<DefaultResponse>;
/**

@@ -25,0 +25,0 @@ *

@@ -66,2 +66,3 @@ "use strict";

var fs_1 = __importDefault(require("fs"));
var form_data_1 = __importDefault(require("form-data"));
var errorHandler_1 = require("./utils/errorHandler");

@@ -78,3 +79,3 @@ var restClient_1 = require("./utils/restClient");

baseURL: "https://graph.facebook.com/v13.0",
errorHandler: errorHandler_1.WABAErrorHandler,
errorHandler: function (error) { var _a; return (0, errorHandler_1.WABAErrorHandler)((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data); },
});

@@ -92,3 +93,3 @@ }

WABAClient.prototype.getBusinessProfile = function (fields) {
return this.restClient.get("/".concat(this.phoneId, "/whatsapp_business_profile"), {
return this.restClient.get("".concat(this.phoneId, "/whatsapp_business_profile"), {
fields: (fields === null || fields === void 0 ? void 0 : fields.join(",")) ||

@@ -99,3 +100,3 @@ "about,address,description,email,profile_picture_url,websites,vertical",

WABAClient.prototype.updateBusinessProfile = function (payload) {
return this.restClient.post("/".concat(this.phoneId, "/whatsapp_business_profile"), __assign(__assign({}, payload), { messaging_product: "whatsapp" }));
return this.restClient.post("".concat(this.phoneId, "/whatsapp_business_profile"), __assign(__assign({}, payload), { messaging_product: "whatsapp" }));
};

@@ -107,10 +108,17 @@ /*

*/
WABAClient.prototype.uploadMedia = function (payload) {
return this.restClient.post("/".concat(this.phoneId, "/media"), __assign(__assign({}, payload), { messaging_product: "whatsapp" }));
WABAClient.prototype.uploadMedia = function (_a) {
var file = _a.file, type = _a.type;
var formData = new form_data_1.default();
formData.append("type", type);
formData.append("file", fs_1.default.createReadStream(file));
formData.append("messaging_product", "whatsapp");
return this.restClient.post("".concat(this.phoneId, "/media"), formData, {
headers: { "Content-Type": "multipart/form-data" },
});
};
WABAClient.prototype.getMedia = function (id) {
return this.restClient.get("/".concat(this.phoneId, "/").concat(id));
return this.restClient.get(id);
};
WABAClient.prototype.deleteMedia = function (id) {
this.restClient.delete("/".concat(this.phoneId, "/").concat(id));
return this.restClient.delete(id);
};

@@ -124,9 +132,15 @@ /**

return __awaiter(this, void 0, void 0, function () {
var response;
var response, err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.restClient.get("", {}, { baseURL: url, responseType: "stream" })];
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, this.restClient.get(url, {}, { baseURL: "", responseType: "stream" })];
case 1:
response = _a.sent();
return [2 /*return*/, response.pipe(fs_1.default.createWriteStream(pathToSaveFile))];
case 2:
err_1 = _a.sent();
return [2 /*return*/, Promise.reject(err_1)];
case 3: return [2 /*return*/];
}

@@ -147,3 +161,3 @@ });

return __generator(this, function (_a) {
return [2 /*return*/, this.restClient.post("/".concat(this.phoneId, "/messages"), __assign(__assign({}, payload), { messaging_product: "whatsapp" }))];
return [2 /*return*/, this.restClient.post("".concat(this.phoneId, "/messages"), __assign(__assign({}, payload), { messaging_product: "whatsapp" }))];
});

@@ -155,3 +169,3 @@ });

return __generator(this, function (_a) {
return [2 /*return*/, this.restClient.post("/".concat(this.phoneId, "/messages"), {
return [2 /*return*/, this.restClient.post("".concat(this.phoneId, "/messages"), {
messaging_product: "whatsapp",

@@ -172,3 +186,3 @@ status: "read",

return __generator(this, function (_a) {
return [2 /*return*/, this.restClient.get("/".concat(this.accountId, "/phone_numbers"))];
return [2 /*return*/, this.restClient.get("".concat(this.accountId, "/phone_numbers"))];
});

@@ -180,3 +194,3 @@ });

return __generator(this, function (_a) {
return [2 /*return*/, this.restClient.get("/".concat(this.accountId, "/").concat(phoneNumberId))];
return [2 /*return*/, this.restClient.get(phoneNumberId)];
});

@@ -189,3 +203,3 @@ });

return __generator(this, function (_b) {
return [2 /*return*/, this.restClient.post("/".concat(phoneNumberId, "/request_code"), payload)];
return [2 /*return*/, this.restClient.post("".concat(phoneNumberId, "/request_code"), payload)];
});

@@ -206,3 +220,3 @@ });

return __generator(this, function (_b) {
return [2 /*return*/, this.restClient.post("/".concat(phoneNumberId, "/register"), __assign({ messaging_product: "whatsapp" }, payload))];
return [2 /*return*/, this.restClient.post("".concat(phoneNumberId, "/register"), __assign({ messaging_product: "whatsapp" }, payload))];
});

@@ -214,3 +228,3 @@ });

return __generator(this, function (_a) {
return [2 /*return*/, this.restClient.post("/".concat(phoneNumber, "/deregister"))];
return [2 /*return*/, this.restClient.post("".concat(phoneNumber, "/deregister"))];
});

@@ -223,3 +237,3 @@ });

return __generator(this, function (_b) {
return [2 /*return*/, this.restClient.post("/".concat(phoneNumberId), payload)];
return [2 /*return*/, this.restClient.post(phoneNumberId, payload)];
});

@@ -226,0 +240,0 @@ });

@@ -16,2 +16,2 @@ export declare type BusinessVertical = "UNDEFINED" | "OTHER" | "AUTO" | "BEAUTY" | "APPAREL" | "EDU" | "ENTERTAIN" | "EVENT_PLAN" | "FINANCE" | "GROCERY" | "GOVT" | "HOTEL" | "HEALTH" | "NONPROFIT" | "PROF_SERVICES" | "RETAIL" | "TRAVEL" | "RESTAURANT" | "NOT_A_BIZ";

export declare type BusinessProfileFieldsQuery = (keyof BusinessProfileFields)[];
export declare type UpdateBusinessProfilePayload = Partial<Omit<BusinessProfileFields, "messaging_product">>;
export declare type UpdateBusinessProfilePayload = Partial<Omit<BusinessProfileFields, "messaging_product" | "id">>;
export declare type MediaAcceptedFileTypes = "image/jpeg" | "image/png" | "text/plain" | "application/pdf" | "application/vnd.ms-powerpoint" | "application/msword" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "audio/aac" | "audio/mp4" | "audio/mpeg" | "audio/amr" | "audio/ogg" | "audio/opus" | "video/mp4" | "video/3gp" | "image/webp";
export declare type UploadMediaPayload = {
/**
* Path to the file stored in your local directory. For example: "@/local/path/file.jpg".
*/
file: string;

@@ -4,0 +7,0 @@ type: MediaAcceptedFileTypes;

export declare type BusinessPhoneNumber = {
verified_name: "Jasper's Market";
display_phone_number: "+1 631-555-5555";
id: "1906385232743451";
quality_rating: "GREEN";
verified_name: string;
display_phone_number: string;
id: string;
quality_rating: string;
code_verification_status?: string;
};
export declare type GetBusinessPhoneNumberResponse = {
data: BusinessPhoneNumber[];
paging: {
cursors: {
before: string;
after: string;
};
};
};

@@ -15,3 +22,3 @@ export declare type RequestPhoneNumberVerificationCodePayload = {

*/
locale: string;
language: string;
};

@@ -18,0 +25,0 @@ export declare type RequestPhoneNumberVerificationCodeArgs = RequestPhoneNumberVerificationCodePayload & {

@@ -20,4 +20,4 @@ "use strict";

var err = __assign(__assign({}, error === null || error === void 0 ? void 0 : error.error), { message: message });
return Promise.reject(err);
return Promise.reject(err.message ? err : error);
};
exports.WABAErrorHandler = WABAErrorHandler;
{
"name": "whatsapp-business",
"author": "MarcosNicolau",
"version": "1.0.4",
"version": "1.1.1",
"description": "This is the common configuration for node js project with typescript I always do",

@@ -17,2 +17,6 @@ "licenses": [

],
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"tag": "latest"
},
"scripts": {

@@ -25,3 +29,4 @@ "build": "tsc",

"dependencies": {
"axios": "^0.27.2"
"axios": "^0.27.2",
"form-data": "^4.0.0"
},

@@ -31,2 +36,4 @@ "devDependencies": {

"@commitlint/config-conventional": "^17.0.0",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@semantic-release/npm": "^9.0.1",

@@ -33,0 +40,0 @@ "@types/jest": "^27.5.1",

@@ -1,9 +0,85 @@

# WhatsApp Business API Sdk
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/MarcosNicolau/whatsapp-business-sdk/Release)
![GitHub last commit](https://img.shields.io/github/last-commit/MarcosNicolau/whatsapp-business-sdk)
![npm](https://img.shields.io/npm/v/whatsapp-business)
![npm bundle size](https://img.shields.io/bundlephobia/minzip/whatsapp-business)
![GitHub](https://img.shields.io/github/license/MarcosNicolau/whatsapp-business-sdk)
![GitHub top language](https://img.shields.io/github/languages/top/MarcosNicolau/whatsapp-business-sdk)
Node.js connector for the WhatsApp APIs, with TypeScript support.
# WhatsApp Business API SDK
This project offers a solution to easily interact with WhatsApp Business APIs. Built with Axios and no other extra dependency!
Node.js connector for WhatsApp Business Cloud API, with TypeScript support.
# Documentation
This project offers a solution to easily interact with WhatsApp Business Cloud API. Built with Axios and no other extra dependency!
Most methods accept JS objects. These can be populated using parameters specified by WhatsApp's API documentation.
The connector is fully typed and documented!
## Installation
`npm install whatsapp-business`
`yarn add whatsapp-business`
## Documentation
Most methods accept JS objects. These can be populated using parameters specified by [WhatsApp's API documentation](https://developers.facebook.com/docs/whatsapp/cloud-api/overview) or following the typescript schema.
# Usage
```typescript
import { WABAClient, WABAErrorAPI } from "whatsapp-business";
const client = new WABAClient({
accountId: "YOUR_ACCOUNT_ID",
apiToken: "YOUR_API_TOKEN",
//You cant get it from the meta for developers app administration
phoneId: "YOUR_BUSINESS_PHONE_ID",
});
const foo = async () => {
try {
const res = await client.getBusinessPhoneNumbers();
console.log(res);
} catch (err) {
const error: WABAErrorAPI = err;
console.error(error.message);
}
};
foo();
```
### Webhooks
Although there is no current support for managing webhooks from the API, you can access the Webhooks response types
```typescript
import { Webhook } from "whatsapp-business";
const webhookListener = (res: Webhook) => {};
```
## Project structure
This project uses typescript. Resources are stored in 2 key structures:
- <b>src</b>: the whole connector written in typescript
- <b>dist</b> the packed bundle of the project for use in browser environments.
## Testing
I am currently working on test integration.
The idea is to make a heavy testing integration with real API calls to support implementation stability.
## Contribution and thanks
Contributions are encouraged, I will review any incoming pull requests.
### Donations
If you found this project interesting or useful, you can give this project a star. Thank you!
Or buy me a coffee using any of these:
- BTC: `1MjRd2YNNjEx3ze1Y71UNSgbAF9XECKTP1`
- ETH: `0xde25d72e9e87513b9c8dad8de11e2d8332276c7e`
- USDC:`0xde25d72e9e87513b9c8dad8de11e2d8332276c7e`

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc