@refactoring/whatsapp-webhook
v1.0.5
Published
WhatsApp Cloud API webhook in a nutshell
Downloads
2
Readme
WhatsApp Cloud API Webhook
WhatsApp Cloud API Webhook for message subscriptions.
Getting started
Install dependecy
npm install @refactoring/whatsapp-webhook
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); })();
Run the code
node webhook.js
Output
The server is listening on the provided port and ready to verify the WhatsApp Cloud API token and receive messages.
Debuggin
Install cloudflared CLI:
brew install cloudflared
Run instance with a Cloudflare tunnel:
cloudflared tunnel --url localhost:3000
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