A Supabase plugin for whatsapp-web.js!
Use SupabaseStore to save your WhatsApp MultiDevice session on a Supabase Database.
The module is available on npm:
npm i wwebjs-supabaseThis plugin allows you to store your WhatsApp Web.js session data in Supabase, providing a reliable and scalable database solution for your WhatsApp bot sessions.
- Node.js (v14 or higher)
- A Supabase project with database access
- whatsapp-web.js installed
const { Client, RemoteAuth } = require('whatsapp-web.js');
const { SupabaseStore } = require('wwebjs-supabase');
const { createClient } = require('@supabase/supabase-js');
// Initialize Supabase client
const supabase = createClient(
process.env.SUPABASE_URL,
process.env.SUPABASE_ANON_KEY
);
// Create store instance
const store = new SupabaseStore({
supabase: supabase,
tableName: 'whatsapp_sessions' // optional, defaults to 'sessions'
});
// Initialize WhatsApp client with Supabase store
const client = new Client({
authStrategy: new RemoteAuth({
store: store,
backupSyncIntervalMs: 300000
})
});
client.initialize();Create a .env file in your project root:
SUPABASE_URL=your_supabase_project_url
SUPABASE_ANON_KEY=your_supabase_anon_keyCreate a table in your Supabase database:
CREATE TABLE whatsapp_sessions (
id SERIAL PRIMARY KEY,
session_id VARCHAR(255) UNIQUE NOT NULL,
data JSONB NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Create an index for better performance
CREATE INDEX idx_whatsapp_sessions_session_id ON whatsapp_sessions(session_id);supabase(required): Supabase client instancetableName(optional): Name of the table to store sessions (default: 'sessions')
Force delete a specific remote session from the database:
await store.delete({ session: 'yourSessionName' });Save session data to Supabase:
await store.save('sessionId', sessionData);Extract session data from Supabase:
const sessionData = await store.extract('sessionId');const client = new Client({
authStrategy: new RemoteAuth({
store: store,
backupSyncIntervalMs: 300000
})
});
client.on('auth_failure', (msg) => {
console.error('Authentication failed:', msg);
});
client.on('disconnected', (reason) => {
console.log('Client was logged out:', reason);
});- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions:
- Check the Issues page
- Create a new issue if your problem isn't already reported
- Provide detailed information about your setup and the issue
- Initial release
- Basic Supabase integration for whatsapp-web.js
- Session management functionality
- CRUD operations for session data
- whatsapp-web.js - WhatsApp Web API for Node.js
- Supabase - Open source Firebase alternative
- Inspired by wwebjs-mongo
- Built for the whatsapp-web.js community
- Thanks to the Supabase team for their excellent database platform