A WhatsApp bot built with Node.js, Baileys (WhatsApp Web protocol — no Selenium/Puppeteer needed) and Express (Node's Flask-equivalent) for the web login page. Deployable on Render as a Web Service.
Every bot reply is sent in bold, except the AI's own answers, which are sent as plain text (as requested). Every reply signs off with
Master: #RADHEY.
You mentioned "Python, Node.js, or more" — WhatsApp bot login is a browser-based multi-device pairing protocol. The most mature, actively-maintained, free libraries for that (Baileys, whatsapp-web.js) are all Node.js. There is no equivalently reliable pure-Python option. So the bot itself is Node.js, and the web login page uses Express, which plays the exact same role Flask would play in Python — a tiny web server that shows you the QR code so you can click the link and scan it. If you specifically need Python code too (e.g. a Flask wrapper that just proxies to this service), say the word and I'll add it — but it isn't needed for the bot to work.
| Command | What it does |
|---|---|
.cmds |
Lists every command and how to use it |
.ping |
Health check + response time + uptime |
.owner |
Shows the owner/master's details |
.setai on / .setai off |
Opt this chat in/out of AI auto-replies |
.setai groq|gemini|openai|openrouter |
Choose which AI provider answers |
.ai <question> |
Ask AI once without enabling AI mode |
.reset |
Clears this chat's AI memory |
.fix |
Runs safe self-repair steps |
.fixlog |
Shows the most recent errors |
.fixlog clear |
Wipes stored logs |
.alive |
Quick alive check |
.about |
About the bot |
AI only replies after a user opts in with .setai on in that chat/group — exactly as you specified. Nobody gets AI replies by just DMing the bot.
You don't need to pay me for keys — every provider below has a free tier you sign up for yourself:
- Go to https://console.groq.com/keys
- Sign up (free), click Create API Key
- Copy it into
GROQ_API_KEYin your.env
- Go to https://aistudio.google.com/app/apikey
- Sign in with a Google account, click Create API key
- Copy it into
GEMINI_API_KEY
- Go to https://openrouter.ai/keys
- Sign up, create a key
- Copy it into
OPENROUTER_API_KEY
- Go to https://platform.openai.com/api-keys
- Create a key, add billing
- Copy it into
OPENAI_API_KEY
Set DEFAULT_AI_PROVIDER in .env to whichever one you filled in (e.g. groq). The bot will automatically fall back to another configured provider if the default one fails, so it's fine to add more than one key.
git clone <your-repo-url>
cd whatsapp-ai-bot
cp .env.example .env
# edit .env and paste in at least one AI key
npm install
npm startOpen http://localhost:3000 in your browser — you'll see the QR code page. Scan it with WhatsApp: Settings → Linked Devices → Link a Device.
- Push this folder to a GitHub repo (
.envis git-ignored on purpose — never commit real keys). - On Render → New + → Web Service → connect your repo.
- Render will detect
render.yamlautomatically (or set manually):- Build command:
npm install - Start command:
npm start
- Build command:
- Under Environment, add your AI key(s) (
GROQ_API_KEY, etc.) andDEFAULT_AI_PROVIDER. - Deploy. Once live, open your Render URL (e.g.
https://your-app.onrender.com) — that's your captivating login link. It shows the animated QR "signal" page. Scan it once, and the bot logs in.
Free Render web services spin down when idle and use an ephemeral filesystem — meaning your auth_info/ login session can be wiped on redeploy/restart, forcing you to re-scan the QR. To avoid that:
- Upgrade to a paid Render plan and attach a persistent disk mounted at
auth_info/(already configured inrender.yaml— just enable disks on your plan), or - Use Render's "Background Worker" + a keep-alive ping to
/healthzon a free plan (still ephemeral on redeploy, but survives idling if pinged), or - Ask me to wire up session storage to a database (MongoDB/Postgres) instead of the filesystem — fully solves this, happy to add it.
whatsapp-ai-bot/
├── index.js # Express server + boots the bot
├── src/
│ ├── bot.js # Baileys WhatsApp connection + message listener
│ ├── commands/ # One file per command
│ │ ├── index.js # Router: prefix parsing + dispatch
│ │ ├── cmds.js ping.js owner.js fix.js fixlog.js setai.js ai.js extra.js
│ ├── ai/
│ │ └── providers.js # Groq / Gemini / OpenAI / OpenRouter integrations + fallback
│ ├── store/
│ │ └── aiState.js # Per-chat AI on/off + provider + short memory (JSON file)
│ └── utils/
│ ├── logger.js # File + console logging, powers .fixlog
│ └── formatting.js # Bold-text helpers
├── public/
│ └── qr.html # The login page shown at your Render URL
├── package.json
├── render.yaml
├── .env.example
└── .gitignore
Add a new file in src/commands/, export a function that returns the reply string, then register it in the switch statement inside src/commands/index.js. Use bold() / withFooter() from src/utils/formatting.js to match the existing style.
- QR page stuck on "Waking up the bot…" → check Render logs; likely still installing/booting. Wait ~30s.
- Bot replies with an AI error → run
.fixlogin WhatsApp, or check that at least one*_API_KEYis set correctly in Render's Environment tab. - Logged out unexpectedly → delete the
auth_info/folder (or the persistent disk contents) and redeploy to get a fresh QR. - Command not responding → make sure the message starts with the prefix (default
.), e.g..pingnotping.
Built for #RADHEY — t.me/youradhey