whatsapp-business
Advanced tools
Comparing version 1.2.2 to 1.2.3
{ | ||
"name": "whatsapp-business", | ||
"author": "MarcosNicolau", | ||
"version": "1.2.2", | ||
"description": "This is the common configuration for node js project with typescript I always do", | ||
"version": "1.2.3", | ||
"description": "Node.js connector for the WhatsApp Business APIs with TypeScript support, integration tests and more.", | ||
"license": "MIT", | ||
"licenses": [ | ||
@@ -23,4 +24,4 @@ { | ||
"build": "tsc", | ||
"test": "jest", | ||
"prepare": "tsc --build", | ||
"test": "jest", | ||
"cm": "cz" | ||
@@ -53,2 +54,3 @@ }, | ||
"devmoji": "^2.3.0", | ||
"dotenv": "^16.0.1", | ||
"eslint": "^8.16.0", | ||
@@ -55,0 +57,0 @@ "eslint-plugin-import": "^2.26.0", |
@@ -78,3 +78,3 @@ "use strict"; | ||
baseURL: "https://graph.facebook.com/v13.0", | ||
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); }, | ||
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) || error); }, | ||
}); | ||
@@ -81,0 +81,0 @@ } |
@@ -62,3 +62,3 @@ /** | ||
code: WABAErrorCodes; | ||
error_data: { | ||
error_data?: { | ||
messaging_product: "whatsapp"; | ||
@@ -70,3 +70,3 @@ /** | ||
}; | ||
error_subcode: number; | ||
error_subcode?: number; | ||
fbtrace_id: string; | ||
@@ -73,0 +73,0 @@ }; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -17,7 +6,10 @@ exports.WABAErrorHandler = void 0; | ||
var WABAErrorHandler = function (error) { | ||
var _a, _b; | ||
var message = types_1.ERROR_CODES[(_a = error === null || error === void 0 ? void 0 : error.error) === null || _a === void 0 ? void 0 : _a.code] || ((_b = error === null || error === void 0 ? void 0 : error.error) === null || _b === void 0 ? void 0 : _b.message); | ||
var err = __assign(__assign({}, error === null || error === void 0 ? void 0 : error.error), { message: message }); | ||
var err = (error === null || error === void 0 ? void 0 : error.error) || {}; | ||
err.message = types_1.ERROR_CODES[err.code]; | ||
if (!err.error_subcode) | ||
err.error_subcode = NaN; | ||
if (!err.error_data) | ||
err.error_data = { details: "", messaging_product: "whatsapp" }; | ||
return Promise.reject(err.message ? err : error); | ||
}; | ||
exports.WABAErrorHandler = WABAErrorHandler; |
@@ -8,2 +8,3 @@ import { AxiosRequestConfig } from "axios"; | ||
export declare const createRestClient: ({ baseURL, apiToken, errorHandler }: RestClientParams) => { | ||
fetch: import("axios").AxiosInstance; | ||
get: <Response_1 = any, Params = Record<string, string>>(endpoint: string, params?: Params | undefined, config?: AxiosRequestConfig<any> | undefined) => Promise<Response_1>; | ||
@@ -10,0 +11,0 @@ post: <Response_2 = any, Payload = Record<string, any>>(endpoint: string, payload?: Payload | undefined, config?: AxiosRequestConfig<any> | undefined) => Promise<Response_2>; |
@@ -67,24 +67,25 @@ "use strict"; | ||
return { | ||
get: function (endpoint, params, config) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
fetch: fetch, | ||
get: function (endpoint, params, config) { return __awaiter(void 0, void 0, void 0, function () { var _a; return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, fetch.get(endpoint, __assign({ params: params }, config))]; | ||
case 1: return [2 /*return*/, (_a.sent()).data]; | ||
case 1: return [2 /*return*/, (_a = (_b.sent())) === null || _a === void 0 ? void 0 : _a.data]; | ||
} | ||
}); }); }, | ||
post: function (endpoint, payload, config) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
post: function (endpoint, payload, config) { return __awaiter(void 0, void 0, void 0, function () { var _a; return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, fetch.post(endpoint, payload, config)]; | ||
case 1: return [2 /*return*/, (_a.sent()).data]; | ||
case 1: return [2 /*return*/, (_a = (_b.sent())) === null || _a === void 0 ? void 0 : _a.data]; | ||
} | ||
}); }); }, | ||
put: function (endpoint, payload, config) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
put: function (endpoint, payload, config) { return __awaiter(void 0, void 0, void 0, function () { var _a; return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, fetch.put(endpoint, payload, config)]; | ||
case 1: return [2 /*return*/, (_a.sent()).data]; | ||
case 1: return [2 /*return*/, (_a = (_b.sent())) === null || _a === void 0 ? void 0 : _a.data]; | ||
} | ||
}); }); }, | ||
delete: function (endpoint, params, config) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
delete: function (endpoint, params, config) { return __awaiter(void 0, void 0, void 0, function () { var _a; return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, fetch.delete(endpoint, __assign({ params: params }, config))]; | ||
case 1: return [2 /*return*/, (_a.sent()).data]; | ||
case 1: return [2 /*return*/, (_a = (_b.sent())) === null || _a === void 0 ? void 0 : _a.data]; | ||
} | ||
@@ -91,0 +92,0 @@ }); }); }, |
{ | ||
"name": "whatsapp-business", | ||
"author": "MarcosNicolau", | ||
"version": "1.2.2", | ||
"description": "This is the common configuration for node js project with typescript I always do", | ||
"version": "1.2.3", | ||
"description": "Node.js connector for the WhatsApp Business APIs with TypeScript support, integration tests and more.", | ||
"license": "MIT", | ||
"licenses": [ | ||
@@ -23,4 +24,4 @@ { | ||
"build": "tsc", | ||
"test": "jest", | ||
"prepare": "tsc --build", | ||
"test": "jest", | ||
"cm": "cz" | ||
@@ -53,2 +54,3 @@ }, | ||
"devmoji": "^2.3.0", | ||
"dotenv": "^16.0.1", | ||
"eslint": "^8.16.0", | ||
@@ -55,0 +57,0 @@ "eslint-plugin-import": "^2.26.0", |
@@ -12,5 +12,5 @@ ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/MarcosNicolau/whatsapp-business-sdk/Release) | ||
This project offers a solution to easily interact with WhatsApp Business Cloud API. Built with Axios and no other extra dependency! | ||
This project offers a solution to easily interact with WhatsApp Business Cloud API with Heavy integration testing with real API calls to support implementation stability. Built with Axios and no other extra dependency! | ||
The connector is fully typed and documented! | ||
The connector is fully typed, tested and documented! | ||
@@ -29,9 +29,11 @@ ## Installation | ||
### Basic usage | ||
```typescript | ||
import { WABAClient, WABAErrorAPI } from "whatsapp-business"; | ||
//You cant get it from the meta for developers app administration | ||
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", | ||
@@ -53,2 +55,28 @@ }); | ||
### Sending a message | ||
```typescript | ||
const sendTextMessage = async (body: string, to: string) => { | ||
try { | ||
const res = await client.sendMessage({ type: "text", text: { body }, to }); | ||
console.log(res); | ||
} catch (err) { | ||
const error: WABAErrorAPI = err; | ||
console.error(error.message); | ||
} | ||
}; | ||
``` | ||
## Support | ||
| Cloud API | Business Management API | Analytics API | | ||
| --------------------------------------------- | ----------------------- | ------------------------------ | | ||
| <ul><li>- [x] Business profiles endpoints | Currently working on | Planning to add future support | | ||
| <ul><li>- [x] Media endpoints | | | ||
| <ul><li>- [x] Message endpoints | | | ||
| <ul><li>- [x] Phone Numbers endpoints | | ||
| <ul><li>- [x] Registration endpoints | | | ||
| <ul><li>- [x] Two-Step-Verification endpoints | | | ||
| <ul><li>- [x] Webhooks types | | | ||
### Webhooks | ||
@@ -64,4 +92,6 @@ | ||
## Project structure | ||
# Project | ||
## Structure | ||
This project uses typescript. Resources are stored in 2 key structures: | ||
@@ -72,7 +102,2 @@ | ||
## 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 | ||
@@ -79,0 +104,0 @@ |
Sorry, the diff of this file is not supported yet
82833
111
21
33
1358
6