wwebjs-supabase
v1.1.0
Published
A Supabase plugin for whatsapp-web.js to store session data in Supabase Storage
Maintainers
Readme
wwebjs-supabase
A Supabase plugin for whatsapp-web.js!
Use SupabaseStore to save your WhatsApp MultiDevice session on a Supabase Database.
Quick Links
Installation
The module is available on npm:
npm i wwebjs-supabaseGetting Started
This 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.
Prerequisites
- Node.js (v14 or higher)
- A Supabase project with database access
- whatsapp-web.js installed
Example Usage
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();Configuration
Environment Variables
Create a .env file in your project root:
SUPABASE_URL=your_supabase_project_url
SUPABASE_ANON_KEY=your_supabase_anon_keyDatabase Setup
Create 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);API Reference
SupabaseStore
Constructor Options
supabase(required): Supabase client instancetableName(optional): Name of the table to store sessions (default: 'sessions')
Methods
delete(options)
Force delete a specific remote session from the database:
await store.delete({ session: 'yourSessionName' });save(sessionId, data)
Save session data to Supabase:
await store.save('sessionId', sessionData);extract(sessionId)
Extract session data from Supabase:
const sessionData = await store.extract('sessionId');Error Handling
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);
});Contributing
- 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
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
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
Changelog
Version 1.0.0
- Initial release
- Basic Supabase integration for whatsapp-web.js
- Session management functionality
- CRUD operations for session data
Related Projects
- whatsapp-web.js - WhatsApp Web API for Node.js
- Supabase - Open source Firebase alternative
Acknowledgments
- Inspired by wwebjs-mongo
- Built for the whatsapp-web.js community
- Thanks to the Supabase team for their excellent database platform
