Skip to content

Repository files navigation

WhatsApp-web.js Country Code Blocker

This app uses whatsapp-web.js directly (no WAHA) to auto-block senders whose phone numbers start with configured country codes.

What it does

  • Listens for incoming WhatsApp messages with whatsapp-web.js
  • Extracts sender phone number from message JID
  • Checks if number starts with a blocked country code
  • Skips blocking if sender is already in your contacts
  • Blocks sender via contact.block()
  • Logs each decision in JSON format (blocked or not_blocked)
  • Supports an optional admin chat by phone number for bot commands

Prerequisites

  • Node.js 18+
  • A WhatsApp account you can pair via QR code

Setup

  1. Install dependencies:
npm install
  1. Create your env file:
cp .env.example .env
  1. Edit .env:
  • Set BLOCKED_COUNTRY_CODES (example 47,593)
  • Optionally set ADMIN_PHONE (digits only, include country code)
  • Keep SESSION_NAME=default unless you want a separate profile
  1. Start app:
npm start
  1. Scan QR code shown in terminal logs.

Run with Docker Compose

  1. Make sure .env exists.
  2. Start container:
docker compose up -d --build
  1. Open logs and scan QR:
docker compose logs -f whatsapp-country-code-blocker
  1. Health check:
curl http://localhost:8787/health
  1. Stop:
docker compose down

Notes

  • Group chats (@g.us) are ignored.
  • Broadcast/status senders are ignored.
  • Commands sent in your own self chat are processed.
  • Existing contacts (isMyContact=true) are ignored even if country code matches.
  • Session auth is persisted in .wwebjs_auth.

Admin Commands

Your own self chat can always run commands.

If ADMIN_PHONE is set, that phone number is also treated as admin chat and will never be auto-blocked.

Available commands:

  • !health returns bot status, session name, blocked country codes, and uptime.

About

A bunch of QoL adjustment to use with WhatsApp. At the moment it blocks any number given a country code not in your contacts.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages