Kiwabot is a WhatsApp chatbot built using Node.js and the whatsapp-web.js library. It supports multi-stage workflows, user interactions, and easy customization for various use cases.
- QR code-based WhatsApp authentication.
- Multi-stage conversation flows.
- Easy integration with external APIs using
axios. - Modular and scalable code structure.
- Error handling for seamless user experience.
Ensure you have the following installed:
-
Clone the repository:
git clone https://github.com/your-username/kiwabot.git cd kiwabot -
Install dependencies:
npm install
-
Start the chatbot:
For development:
npm run dev
For production:
npm start
-
Scan the QR code displayed in the terminal using your WhatsApp mobile app to link your account.
- src/server.js: Main entry point for the chatbot.
- stages/: Contains stage logic for multi-step conversations.
- storage.js: Manages persistent data across sessions.
- 0.js, 1.js, ... 14.js: Stages of the chatbot conversation.
Below are the libraries used and their purpose:
| Library | Purpose |
|---|---|
express |
Web framework for potential API endpoints. |
axios |
For making HTTP requests to external services. |
whatsapp-web.js |
WhatsApp Web client for Node.js. |
qrcode-terminal |
Displays the QR code for authentication in the CLI. |
nodemon |
Automatically restarts the server during development. |
The chatbot uses a modular design for conversation flows. Each stage is a separate JavaScript file in the stages/ directory.
To customize the initialStage, edit the 0.js file:
export const initialStage = {
exec: async ({ from, message, client }) => {
// Example response
return 'Welcome to Kiwabot! How can I assist you today?';
},
};-
Create a new file, e.g.,
stages/15.js:export const fifteen = { exec: async ({ from, message, client }) => { return 'This is a new stage response!'; }, };
-
Import the new stage in
stages.js:import { fifteen } from './15.js'; export { ..., fifteen };
-
Update the
getStage()logic instages.jsto route users to the new stage.
-
QR Code not displayed: Ensure your terminal supports UTF-8 encoding. Resize the terminal if the QR code appears cut off.
-
Authentication Failure: Check the
auth_failuremessage for specific issues and re-scan the QR code. -
Unhandled Errors: Review logs for specific issues and ensure all stages return valid responses.
Feel free to fork the repository and submit pull requests for enhancements or bug fixes.
This project is licensed under the ISC License. See the LICENSE file for details.