Plugins
Extend WAKit's capabilities using the modular Plugin Registry.
What is a Plugin?
WAKit was designed with extensibility from Day 1. Instead of bloating the core WAKitClient with every possible feature (like scheduling, AI chatbots, logging), WAKit provides a PluginRegistry.
A Plugin in WAKit is an object that hooks into the client's lifecycle. It has access to the client instance, the underlying socket, and the event emitter.
Using a Built-in Plugin
WAKit ships with several powerful plugins out of the box. For example, the RESTApiPlugin spins up an Express server to control your bot via HTTP!
import { WAKitClient } from '@atharvh01/wakit';
import { RESTApiPlugin } from '@atharvh01/wakit/plugins';
const client = new WAKitClient({ sessionName: 'api-bot' });
// Install the plugin BEFORE calling initialize()
client.plugins.install(new RESTApiPlugin({ port: 3000 }));
await client.initialize();
// Your bot can now be controlled via http://localhost:3000/docs
Building a Custom Plugin
Creating a plugin is easy. You just implement the WAKitPlugin interface.
import type { WAKitPlugin, WAKitClient } from '@atharvh01/wakit';
export class MyCustomPlugin implements WAKitPlugin {
// Required: A unique name for your plugin
name = 'my-custom-plugin';
private client?: WAKitClient;
// Called when client.plugins.install() is run
install(client: WAKitClient): void {
this.client = client;
console.log(`[Plugin] Installed ${this.name}`);
}
// Called just before the socket connects
initialize(): void {
console.log(`[Plugin] Initializing...`);
}
// Called when the client successfully connects to WhatsApp
ready(): void {
console.log(`[Plugin] Client is ready!`);
// You can attach listeners!
this.client?.on('message', (msg) => {
console.log(`[Plugin] Monitored a new message from ${msg.chatId}`);
});
}
// Called when client.destroy() is called
destroy(): void {
console.log(`[Plugin] Cleaning up resources...`);
}
}
Why use Plugins?
Plugins force you to write isolated, testable, and reusable code. Instead of scattering your bot's logic across a huge index.ts file, you can encapsulate features (like a Welcomer, a Moderation engine, or an AI auto-responder) into their own Plugins and share them with the community!