Small WhatsApp notification API built with whatsmeow.
It currently supports:
- WhatsApp opt-in with
subscribe - WhatsApp opt-out with
unsubscribe - direct text sends to one subscribed number
- broadcast text sends to all subscribed users
For speed, the app uses:
- SQLite as the primary runtime database
- optional Postgres as async backup storage for subscriber writes
- A user sends
subscribeto the bot on WhatsApp. - The bot replies and stores that phone number as subscribed.
- Your backend can now:
- send direct text to that subscribed number
- send broadcast text to all subscribed numbers
If a number is not subscribed, direct send is rejected.
Send text to one subscribed phone number.
Example body:
{
"phone_number": "2348000000000",
"message": "hello from spark"
}Send text to all subscribed users.
Example body:
{
"message": "hello subscribers"
}Copy .env.example to .env and edit it:
cp .env.example .envAvailable environment variables:
SQLITE_PATH=spark-whatsapp-module.db
POSTGRES_URI=
HTTP_ADDRESS=:8080
WHATSAPP_SUBSCRIBE_WORD=subscribe
WHATSAPP_UNSUBSCRIBE_WORD=unsubscribe
DB_MAX_OPEN_CONNS=10
DB_MAX_IDLE_CONNS=5
DB_CONN_MAX_IDLE_TIME=5m
DB_CONN_MAX_LIFETIME=30mNotes:
SQLITE_PATHis required and is used by the main app flow.POSTGRES_URIis optional. If set, subscriber writes are mirrored in the background.- if Postgres is down, the app still keeps working on SQLite.
If you are using SparkDB:
- Sign in at
https://sparkdb.pro/auth - Open
https://sparkdb.pro/dashboard - Create a Postgres database
- Open that database's details or SDK/access page
- Copy the Postgres connection URL
- Paste it into
.envas:
POSTGRES_URI=postgres://user:password@host:port/databaseThis project needs the Postgres connection URL, not the SparkDB API key.
Initialize tables:
make setupRun the app:
make runYou can also use:
go run ./cmd/setup
go run ./cmd/spark-whatsapp-moduleRequest files are in requests/:
Install system packages:
sudo apt-get update
sudo apt-get install -y golang git build-essential sqlite3Clone the project:
git clone <your-repo-url> spark-whatsapp-module
cd spark-whatsapp-moduleCreate config:
cp .env.example .envInitialize the databases:
make setupBuild:
make buildRun manually:
./bin/appBuild:
docker build -t spark-whatsapp-module .Run:
docker run -d \
--name spark-whatsapp-module \
--restart unless-stopped \
-p 8080:8080 \
-v $(pwd)/data:/app/data \
--env-file .env \
spark-whatsapp-moduleRecommended for Docker:
- set
SQLITE_PATH=/app/data/spark-whatsapp-module.db - mount
/app/dataso the SQLite database survives container restarts
There is a first-install helper script:
sudo bash scripts/install-vps.shThis is for first installation only.
It:
- installs required packages
- copies the project into
/opt/spark-whatsapp-module - creates
/etc/spark-whatsapp-module.env - builds the binary
- installs a
systemdservice - enables and starts the service
After the first install, normal updates are:
git pull
sudo systemctl restart spark-whatsapp-moduleUseful service commands:
sudo systemctl status spark-whatsapp-module
sudo journalctl -u spark-whatsapp-module -fThis repo is set up to be minimally open-source friendly:
- runtime secrets stay in
.env .env.exampleshows the required keys without secrets- SQLite database files are local runtime data and should not be committed
Before publishing, make sure your real .env, database files, and WhatsApp session data are not in git.