This app uses whatsapp-web.js directly (no WAHA) to auto-block senders whose phone numbers start with configured country codes.
- 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 (
blockedornot_blocked) - Supports an optional admin chat by phone number for bot commands
- Node.js 18+
- A WhatsApp account you can pair via QR code
- Install dependencies:
npm install- Create your env file:
cp .env.example .env- Edit
.env:
- Set
BLOCKED_COUNTRY_CODES(example47,593) - Optionally set
ADMIN_PHONE(digits only, include country code) - Keep
SESSION_NAME=defaultunless you want a separate profile
- Start app:
npm start- Scan QR code shown in terminal logs.
- Make sure
.envexists. - Start container:
docker compose up -d --build- Open logs and scan QR:
docker compose logs -f whatsapp-country-code-blocker- Health check:
curl http://localhost:8787/health- Stop:
docker compose down- 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.
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:
!healthreturns bot status, session name, blocked country codes, and uptime.