A WhatsApp bot you can actually manage.
Sonicos is a Go bot built on whatsmeow, with a web console for linking your account, tuning commands and groups, and moderating media. This guide covers what it does and how to run it in the cloud.
Features
Everything below is controlled from the web console or from chat.
Quick start
You need Git, a recent Go toolchain (see the version in go.mod), and a WhatsApp account to link. A spare number is strongly recommended.
Sonicos talks to WhatsApp through whatsmeow, an unofficial open-source library. WhatsApp can restrict accounts that automate messaging. Use a dedicated number, do not send unsolicited messages, and keep the bot to groups that have opted in.
Clone the repository
git clone https://github.com/SafwanGanz/Sonicos.git cd Sonicos go mod download
Set the configuration
The bot reads its settings from environment variables. Only the first two are required for a local run.
# Port the API and console talk to export PORT=8080 # Password you will type into the web console export DASHBOARD_PASSWORD="choose-a-long-passphrase" # Random string used to sign session cookies (openssl rand -hex 32) export SESSION_SECRET="paste-a-random-value" # Origins allowed to call the API (your console's address) export ALLOWED_ORIGINS="http://localhost:5500" # Where the WhatsApp session database is stored export DATA_DIR="./data"
Start the bot
go run .
You should see the API start on your chosen port. Keep this terminal open.
Open the console and link your account
Serve
dashboard.htmlfrom any static server (for examplepython3 -m http.server 5500), sign in with your password, and follow Link WhatsApp.
Configuration reference
| Variable | Required | Purpose |
|---|---|---|
PORT | Yes | HTTP port. Railway sets this for you. |
DASHBOARD_PASSWORD | Yes | Password for the web console. Use a long passphrase. |
SESSION_SECRET | Yes | Signs the login cookie. Changing it signs everyone out. |
ALLOWED_ORIGINS | Yes | Comma-separated list of console origins permitted by CORS. No wildcards. |
DATA_DIR | Recommended | Folder for the WhatsApp session database and settings. Must be persistent in the cloud. |
Deploy on Railway
Railway builds Go projects automatically and gives you an HTTPS address, which the console needs. Other hosts that run a long-lived process with persistent disk work the same way.
Put the code on GitHub
Fork the repository, or push your own copy. Never commit passwords or session files.
Create the Railway project
In Railway choose New Project → Deploy from GitHub repo and select Sonicos. The first build starts on its own.
Add a persistent volume
Open the service, add a Volume, and mount it at
/data. Then setDATA_DIR=/data.Do not skip thisThe WhatsApp session lives in
DATA_DIR. Without a volume it is wiped on every deploy and you must link the account again each time.Set the variables
Under Variables, add the values from the table above. Leave
PORTalone; Railway provides it and the bot must listen on it.DASHBOARD_PASSWORD=choose-a-long-passphrase SESSION_SECRET=paste-a-random-value ALLOWED_ORIGINS=https://console.example.com DATA_DIR=/data
Expose the service
In Settings → Networking, click Generate Domain (or attach your own, such as
api.example.com). You now have an HTTPS API address.Check it responds
Open
https://your-api-domain/statusin a browser. A JSON reply, or a 401 if you are not signed in, means the service is up.Host the console
Upload
dashboard.htmlto any static host (Cloudflare Pages, Netlify, GitHub Pages, Vercel). Open the file, setDEFAULT_API_BASEto your Railway address, and add the console's address toALLOWED_ORIGINS.
Login uses a secure cookie. Browsers increasingly block cookies between unrelated sites, so host the API and the console as subdomains of the same domain, for example api.example.com and console.example.com. They count as the same site and sign-in works everywhere, including Safari.
The web console
The console is one HTML file with no build step. It shows live state through server-sent events and falls back to polling every five seconds if the stream drops. A red banner appears whenever the backend cannot be reached.
| Page | What you can do |
|---|---|
| Overview | Connection state, uptime, message, group and user counts, warnings, service health and recent activity. |
| Connection | Link with a QR code or pairing code. Reconnect, disconnect, or unlink the account. |
| Settings | Bot name, description, language, timezone, auto-start and maintenance mode. |
| Commands | Change the prefix, switch commands on or off, and choose who can run each one. |
| Groups | Enable the bot per group, welcome messages, admin-only mode, disabled commands. |
| Moderation | Detection settings, enrolled references, match review and history. |
| Users | Warning counts and history per user, with phone numbers masked. |
| Activity | Searchable, filterable log with severity and pagination. |
Changing the command prefix
Set it on the Commands page or in Settings. It is a one to three character string without spaces, and it takes effect in the running bot right away. The old prefix stops working immediately, so tell your group members first.
Link WhatsApp
Both methods use WhatsApp's own Linked Devices feature. Sonicos never asks for your WhatsApp password or a verification code.
Option A: QR code
Open Connection in the console. A QR code appears once the bot is ready.
On your phone open WhatsApp → Settings → Linked devices → Link a device.
Scan the code. The page switches to Connected on its own. If the code expires, press Refresh QR.
Option B: Phone number
Choose the Phone number tab, pick your country and enter the number without the country code.
Press Get pairing code. An eight-character code appears.
In WhatsApp go to Linked devices → Link a device → Link with phone number instead and type the code in.
Once linked you can Reconnect after a network drop, Disconnect to pause the bot while keeping the session, or Unlink to delete the session completely.
Media moderation
Group admins enroll reference media, and the bot compares media shared in moderated groups against those references. It covers images, stickers, videos, audio and voice notes.
| Setting | What it controls |
|---|---|
| Dry-run mode | Logs detections without taking any action. Start here. |
| High-confidence threshold | Scores at or above this count as violations. |
| Possible-match threshold | Scores between this and the high threshold wait in a review queue for an admin. |
| Warnings before action | How many warnings a user receives before the removal step applies. |
| Removal on violation | Removes the sender on a chosen violation number (the default is the fourth). |
| Delete matching messages | Removes high-confidence matches automatically. The bot needs admin rights in that group. |
Turn on dry-run, watch the Detections and History tabs for a week, adjust the thresholds, then switch dry-run off. Every destructive action in the console asks for confirmation.
Security
The console can control a real WhatsApp account, so treat it like an admin panel.
- No secrets in the browser. The console never holds your session, keys or passwords. Sign-in is an HttpOnly cookie set by the backend.
- The backend decides. Every privileged action is checked on the server. Hiding a button is never the only protection.
- Strict CORS. List exact console origins in
ALLOWED_ORIGINS. Never use a wildcard. - HTTPS only in production. Railway provides it. Cookies are marked Secure.
- Protect the session folder. Anyone who copies
DATA_DIRcan act as your bot. Do not commit it or share backups. - Private by default. User phone numbers are masked in the console, and you should avoid sharing log exports.
- Rotate when in doubt. Change
DASHBOARD_PASSWORDandSESSION_SECRET, then unlink and relink the account.
Troubleshooting
The console says the backend is unreachable
Check that the bot is running and that the API address is correct, with https:// and no trailing path. Then confirm the console's exact origin is listed in ALLOWED_ORIGINS. A CORS block looks the same as a server that is down.
I sign in but get sent back to the login page
The browser is refusing the cookie. Make sure both sites use HTTPS, and host the console and API on subdomains of the same domain. Third-party cookie blocking commonly breaks cross-site sign-in.
No QR code appears
The bot may already be linked, or it has not finished starting. Check the Activity page for errors and press Refresh QR. If an account is stuck, use Unlink and start again.
WhatsApp rejects the pairing code
Codes expire after a couple of minutes. Request a new one, confirm the country code and number are right, and type the code on the phone that owns that number.
I have to relink after every deploy
The session folder is not persistent. Attach a Railway volume, mount it at /data, and set DATA_DIR=/data.
The bot ignores commands in a group
Check, in order: maintenance mode is off, the bot is enabled for that group, the command is enabled, the sender is allowed to run it, and you are using the current prefix.
Moderation flags media but nothing is deleted
Dry-run may be on, automatic deletion may be off, or the bot may not be an admin in that group. WhatsApp only lets admins delete other people's messages.
Team & credits
Developers
Testers
Built with
Contribute
Found a bug or want to help test? Open an issue or pull request on GitHub. Reports that include steps to reproduce and the Activity log entry are the easiest to fix.