Socket
Book a DemoInstallSign in
Socket

whatsapp-cloud-api-bot-express

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

whatsapp-cloud-api-bot-express

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.

unpublished
Source
npmnpm
Version
1.2.1
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

WhatsappBot

WhatsappBot is a JavaScript class that represents a WhatsApp bot. It provides functions for sending text messages using the WhatsApp API. It extends the EventEmitter class to handle event-based communication.

Installation

To use the WhatsappBot class, you need to have Node.js installed. You can install the package using npm or yarn:

npm install whatsapp-bot

or

yarn add whatsapp-bot

Usage

To use the WhatsappBot class in your JavaScript or TypeScript code, follow these steps:

  • Import the WhatsappBot class:

    import WhatsappBot from "whatsapp-bot";
    
  • Create an instance of the WhatsappBot class:

    const bot = new WhatsappBot(userAccessToken, phoneNumberId);
    
    • userAccessToken (string): The user access token for authentication.
    • phoneNumberId (string): The phone number ID associated with the bot.
  • Send a text message using the sendTextMessage method:

    bot.sendTextMessage(textMessage, to);
    
    • textMessage (string): The text message to send.
    • to (string): The recipient of the message.

    This method sends a text message using the WhatsApp API. If sending the message fails, an error is logged using the configured logger.

  • Subscribe to events using the on method:

    bot.on(eventName, listener);
    
    • eventName (string): The name of the event you want to listen to.
    • listener (function): The listener function to be called when the event is triggered.

    You can register event listeners to handle specific events emitted by the WhatsappBot instance.

Configuration

The WhatsappBot class can be configured with an optional custom Winston logger. If you want to use a custom logger, pass it as part of the optional configuration:

const customLogger = ...; // Create your custom Winston logger
const optionalConfig = {
  customWinstonLogger: customLogger,
};

const bot = new WhatsappBot(userAccessToken, phoneNumberId, optionalConfig);

Logging

The WhatsappBot class uses the Winston logging library for logging. By default, it uses a default logger configuration provided by the package. However, you can specify a custom Winston logger during instantiation to customize the logging behavior.

Contribution

Contributions are welcome! If you find any issues or have suggestions for improvement, please create an issue or submit a pull request in the GitHub repository.

License

This project is licensed under the MIT License.

Functionality Checklist

Please note that the current functionality of the WhatsappBot class is as follows:

  • Sending text messages using the sendTextMessage method.
  • 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.

Please note that the checklist is currently marked as incomplete for most items, indicating that only sending text messages is implemented.

Keywords

whatsapp

FAQs

Package last updated on 08 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts