Yagami is a Whatsapp client for command execution via message.
npm install wwebjs-yagami
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:
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();
...
See commands README.
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
π whatsapp-web.js
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
.
The Yagami Client, through mongoose, uses Mongo's non-relational database to store some entities such as:
- Users
- Groups
- Sessions
You find the DB logic in the src/app
directory.
A collection provides methods to maintain a database entity. In other words, you can create, update, delete and read a database entity.
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.
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