Documentation

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.

LanguageGo
WhatsApp layerwhatsmeow
ConsoleStatic HTML
HostingRailway-ready
What it does

Features

Everything below is controlled from the web console or from chat.

Run it locally

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.

Unofficial client

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.

  1. Clone the repository

    bash
    git clone https://github.com/SafwanGanz/Sonicos.git
    cd Sonicos
    go mod download
  2. Set the configuration

    The bot reads its settings from environment variables. Only the first two are required for a local run.

    bash
    # 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"
  3. Start the bot

    bash
    go run .

    You should see the API start on your chosen port. Keep this terminal open.

  4. Open the console and link your account

    Serve dashboard.html from any static server (for example python3 -m http.server 5500), sign in with your password, and follow Link WhatsApp.

Configuration reference

VariableRequiredPurpose
PORTYesHTTP port. Railway sets this for you.
DASHBOARD_PASSWORDYesPassword for the web console. Use a long passphrase.
SESSION_SECRETYesSigns the login cookie. Changing it signs everyone out.
ALLOWED_ORIGINSYesComma-separated list of console origins permitted by CORS. No wildcards.
DATA_DIRRecommendedFolder for the WhatsApp session database and settings. Must be persistent in the cloud.
Go live

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.

  1. Put the code on GitHub

    Fork the repository, or push your own copy. Never commit passwords or session files.

  2. Create the Railway project

    In Railway choose New Project → Deploy from GitHub repo and select Sonicos. The first build starts on its own.

  3. Add a persistent volume

    Open the service, add a Volume, and mount it at /data. Then set DATA_DIR=/data.

    Do not skip this

    The WhatsApp session lives in DATA_DIR. Without a volume it is wiped on every deploy and you must link the account again each time.

  4. Set the variables

    Under Variables, add the values from the table above. Leave PORT alone; Railway provides it and the bot must listen on it.

    variables
    DASHBOARD_PASSWORD=choose-a-long-passphrase
    SESSION_SECRET=paste-a-random-value
    ALLOWED_ORIGINS=https://console.example.com
    DATA_DIR=/data
  5. 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.

  6. Check it responds

    Open https://your-api-domain/status in a browser. A JSON reply, or a 401 if you are not signed in, means the service is up.

  7. Host the console

    Upload dashboard.html to any static host (Cloudflare Pages, Netlify, GitHub Pages, Vercel). Open the file, set DEFAULT_API_BASE to your Railway address, and add the console's address to ALLOWED_ORIGINS.

Tip: keep both on one domain

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.

Control panel

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.

PageWhat you can do
OverviewConnection state, uptime, message, group and user counts, warnings, service health and recent activity.
ConnectionLink with a QR code or pairing code. Reconnect, disconnect, or unlink the account.
SettingsBot name, description, language, timezone, auto-start and maintenance mode.
CommandsChange the prefix, switch commands on or off, and choose who can run each one.
GroupsEnable the bot per group, welcome messages, admin-only mode, disabled commands.
ModerationDetection settings, enrolled references, match review and history.
UsersWarning counts and history per user, with phone numbers masked.
ActivitySearchable, 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.

Group safety

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.

01EnrollAn admin adds a reference item.
02CompareIncoming media gets a confidence score.
03SortHigh-confidence and possible matches are kept apart.
04ActWarn, delete or remove, as configured.
SettingWhat it controls
Dry-run modeLogs detections without taking any action. Start here.
High-confidence thresholdScores at or above this count as violations.
Possible-match thresholdScores between this and the high threshold wait in a review queue for an admin.
Warnings before actionHow many warnings a user receives before the removal step applies.
Removal on violationRemoves the sender on a chosen violation number (the default is the fourth).
Delete matching messagesRemoves high-confidence matches automatically. The bot needs admin rights in that group.
Recommended rollout

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.

Keep it safe

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_DIR can 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_PASSWORD and SESSION_SECRET, then unlink and relink the account.
When something is off

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.

The people

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.