A powerful Node.js bot designed to automate the extraction, translation, and distribution of crop market offers received via WhatsApp. Currently, over 1,000s agricultural brokers across Telangana rely on this bot for their day-to-day operations, processiong lakhs of of messages everyday with each instance deployed locally to ensure complete control and zero hosting costs. It includes a user-friendly local web interface for easy management and monitoring.
The repo has zero stars. That's because the people using it are farmers who've never opened GitHub. My team deployed it for them β locally, offline, on their own machines. No cloud bill, no subscription, no barrier. Just a thing that works for people who needed it to work.
THe bot has a simple UI with only one toggle button to turn on/off the bot. Agri-brokers toggle the button on during the morning and toggle it off end of the day and toggle it on again the next morning. This simple free tool has improved their efficieny by 100x and saving them a lot of time and energy.
Agricultural commodity brokers receive hundreds of raw, unformatted crop offers daily via WhatsApp. Manually reading, standardizing, translating, and forwarding these messages to appropriate buyer groups is highly time-consuming and prone to human error.
Why this bot is 100% Free: This project was deliberately architected to circumvent the steep costs typically associated with enterprise bot development so that people can run it for free:
whatsapp-web.jsvs. WhatsApp Business API: We deliberately chosewhatsapp-web.jsbecause it acts as a wrapper for WhatsApp Web, completely bypassing the expensive per-message costs and strict template approvals required by the official Meta/WhatsApp Business API.- Google Gemini vs. ChatGPT: We chose Google Gemini for our AI extraction engine because it offers a highly generous free tier (unlike OpenAI's ChatGPT, which charges for every API call), allowing the bot to process massive amounts of market data at zero cost to the user.
- WhatsApp Integration: Connects to WhatsApp Web to monitor designated seller groups.
- AI-Powered Extraction: Leverages Google Gemini to intelligently extract crop offer details from raw messages.
- Multi-language Translation: Automatically translates extracted offers into multiple target languages (e.g., English, Telugu).
- Intelligent Distribution: Routes translated offers to specific buyer groups based on crop type and language, and also broadcasts updates to a general "All Updates" group.
- Robust Message Queue: Processes incoming messages sequentially with a built-in queue to prevent API rate limits and ensure reliable delivery.
- Comprehensive Logging: Detailed activity and error logs are maintained for troubleshooting and auditing.
- Local Web UI: A simple, intuitive web interface accessible locally to:
- Monitor bot connection status.
- Toggle automation ON/OFF.
- View real-time and historical bot logs.
- Email Notifications: Sends automated email alerts for failed message processing, providing crucial details for quick intervention.
- Market Statistics Storage: Saves processed market data for future analysis or display.
- Graceful Error Handling: Implements error capture and reporting for critical operational failures.
[demo deployment link will be provided soon]
πΈ more output screenshots are in outputs
Follow these steps to set up and run the bot on your local machine.
Ensure you have the following installed on your system:
- Node.js: Download & Install Node.js (LTS version recommended).
- npm: Comes bundled with Node.js.
- A WhatsApp account dedicated solely to the bot's operations.
- A Google Gemini API Key: Obtain one from Google AI Studio.
- An Email Account (Gmail recommended): For sending error notifications. If using Gmail, you must generate an App Password as direct password usage is deprecated for security reasons.
-
Clone the repository:
git clone [[https://github.com/avin-cyborg/RAW-Read-Analyze-Write-bot-for-crop-dealers-in-whatsapp](https://github.com/avin-cyborg/RAW-Read-Analyze-Write-bot-for-crop-dealers-in-whatsapp)] cd YOUR_REPO_NAME -
Install project dependencies:
npm install
The bot requires specific configurations for API keys, email details, and WhatsApp group mappings.
-
Set up Environment Variables (
.envfile): Copy the provided.env.examplefile to.envin the root of your project:cp .env.example .env
Then, open the newly created
.envfile and fill in your actual credentials:GEMINI_API_KEY=YOUR_GOOGLE_GEMINI_API_KEY_HERE NODEMAILER_EMAIL=your_sending_email@gmail.com NODEMAILER_PASSWORD=your_email_app_password_here ERROR_RECIPIENT_EMAIL=admin_notification_email@example.com LOCAL_UI_PORT=3000 # Optional: Customize the port for the local web UIRemember: Keep your
.envfile secret and never commit it to Git! -
Configure WhatsApp Groups and Crop Mappings (
config.js): Openconfig.jsand update the following variables with your specific WhatsApp group IDs and crop mapping logic:SELLER_GROUP_IDS: An array of serialized WhatsApp group IDs from which the bot will receive crop offers.BUYER_GROUP_MAPPING: An object that maps standardized crop names to specific buyer group IDs for each target language.TARGET_LANGUAGES: An array defining the language codes for translation (e.g.,['en', 'te']).ALL_UPDATES_GROUP_ID: The serialized WhatsApp group ID where all English translated offers will be broadcasted.
How to obtain WhatsApp Group IDs: You can get a group's serialized ID by either inspecting elements in WhatsApp Web or by logging
msg.fromorchat.id._serializedfrom a message received within that group using a simple test script.Example
config.jsstructure:// config.js module.exports = { SELLER_GROUP_IDS: [ '000000000000000000@g.us', // Example: "Gurunanak agro source 3" // Add more seller group IDs here ], BUYER_GROUP_MAPPING: { "TOOR DAL": { "en": "000000000000000000@g.us", // Example: "Pulses-English" "te": "000000000000000000@g.us" // Example: "Pulses-Telugu" }, "CHANA DAL": { "en": "000000000000000000@g.us", "te": "120363419197240816@g.us" }, "MASUR DAL": { "en": "000000000000000000@g.us", "te": "000000000000000000@g.us" }, "MATAR": { "en": "000000000000000000@g.us", "te": "000000000000000000@g.us" } // Add more standardized crop mappings as needed }, TARGET_LANGUAGES: ['en', 'te'], // You can add more languages here (e.g., 'hi' for Hindi) ALL_UPDATES_GROUP_ID: '000000000000000000@g.us', // Example: "All Updates" general group };
- Start the bot from your project root:
node index.js
- Scan the QR Code:
A QR code will appear in your terminal. Using your dedicated WhatsApp account, open WhatsApp on your phone, go to
Settings>Linked Devices>Link a Device, and scan the QR code. - WhatsApp Window Appears: Upon successful authentication, a browser window (Chromium/Chrome) showing WhatsApp Web will launch. Do not close this window, as it's required for the bot's operation.
- Bot Ready:
The bot will log "WhatsApp Client is ready!" in your terminal. Automation is initially
OFF.
- Once the bot starts, the local web UI server will launch.
- Open your web browser and navigate to:
http://localhost:3000(or the port you specified in your.envfile). - On this UI, you can:
- See the bot's connection status.
- Toggle the automation
ONorOFF. - View real-time logs from the bot.
This outlines the key files and directories within your bot's project:
whatsapp-logger/(Your project's root directory).env.example- Template for environment variables; copy this to.envand fill in your details..gitignore- Specifies files and folders that Git should ignore (e.g.,node_modules/,.env, session data).config.js- Centralized configuration file for WhatsApp group IDs, crop mappings, and target languages.index.js- The main entry point for the bot, handling WhatsApp client, message queue, and local UI server.geminiProcessor.js- Contains the logic for AI-powered text extraction and translation using the Gemini API.market_stats.json- (Generated by bot) A file used to store the latest market data for processed crops.package.json- Defines project metadata, scripts, and lists all npm dependencies.package-lock.json- Records the exact versions of dependencies installed, ensuring consistent builds.public/- Directory containing static assets for the local web user interface.index.html- The main HTML file for your local bot control and monitoring UI.
logs/- (Auto-created directory) Stores daily log files generated by the Winston logger.bot_activity-YYYY-MM-DD.log- Example format of a daily log file (e.g.,bot_activity-2025-07-19.log).
LICENSE.md- Details the licensing terms for your project (e.g., MIT License).
- No WhatsApp Window / QR Code Issue:
- Ensure
headless: falseis set inpuppeteeroptions withinindex.js. - Check your internet connection.
- If QR code doesn't appear or scan, try deleting the
.wwebjs_authfolder and restartingnode index.jsto force a fresh authentication.
- Ensure
- Bot not processing messages:
- Verify
botAutomationEnabledistruevia the local UI. - Double-check that the
SELLER_GROUP_IDSinconfig.jsexactly match the serialized IDs of your seller WhatsApp groups. - Review the bot's logs in the terminal or local UI for any errors or warnings.
- Verify
- Dependencies Outdated / WhatsApp Web Updates:
- WhatsApp frequently updates its internal web code, which can break the bot's connection. You must regularly keep upgrading your Node packages to ensure the bot stays compatible. Run these commands in your terminal to update the core packages:
npm install whatsapp-web.js@latest npm install puppeteer@latest
- WhatsApp frequently updates its internal web code, which can break the bot's connection. You must regularly keep upgrading your Node packages to ensure the bot stays compatible. Run these commands in your terminal to update the core packages:
- Gemini API Errors:
- Ensure your
GEMINI_API_KEYin.envis correct and active. - Check if you've enabled the necessary Gemini API services in your Google Cloud Project.
- Ensure your
- Email Notifications Failing:
- Confirm
NODEMAILER_EMAIL,NODEMAILER_PASSWORD, andERROR_RECIPIENT_EMAILare correctly set in.env. - If using Gmail, ensure you're using an App Password, not your regular Gmail password.
- Confirm
If you need a tailored or more customized version of this bot designed specifically for your unique business operations, feel free to reach out!
π§ Email me at: avinashsana2@gmail.com
Contributions, issues, and feature requests are welcome! Feel free to fork the repository and submit pull requests.
This project is licensed under the MIT License. See the LICENSE.md file for details.



