A powerful, intelligent, and highly customizable WhatsApp Bot powered by the Baileys library and OpenAI's API. This bot acts as a highly contextual, natural conversational assistant for your groups and private chats.
- Multi-Auth Support: Connect seamlessly using either a WhatsApp QR code or a Pairing Code.
- Smart Group Event Reactions: The AI automatically detects when members join/leave, admins promote/demote users, or when group settings (name, description, icon, open/close, locked info) are changed, and reacts with a natural conversational response in the group's current language.
- Contextual Memory System: The bot remembers the last 30 messages per conversation (resetting after 24 hours of inactivity) and natively understands exactly who is speaking in a crowded group.
- Live Configuration via WhatsApp: Owners can toggle
autotyping,autoread,alwaysOnline, and switch AI models directly via WhatsApp commands without touching the code. - Dynamic Model Validation: Switching models via
/setmodelwill automatically verify the requested model against the live OpenAI API. - Public & Self Modes: Easily restrict the bot to only reply to the owner (
selfmode) or open it up to everyone (publicmode). - Anti-Prompt Injection: Safely designed without group-modifying execution tools, preventing malicious users from tricking the AI into changing group settings or kicking members.
Make sure you have Node.js installed on your machine or Termux environment.
git clone https://github.com/hostinger-bot/CNAI-BOT.git
cd CNAI-BOT
npm installOpen config.json and customize the default values before running:
{
"keyopenai": "YOUR_OPENAI_API_KEY",
"authMethod": "pairing",
"pairingNumber": "628xxx",
"ownerNumber": "628xxx",
"mode": "public",
"autoread": true,
"alwaysOnline": true,
"autotyping": true,
"model": "auto",
"autoai": "enable"
}keyopenai: Register at https://ai.tioo.eu.org/ (or use the official OpenAI API) to get your key.authMethod: Choose"pairing"or"qr".pairingNumber: The phone number of the bot itself (Format:628...no spaces or+). Only required if usingpairing.ownerNumber: Your personal WhatsApp number for admin access.
npm start
# or
node index.jsIf you chose "pairing", check your terminal for the pairing code and enter it into the "Linked Devices" section of your WhatsApp app.
The bot supports both prefixed commands (e.g., /menu) and non-prefixed commands (e.g., menu).
| Command | Description |
|---|---|
/ai <text> |
Ask the AI anything (e.g., /ai Write a poem) |
/menu, /help |
Display the list of all available commands |
/clear |
Clear conversation memory |
/sc, /script |
Show the source code information |
| Command | Description |
|---|---|
/models |
Fetch and list all available AI models from the server |
/setmodel <name> |
Change the active AI model (automatically validated) |
/mode <self/public> |
Toggle between Owner-only (self) or open access (public) |
/autoai <enable/disable> |
Enable or disable automatic AI replies in Private Chats |
/autoread <true/false> |
Toggle whether the bot automatically sends blue ticks |
/online <true/false> |
Toggle the permanent "Online" status presence |
/autotyping <true/false> |
Toggle the "typing..." presence when receiving messages |
/setkey <apikey> |
Update the API key (from ai.tioo.eu.org) |
You can fully customize how the bot behaves, speaks, and responds by editing the PROMPT.json file. It contains the system prompt which the AI will strictly adhere to during conversations.
This project is open-source. Feel free to fork, modify, and distribute it!