@refactoring/whatsapp-webhook
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

WhatsApp Cloud API Webhook

@refactoring-do/whatsapp-webhook

WhatsApp Cloud API Webhook for message subscriptions.

NPM Package Tests Linting and Formatting

Getting started

  1. Install dependecy

    npm install @refactoring/whatsapp-webhook
  2. Write the following code:

    import { Logger, Webhook, ProcessedMessage } from "@refactoring/whatsapp-webhook";
    
    const observer = (message: any) => {
      console.log(JSON.stringify(message));
    };
    
    const port = +process.env['PORT'] || 3000;
    const verificationToken = process.env['VERIFICATION_TOKEN'] || 'qwertyuiop1234567890';
    
    (async () => {
      const webhook = new Webhook({
        endpoint: '/webhook',
        port,
        verificationToken,
        observer,
      });
    
      webhook.run().then(Logger.log).catch(Logger.error);
    })();
  3. Run the code

      node webhook.js
  4. Output

    The server is listening on the provided port and ready to verify the WhatsApp Cloud API token and receive messages.

Debuggin

  1. Install cloudflared CLI:

    brew install cloudflared
  2. Run instance with a Cloudflare tunnel:

    cloudflared tunnel --url localhost:3000   
  3. Write message to the bot and wait for the webhook subscription.

Credits

This package has been inspired by the official WhatsApp Cloud API for Node.js. A few improvements and facilities have been added.

Made with ❤️ by Refactoring, SRL

Package Sidebar

Install

npm i @refactoring/whatsapp-webhook

Weekly Downloads

0

Version

1.0.5

License

MIT

Unpacked Size

41.9 kB

Total Files

90

Last publish

Collaborators

  • marluanespiritusanto
  • jeffreyart1