Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WhatsApp OpenAI Bot

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.

🚀 Key Features

  • 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 /setmodel will automatically verify the requested model against the live OpenAI API.
  • Public & Self Modes: Easily restrict the bot to only reply to the owner (self mode) or open it up to everyone (public mode).
  • Anti-Prompt Injection: Safely designed without group-modifying execution tools, preventing malicious users from tricking the AI into changing group settings or kicking members.

🛠️ Installation & Setup

1. Prerequisites

Make sure you have Node.js installed on your machine or Termux environment.

2. Clone and Install Dependencies

git clone https://github.com/hostinger-bot/CNAI-BOT.git
cd CNAI-BOT
npm install

3. Configuration (config.json)

Open 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 using pairing.
  • ownerNumber: Your personal WhatsApp number for admin access.

4. Running the Bot

npm start
# or
node index.js

If you chose "pairing", check your terminal for the pairing code and enter it into the "Linked Devices" section of your WhatsApp app.


🤖 Commands List

The bot supports both prefixed commands (e.g., /menu) and non-prefixed commands (e.g., menu).

General Commands (Public)

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

Owner / Admin Commands (Restricted)

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)

🧠 Customizing the AI Persona

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.

📝 License

This project is open-source. Feel free to fork, modify, and distribute it!

About

WhatsApp Bot AI By CNAI

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages