Can I run openWA inside Supabase? #1004
Replies: 2 comments 1 reply
|
Hi @sakibstime 👋 Short answer: OpenWA can't run as a process inside Supabase, but it can use Supabase as its database and media storage. Here's the detail. What won't workOpenWA is a long-running daemon (Node.js/NestJS) that keeps a WhatsApp session alive and handles the QR pairing flow. The default engine runs a full Chromium instance per session, and even the lightweight Baileys engine maintains a persistent WebSocket. Supabase provides managed Postgres, Storage, Auth, and short-lived Edge Functions — none of those are meant to host an always-on process like OpenWA. So OpenWA itself still needs to run somewhere that stays up: the simplest option is the provided Docker setup on your VPS. What will workYou can point OpenWA at your Supabase Postgres and Storage instead of its built-in backends. OpenWA supports external Postgres and S3-compatible storage out of the box. 1. Use Supabase Postgres as the database In your OpenWA environment ( DATABASE_TYPE=postgres
DATABASE_HOST=db.<your-project>.supabase.co # or your self-hosted Postgres host
DATABASE_PORT=5432
DATABASE_USERNAME=<your-supabase-user>
DATABASE_PASSWORD=<your-supabase-password>
DATABASE_NAME=postgres
POSTGRES_SCHEMA=openwa # optional, keeps tables isolated
DATABASE_SSL=true
DATABASE_SSL_REJECT_UNAUTHORIZED=true
2. Use Supabase Storage for media (optional) Supabase exposes an S3-compatible API, so OpenWA's S3 storage mode works with it: STORAGE_TYPE=s3
S3_ENDPOINT=https://<your-project>.supabase.co/storage/v1
S3_ACCESS_KEY_ID=<your-supabase-storage-key>
S3_SECRET_ACCESS_KEY=<your-supabase-storage-secret>
S3_BUCKET=<your-bucket-name>
S3_REGION=us-east-1 # set to your regionA couple of practical notes
TL;DRRun OpenWA in Docker on your VPS, and point it at Supabase for Postgres and (optionally) Storage. OpenWA itself can't live inside Supabase, but it integrates cleanly with the services Supabase provides. Hope that helps — happy to go deeper on any of the config if you need it. 🙌 |
|
As mentioned by the maintainer, you cannot run the open-wa daemon process directly inside the serverless Supabase ecosystem. However, you can seamlessly host your open-wa Node.js app on a standard VPS/PaaS (like Render, Railway, or DigitalOcean) and configure it to use your Supabase instance for data, authentication, and media file uploads. Here is the step-by-step boilerplate workflow to connect openWA with Supabase: 1. Initialize Supabase Client in your openWA ProjectInstall the required dependencies in your local Node.js environment: npm install @open-wa/wa-automation @supabase/supabase-js dotenvCreate a database configuration file ( import { createClient } from '@supabase/supabase-js';
import dotenv from 'dotenv';
dotenv.config();
const supabaseUrl = process.env.SUPABASE_URL;
const supabaseKey = process.env.SUPABASE_ANON_KEY;
export const supabase = createClient(supabaseUrl, supabaseKey);2. Save Incoming WhatsApp Messages to SupabaseYou can set up an event listener inside your openWA script to stream incoming text or group payloads directly into a custom table in your Supabase PostgreSQL database: import { create } from '@open-wa/wa-automation';
import { supabase } from './db.js';
create({
sessionId: "WHATSAPP_SESSION",
authTimeout: 60,
blockCrashLogs: true,
}).then((client) => start(client));
async function start(client) {
client.onMessage(async (message) => {
// Prevent processing bot status updates
if (message.from === 'status@broadcast') return;
// Log the incoming message directly to a Supabase table named 'whatsapp_logs'
const { data, error } = await supabase
.from('whatsapp_logs')
.insert([
{
sender_id: message.from,
message_body: message.body,
timestamp: new Date(message.t * 1000).toISOString()
}
]);
if (error) console.error('Supabase Sync Error:', error);
});
}3. Handle Media Storage (Optional)If users send images or voice notes, you can download the decrypted decrypted buffer from openWA and upload it directly into a Supabase Storage Bucket: if (message.isMedia || message.type === 'image') {
const buffer = await client.decryptMedia(message);
const fileName = `${message.from}/${message.t}.png`;
const { data, error } = await supabase.storage
.from('whatsapp-media')
.upload(fileName, buffer, {
contentType: 'image/png',
upsert: true
});
} |
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I have Supabase installed on my VPS. Can OpenWA run properly with Supabase?
Thank you.
All reactions