Thanks to visit codestin.com
Credit goes to GitHub.com

Skip to content

The WhatsApp Bot That Actually Works Transform your WhatsApp into a smart assistant with AI conversations, seamless database integration, and modular architecture. From hobby projects to production deployments - one bot, infinite possibilities.

License

Notifications You must be signed in to change notification settings

yuurahz/yoshida

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

121 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

YOSHIDA-BOT

Node.js WhatsApp PostgreSQL JSON License

Lightweight & Powerful WhatsApp Bot

Built with Baileys β€’ Powered by Yoshida-APIs β€’ Completely Free


✨ Why Choose Yoshida-Bot?

πŸ†“ 100% Free No hidden costs, completely open-source
πŸ”Œ Plug & Play Modular architecture for easy customization
⚑ Lightning Fast Built on Baileys for optimal performance
πŸ’Ύ Hybrid Storage PostgreSQL + JSON for optimal performance
πŸ›‘οΈ Reliable Stable connection with advanced error handling
🎯 Easy Deploy Multiple deployment options available

πŸ—οΈ Architecture Overview

πŸ“¦ yoshida-bot/
β”œβ”€β”€ πŸ“ library/           # Core logic & helper modules
β”œβ”€β”€ πŸ“ plugins/           # Command-based plugin modules
β”œβ”€β”€ πŸ“ system/            # Internal system logic
β”œβ”€β”€ πŸ“ sessions/          # WhatsApp session files (JSON)
β”œβ”€β”€ πŸ“ database/          # Local database files (JSON)
β”œβ”€β”€ πŸ“„ index.js           # Main application entry point
β”œβ”€β”€ πŸ“„ machine.js         # State management logic
β”œβ”€β”€ βš™οΈ ecosystem.config.js # PM2 deployment configuration
β”œβ”€β”€ πŸ” .env               # Environment variables
└── πŸ“‹ package.json       # Project dependencies

πŸ“‹ Requirements

System Requirements

Component Version Required
Node.js 16.x or higher βœ…
npm/yarn Latest βœ…
Git Latest βœ…
FFmpeg Latest βœ…
ImageMagick Latest βœ…
PostgreSQL 12.x or higher ⚠️ Optional

🟒 For Heroku Users

Required Buildpacks (Add in this order):

# 1. Node.js buildpack
heroku buildpacks:add heroku/nodejs

# 2. Python buildpack
heroku buildpacks:add heroku/python

# 3. FFmpeg buildpack
heroku buildpacks:add https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git

# 4. ImageMagick buildpack
heroku buildpacks:add https://github.com/DuckyTeam/heroku-buildpack-imagemagick.git

Alternative using app.json:

{
	"buildpacks": [
		{ "url": "heroku/nodejs" },
		{ "url": "heroku/python" },
		{
			"url": "https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git"
		},
		{
			"url": "https://github.com/DuckyTeam/heroku-buildpack-imagemagick.git"
		}
	]
}

🟑 For Windows / RDP Users

Download and install the following software:

Software Download Link Purpose
Git Download here Version control & cloning
Node.js Download here JavaScript runtime
FFmpeg Download here Media processing
ImageMagick Download here Image processing

Installation Steps:

  1. Install Git

    • Download Git from the official website
    • Run the installer with default settings
    • Verify: git --version
  2. Install Node.js

    • Download LTS version from nodejs.org
    • Run the installer (includes npm)
    • Verify: node --version and npm --version
  3. Install FFmpeg

    • Download the Windows build
    • Extract to C:\ffmpeg\
    • Add C:\ffmpeg\bin to your system PATH
    • Verify: ffmpeg -version
  4. Install ImageMagick

    • Download Windows installer
    • Run with default settings
    • Verify: magick -version

🟠 For Linux/VPS Users

Ubuntu/Debian:

# Update package list
sudo apt update

# Install required packages
sudo apt install -y git nodejs npm ffmpeg imagemagick

# Verify installations
node --version
npm --version
ffmpeg -version
convert -version

CentOS/RHEL:

# Install NodeJS
curl -sL https://rpm.nodesource.com/setup_16.x | sudo bash -
sudo yum install -y nodejs

# Install other packages
sudo yum install -y git ffmpeg ImageMagick

# Verify installations
node --version
npm --version
ffmpeg -version
convert -version

πŸš€ Quick Start Guide

1️⃣ Installation

# Clone the repository
git clone https://github.com/yuurahz/yoshida.git

# Navigate to project directory
cd yoshida

# Install dependencies
npm install

2️⃣ Configuration

Create a .env file in the root directory:

# Time Zone Configuration
TZ=Asia/Jakarta

# Pairing Configuration
PAIRING_STATE=true
PAIRING_NUMBER= (e.g 628xxx)

#setup
DATABASE_NAME= /** local or postgres (default local) */
DATABASE_STATE=
SESSION_NAME=
SESSION_TYPE= /** local or postgres (default local) */

#postgresql config (visit here: https://console.aiven.io)[recommended]
POSTGRES_HOST=
POSTGRES_PASSWORD=
POSTGRES_USER=
POSTGRES_DATABASE=
POSTGRES_PORT=
POSTGRES_SSL=""

3️⃣ Launch Your Bot

Choose your preferred method:

# Development Mode
npm start

# Production Mode with PM2
npm run pm2

# Manual PM2 Setup
pm2 start ecosystem.config.js

πŸ”§ Plugin Development

Creating a Basic Plugin

module.exports = {
	// Plugin metadata
	help: ["ping", "test"],
	tags: ["tools"],
	command: /^(ping|test)$/i,

	// Main plugin logic
	run: async (m, { conn }) => {
		try {
			const startTime = Date.now();
			await conn.reply(m.chat, "πŸ“ Pong!", m);
			const endTime = Date.now();

			await conn.reply(
				m.chat,
				`⚑ Response time: ${endTime - startTime}ms`,
				m
			);
		} catch (error) {
			return conn.reply(m.chat, `❌ Error: ${error.message}`, m);
		}
	},

	// Plugin permissions
	group: false, // Works in groups
	admin: false, // Requires admin
	limit: false, // Uses command limit
	premium: false, // Premium only
	botAdmin: false, // Bot needs admin
	owner: false, // Owner only
};

Creating Event Handlers

module.exports = {
	async before(m, { conn }) {
		try {
			// Pre-processing logic
			if (m.text && m.text.includes("hello")) {
				await conn.reply(m.chat, "πŸ‘‹ Hello there!", m);
			}
		} catch (error) {
			console.error("Event handler error:", error);
		}
		return true;
	},
};

PM2 Configuration

module.exports = {
	apps: [
		{
			name: "yoshida-bot",
			script: "./index.js",
			instances: 1,
			autorestart: true,
			watch: false,
			max_memory_restart: "1G",
			node_args: "--max-old-space-size=2048",
			env: {
				NODE_ENV: "production",
			},
			env_development: {
				NODE_ENV: "development",
			},
		},
	],
};

πŸ“Š Storage & Database

Multi-Storage Architecture

Yoshida-Bot uses a hybrid storage system for optimal performance and reliability:

πŸ—„οΈ PostgreSQL Primary database for persistent data
πŸ“ JSON Local Local file storage for sessions & cache

Session Management

// Multiple session storage options
const postgreSQLConfig = {
    user: process.env.POSTGRES_USER,
    password: process.env.POSTGRES_PASSWORD,
    host: process.env.POSTGRES_HOST,
    port: parseInt(process.env.POSTGRES_PORT),
    database: process.env.POSTGRES_DATABASE,
    ssl: {
      rejectUnauthorized: true,
      ca: process.env.POSTGRES_SSL.replace(/"""/g, ""),
    },
  },

  // Local JSON

Database Configuration

// PostgreSQL connection example
const { Pool } = require("pg");

const pool = new Pool({
	user: process.env.POSTGRES_USER,
	host: process.env.POSTGRES_HOST,
	database: process.env.POSTGRES_DATABASE,
	password: process.env.POSTGRES_PASSWORD,
	port: process.env.POSTGRES_PORT,
	ssl: {
		rejectUnauthorized: true,
		ca: process.env.POSTGRES_SSL.replace(/"""/g, ""),
	},
});

// Local JSON storage
class Local {
	/**
	 * Initializes the LocalDB instance with the provided file path.
	 * @param {string} [filePath] - The path to the JSON file where the database will be stored. Defaults to 'database.json'.
	 */
	constructor(filePath) {
		this.filePath = filePath
			? filePath + ".json"
			: process.env.DATABASE_NAME;
		this.queue = [];
		this.initDB();
	}

	/**
	 * Initializes the database by checking if the file exists.
	 * If the file does not exist, it creates an empty JSON file.
	 * @returns {Promise<void>}
	 */
	initDB = async () => {
		try {
			await fs.access(this.filePath);
		} catch (err) {
			await this.write({});
		}
	};

	/**
	 * Validates if the provided data is a valid JSON object.
	 * @param {any} data - The data to be validated.
	 * @returns {boolean} - Returns true if the data is valid JSON, otherwise false.
	 */
	validateJSON = (data) => {
		try {
			JSON.stringify(data, null);
			return true;
		} catch (err) {
			return false;
		}
	};

	/**
	 * Adds data to the internal queue to be saved later.
	 * @param {object} data - The data to be added to the queue.
	 */
	enqueue = (data) => this.queue.push(data);

	/**
	 * Write the valid data from the queue to the file.
	 * If the data is valid JSON, it will be written to the file.
	 * @param {object} data - The data to be saved to the file.
	 * @returns {Promise<void>}
	 */
	write = async (data) => {
		this.enqueue(data);

		const validData = this.queue.filter(this.validateJSON);
		this.queue = [];

		if (validData.length > 0) {
			try {
				await fs.writeFile(
					this.filePath,
					JSON.stringify(validData[0], null),
					"utf8"
				);
			} catch (err) {
				console.log(`Failed to save data: ${err.message}`);
			}
		} else {
			console.log("No valid data to save");
		}
	};

	/**
	 * Read the data from the JSON file and returns it.
	 * @returns {Promise<object|null>} - The parsed data from the file, or null if an error occurred.
	 */
	read = async () => {
		try {
			const data = await fs.readFile(this.filePath, "utf8");
			return JSON.parse(data);
		} catch (err) {
			console.log(`Failed to fetch data: ${err.message}`);
			return null;
		}
	};
}

🀝 Contributing

We welcome contributions! Here's how you can help:

  1. 🍴 Fork the repository
  2. 🌟 Create a feature branch (git checkout -b feature/amazing-feature)
  3. πŸ’Ύ Commit your changes (git commit -m 'Add amazing feature')
  4. πŸ“€ Push to the branch (git push origin feature/amazing-feature)
  5. πŸ”„ Open a Pull Request

πŸ“œ License & Terms

MIT License - Free for personal and commercial use

⭐ Please star this repository if you find it useful!

Usage Guidelines

  • βœ… Free to use and modify
  • βœ… Commercial use allowed
  • βœ… Private use allowed
  • ⚠️ Must include license and copyright notice
  • ❌ No warranty provided

πŸ† Credits & Acknowledgements

Role Contributor Links
Developer yuurahz GitHub
Library Provider @yoshx/func npm
API Provider Yoshida-APIs Try it

πŸ†˜ Support & Community

GitHub Issues GitHub Stars GitHub Forks

Need help? Open an issue or join our community discussions!

Made with ❀️ by the Yoshida-Bot Team

Building the future of WhatsApp automation

About

The WhatsApp Bot That Actually Works Transform your WhatsApp into a smart assistant with AI conversations, seamless database integration, and modular architecture. From hobby projects to production deployments - one bot, infinite possibilities.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Contributors 2

  •  
  •