Skip to content

A whatsapp-web.js client abstraction that provides an easy way to run commands πŸ€–

License

Notifications You must be signed in to change notification settings

fm1randa/yagami

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

62 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– Yagami

πŸ“ Description

Yagami is a Whatsapp client for command execution via message.

πŸ’‘ Usage

⬆️ Install

npm install wwebjs-yagami

πŸ”Ž Example

import { YagamiClient, connectToDatabase } from 'wwebjs-yagami';
import commands from './commands';
async function main() {
  const isServer = process.env.SERVER === 'true';

  const { store } = await connectToDatabase();
  const authStrategy = new RemoteAuth({
    clientId: process.env.CLIENT_ID,
    store,
    backupSyncIntervalMs: 5 * 60 * 1000
  });

  const clientOptions: YagamiOptions = {
    handleSignups: true,
    authStrategy,
    puppeteer: {
      headless: true,
      [isServer && 'executablePath']: '/usr/bin/chromium-browser',
      [isServer && 'args']: ['--no-sandbox']
    }
  };

  const client = new YagamiClient(commands, clientOptions);

  start();

  function start() {
    client.init();
  }
}
main();

Obs:

🚨 You must import connectToDatabase and call that function before instantiating Yagami Client.

See commands.md for more info about commands.

After running npm start or npm run compile (build + start), you'll see that in the terminal:

image

πŸ‘Ύ Clients

It's possible to have many concurrent clients. In other words, you can manage more than one bot simultaneously with one Node instance.

To do so, it's necessary to instantiate different objects of YagamiClient, in that way:

const foo = new YagamiClient(commandsFoo, clientOptionsFoo);
const bar = new YagamiClient(commandsBar, clientOptionsBar);
start();

function start() {
  foo.init();
  bar.init();
...

πŸ•Ή Commands

See commands README.

βš™οΈ Environment variables

Some environment variables are necessary. You must create a .env file at the project root and follow this pattern:

SERVER=false # is running in a server?
MONGO_URI="" # mongo connection string
CLIENT_ID="" # ID that will represent a unique session at the database

πŸ“¦ Main dependencies

It's the main library that makes all the magic. It provides a helpful API with Whatsapp Web.

The qrcode-terminal module allows the QR Code mirroring from the Whatsapp Web page to the terminal.

πŸ–₯ winston

It's the one responsible for standardization logs. You may use the helper logger instead of console.log.

πŸ—ƒ Database

The Yagami Client, through mongoose, uses Mongo's non-relational database to store some entities such as:

You find the DB logic in the src/app directory.

πŸ“‚ /app/collections

A collection provides methods to maintain a database entity. In other words, you can create, update, delete and read a database entity.

πŸ“‚ /app/models

A estrutura de dados das entidades User e Group do banco Γ© representada nas classes contidas nessa pasta.

User and Group's database entities are represented by the classes contained in that directory.

🎫 Session

You can use any phone number with Yagami Client. To do so, it is used a session stored in the database, for avoiding scanning the QR Code every execution. It is done through the whatsapp-web.js auth strategy, Remote Auth.

Each session is identified by the environment variable CLIENT_ID. For each new ID, two collections are created in the Mongo database:

  • whatsapp-RemoteAuth-<CLIENT_ID>.chunks

  • whatsapp-RemoteAuth-<CLIENT_ID>.files