npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

whatsapp-cloud-api-examples

v1.0.0

Published

Examples for using @phoscoder/whatsapp-cloud-api

Downloads

129

Readme

WhatsApp Cloud API Examples

This directory contains examples demonstrating how to use the @phoscoder/whatsapp-cloud-api package in a Node.js project.

Setup

  1. Install dependencies:

    npm install
  2. Configure environment variables:

    cp .env.example .env
  3. Get your credentials:

    • Go to Facebook Developer Portal
    • Create a new app or select an existing one
    • Add WhatsApp Messenger product
    • Get your TOKEN and PHONE_NUMBER_ID
    • Verify your test recipient phone number

Examples

1. Basic Usage (basic-usage.js)

Demonstrates how to send different types of messages:

  • Text messages
  • Images
  • Videos
  • Documents
  • Location
  • Interactive buttons
  • Template messages

Run it:

node basic-usage.js

Make sure to:

  • Update the TOKEN, PHONE_NUMBER_ID, and RECIPIENT variables
  • Uncomment the function you want to test in the main execution block

2. Webhook Example (webhook-example.js)

Demonstrates how to set up a webhook server to receive incoming messages and events.

Run it:

node webhook-example.js

Features:

  • Handles incoming text messages
  • Responds to different commands (hello, help, menu)
  • Handles media messages (images, videos, audio, documents)
  • Handles location messages
  • Handles interactive message responses
  • Tracks message delivery status

Setting up the webhook:

  1. Deploy your webhook to a public server (or use ngrok for local testing)
  2. Go to Facebook Developer Portal
  3. Configure webhook settings:
    • Webhook URL: https://your-domain.com/webhook
    • Verify Token: Use the same token from your .env file
  4. Subscribe to webhook fields (messages, message_status, etc.)

Using with Environment Variables

Both examples support environment variables. Create a .env file:

WHATSAPP_TOKEN=your_actual_token
PHONE_NUMBER_ID=your_phone_number_id
VERIFY_TOKEN=your_verify_token
LISTEN_PORT=3000
TEST_RECIPIENT=recipient_phone_number

Then modify the examples to use:

require('dotenv').config();
const TOKEN = process.env.WHATSAPP_TOKEN;
const PHONE_NUMBER_ID = process.env.PHONE_NUMBER_ID;

Important Notes

  1. Media URLs: When sending media, the URL must be publicly accessible and return the correct content-type header.

  2. Phone Number Format: Use international format without '+' or '00' prefix (e.g., 255757902132 for a Tanzanian number).

  3. Template Messages: Template messages must be pre-approved in the Facebook Business Manager before you can use them.

  4. Rate Limits: Be aware of WhatsApp Cloud API rate limits. Check the official documentation for details.

  5. Media Download: Media URLs from getMedia() are only valid for 5 minutes. Download and store them immediately if needed.

Resources

Support

If you encounter any issues, please open an issue on the GitHub repository.