Socket
Socket
Sign inDemoInstall

node-whatsapp-bot-api

Package Overview
Dependencies
92
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.0 to 1.4.1

38

dist/index.js

@@ -39,3 +39,3 @@ "use strict";

const verifyWebhook_1 = __importDefault(require("./util/verifyWebhook"));
/** Types that should be exported for the package users. */
/** Types that should be exported for the package users. */
// Service

@@ -65,23 +65,18 @@ __exportStar(require("./customTypes/service"), exports);

*/
constructor(hubVerifyToken, phoneNumberId, optionalconfig) {
constructor(hubVerifyToken, metaAPIToken, phoneNumberId, optionalconfig) {
var _a, _b, _c;
super();
this.hubVerifyToken = hubVerifyToken;
this.metaAPIToken = metaAPIToken;
this.phoneNumberId = phoneNumberId;
// Members that can be configured when optional config is defined.
this.metaGraphAPIVersion = (optionalconfig === null || optionalconfig === void 0 ? void 0 : optionalconfig.metaGraphAPIVersion)
? optionalconfig.metaGraphAPIVersion
: Constants_1.default.MetaGraphAPIVersion;
this.metaGraphBaseUrl = (optionalconfig === null || optionalconfig === void 0 ? void 0 : optionalconfig.metaGraphBaseUrl)
? optionalconfig.metaGraphBaseUrl
: Constants_1.default.MetaGraphBaseUrl;
this.logger = (optionalconfig === null || optionalconfig === void 0 ? void 0 : optionalconfig.customWinstonLogger)
? optionalconfig.customWinstonLogger
: logger_1.default;
this.metaGraphAPIVersion =
(_a = optionalconfig === null || optionalconfig === void 0 ? void 0 : optionalconfig.metaGraphAPIVersion) !== null && _a !== void 0 ? _a : Constants_1.default.MetaGraphAPIVersion;
this.metaGraphBaseUrl =
(_b = optionalconfig === null || optionalconfig === void 0 ? void 0 : optionalconfig.metaGraphBaseUrl) !== null && _b !== void 0 ? _b : Constants_1.default.MetaGraphBaseUrl;
this.logger = (_c = optionalconfig === null || optionalconfig === void 0 ? void 0 : optionalconfig.customWinstonLogger) !== null && _c !== void 0 ? _c : logger_1.default;
}
// This implementation signature covers all possible argument combinations
/* istanbul ignore next */ on(eventName, listener) {
on(eventName, listener) {
return super.on(eventName, listener);
}
// This implementation signature covers all possible argument combinations
/* istanbul ignore next */
emit(eventName, ...args) {

@@ -91,3 +86,3 @@ return super.emit(eventName, ...args);

/**
* Middleware handler for verifying the webhook
* Middleware handler for verifying the webhook.
* @param req The Express request object.

@@ -108,10 +103,7 @@ * @param res The Express response object.

const body = req.body;
// Check if the given req.body is a webhookMessagesPayload from meta
if (body === undefined ||
body.object === undefined ||
body.object !== "whatsapp_business_account") {
// No match, call the next middleware
return next();
}
// Continue processing the payload
if (!(0, validateWebhookMessagesPayload_1.validateWebhookMessagesPayload)(this, body)) {

@@ -121,9 +113,6 @@ return next(new Error("Received invalid MessagesPayload."));

try {
// Handle the changes sent in the IWebhookMessagesPayload (e.g., received new message or status update of messages).
(0, processChanges_1.default)(this, body.entry[0].changes);
//Successfully processed changes
res.status(200).json({ status: "OK" });
}
catch (error) {
// Failed to process changes, call error handler middleware.
return next(error);

@@ -152,9 +141,10 @@ }

"Content-Type": "application/json",
Authorization: `Bearer ${this.hubVerifyToken}`,
Authorization: `Bearer ${this.metaAPIToken}`,
},
data: textObject,
};
// ...
try {
yield (0, makePostRequest_1.default)(this, axiosConfig);
this.logger.verbose(`Successful sent message to: ${to}.`);
this.logger.verbose(`Successfully sent message to: ${to}.`);
}

@@ -161,0 +151,0 @@ catch (error) {

@@ -462,2 +462,3 @@ // Generated by dts-bundle-generator v8.0.1

readonly hubVerifyToken: string;
readonly metaAPIToken: string;
readonly phoneNumberId: string;

@@ -471,3 +472,3 @@ logger: winston.Logger;

*/
constructor(hubVerifyToken: string, phoneNumberId: string, optionalconfig?: WhatsappBotOptionalConfig);
constructor(hubVerifyToken: string, metaAPIToken: string, phoneNumberId: string, optionalconfig?: WhatsappBotOptionalConfig);
/**

@@ -479,3 +480,3 @@ * Overrides the on() method of EventEmitter to register an event listener.

*/
on(eventName: SupportedWhatsappMessageTypes.TEXT, listener: (Message: IListenerTextMessage) => void): this;
on(eventName: SupportedWhatsappMessageTypes.TEXT, listener: (message: IListenerTextMessage) => void): this;
on(eventName: "error", listener: (error: Error) => void): this;

@@ -491,3 +492,3 @@ /**

/**
* Middleware handler for verifying the webhook
* Middleware handler for verifying the webhook.
* @param req The Express request object.

@@ -494,0 +495,0 @@ * @param res The Express response object.

{
"name": "node-whatsapp-bot-api",
"version": "1.4.0",
"version": "1.4.1",
"description": "WhatsApp Bot that can be used as middleware to emit events to listeners. Listeners can react to incoming messages. Additionally, the WhatsApp bot can send messages if a WhatsApp Cloud API token is provided.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -0,1 +1,4 @@

[![Checks](https://github.com/MartinMohammed/node-whatsapp-bot-api/actions/workflows/checks.yaml/badge.svg)](https://github.com/MartinMohammed/node-whatsapp-bot-api/actions/workflows/checks.yaml)
![npm type definitions](https://img.shields.io/npm/types/node-whatsapp-bot-api)
````markdown

@@ -135,7 +138,7 @@ # WhatsappBot

- [ ] Sending media messages (e.g., images, videos).
- [ ] Handling incoming messages and events from the WhatsApp API.
- [ ] Error handling and logging for failed message sending.
- [ ] Configuring a custom Winston logger for logging.
- [ ] Subscribing to and handling events using the `on` method.
- [ ] Implementing additional features and functionalities.
- [x] Webhook verification middleware
- [x] Handling incoming messages and events from the WhatsApp API.
- [x] Error handling and logging for failed message sending.
- [x] Configuring a custom Winston logger for logging.
- [x] Subscribing to and handling events using the `on` method.

@@ -142,0 +145,0 @@ Please note that the checklist is currently marked as incomplete for most items, indicating that only sending text messages is implemented.

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc