topicdesk

A Telegram support bot that turns every customer conversation into its own forum
topic inside your private supergroup. Your team answers in the topic; the bot
delivers the reply from its own account. Customers never see who is behind it.
One Go binary, an embedded bbolt file, no database server.
Why
The usual options are either a hosted bot where your customer conversations flow
through somebody else's server, or a full help desk that wants Postgres, Redis and
a Rails stack to answer a handful of messages a day. topicdesk sits in between:
your data stays on your box, and the whole thing is a binary and a .db file.
How it works
customer ──DM──▶ bot ──creates topic──▶ your private supergroup
│
topic per customer
│
customer ◀──DM── bot ◀──reply in topic── your team
- A customer opens the bot and writes.
- The bot creates a forum topic in your support group and stores the mapping
chat_id ↔ message_thread_id in bbolt.
- Every following message from that customer lands in the same topic.
- Anything an agent writes in the topic is copied back to the customer as a message
from the bot.
Messages are relayed with copyMessage, not forwardMessage, so agent names and the
group itself never leak to the customer side. A delivered message is not confirmed in
any way; a failed one gets a silent ❌ reply right under it with the reason.
Features
- One forum topic per customer, with a pinned info card
- Two-way relay: text, photos, video, documents, voice, stickers
- Deep links (
t.me/yourbot?start=source42) recorded per customer and shown in the topic
/ban and /unban straight from the topic
/close closes the topic and notifies the customer; it reopens automatically on their next message
- Customer edits are mirrored into the topic, in place when Telegram still allows it
- Each customer is answered in their own Telegram language, while the group stays in one
- Survives restarts, deleted topics and blocked bots without losing the mapping
- Rate limiting, 429 retries and long-polling backoff built in
Quick start
1. Create the bot
Talk to @BotFather:
/newbot → get your BOT_TOKEN
/setprivacy → select the bot → Disable
Privacy mode must be disabled, otherwise the bot only receives replies to its own
messages and plain answers in a topic go nowhere.
2. Prepare the group
- Create a private group, upgrade it to a supergroup, enable Topics in settings.
- Set History for new members to Hidden.
- Add the bot as an administrator with the Manage topics permission.
- Get the group ID — it looks like
-1001234567890. Temporarily add
@RawDataBot or read it from the bot's own logs on start.
3. Run it
Docker Compose
The repository ships a docker-compose.yml and an .env.example:
cp .env.example .env # put your BOT_TOKEN and SUPPORT_GROUP_ID in it
mkdir -p data # keep it owned by your user, no chown needed
docker compose up -d --build
The image is distroless/static and the whole state is the bbolt file in ./data.
The container runs as ${UID:-1000}:${GID:-1000}, so the database file belongs to you
and not to a system account; if your ids are not 1000, put them into .env.
If the log says cannot open the database ... permission denied, the ./data
directory is not writable by that user — sudo chown -R $(id -u):$(id -g) data fixes
it. Do not chown it to the image's nonroot uid: with Docker Desktop and rootless
Docker the bind mount is written by your host user, whatever the container claims to
be, so a directory owned by 65532 locks everyone out.
Binary
Needs Go 1.26.7 or newer.
go install github.com/googolgl/topicdesk/cmd/topicdesk@latest
export BOT_TOKEN="123456:AA..."
export SUPPORT_GROUP_ID="-1001234567890"
topicdesk
Or from a clone: make build, which puts the binary in bin/.
On start the bot checks the Telegram side for you. It refuses to start when it is not
an administrator with Manage topics, when the group is not a supergroup, or when
topics are off. Privacy mode being enabled is logged as an error but is not fatal —
replies to the bot's own messages still arrive.
Configuration
All configuration is done through environment variables.
| Variable |
Required |
Default |
Description |
BOT_TOKEN |
yes |
— |
Token from @BotFather |
SUPPORT_GROUP_ID |
yes |
— |
Supergroup ID, negative, -100… |
DB_PATH |
no |
./support.db |
Path to the bbolt file |
DEFAULT_LANG |
no |
uk |
Locale for a customer whose language has no catalog |
OPERATOR_LANG |
no |
DEFAULT_LANG |
Language of everything written into the group |
WELCOME_TEXT_<LANG> |
no |
built-in |
Reply to /start, for that locale |
CLOSED_TEXT_<LANG> |
no |
built-in |
Sent to the customer on /close, for that locale |
BANNED_SILENT |
no |
true |
Ignore banned users instead of replying |
LOG_LEVEL |
no |
info |
debug, info, warn, error |
Logs are JSON on stdout, so docker compose logs or any collector reads them as
they are.
All times are stored and displayed in UTC — the card and /info spell the zone out, so
a date is never read as local time by mistake. The date layout itself follows
OPERATOR_LANG, since field order is a matter of language.
Locales
The bot ships with uk, en and ru, and speaks two languages at once:
- To the customer — welcome, the
/close notice, the banned notice — it answers in
their own Telegram language (language_code). en-US falls on the en catalog,
pt-br on pt if there is one, and anything unknown on DEFAULT_LANG.
- Into the support group — the customer card,
/info, the ❌ delivery notices,
every warning — it writes in OPERATOR_LANG only. Your team reads one group, and
topics in mixed languages would be unreadable to them.
The wording itself belongs in the catalogs. WELCOME_TEXT_EN and CLOSED_TEXT_EN
(and the same with any other tag) exist only so a running deployment can reword one
locale without rebuilding the binary; they win over that locale's catalog entry and
leave the other languages alone. There is no language-less WELCOME_TEXT — a single
wording cannot serve every locale. The banned notice is deliberately not configurable
at all: a ban is an internal decision, and its wording should not invite a discussion
about it.
Adding a language
Copy internal/i18n/locales/en.json to <tag>.json, translate the values, rebuild.
No Go code changes — the catalogs are embedded with go:embed, so the binary stays a
single file. A catalog that misses a key, carries an unknown one or has a broken
{{.Placeholder}} stops the process at start-up rather than surfacing months later in
front of a customer, and go test ./internal/i18n/ says the same thing sooner.
Use the named placeholders, not positional verbs: {{.Username}} can move to wherever
the sentence needs it in your language.
Commands
Run these inside the customer's topic:
| Command |
Effect |
/info |
Customer card: ID, username, first contact, last seen, source, ban status |
/ban |
Stop accepting messages from this customer |
/unban |
Resume |
/close |
Notify the customer and close the topic |
/start [payload] works in the customer's private chat and records where they came
from. It does not open a topic by itself — the topic appears with the first real
message, so a customer who only pressed Start does not clutter the group.
Commands are never delivered to the customer. Anything else in the topic is.
Known limitations
These are deliberate, not bugs:
- Everything you write in a topic reaches the customer. There is no internal note
mode. Keep team discussion in General or in a separate chat.
- Albums arrive as separate messages. Media groups are relayed one attachment at a
time, in order, rather than reassembled.
- Telegram has no per-topic permissions. Every member of the group can read every
topic. Split traffic across several groups if you need isolation, or use a real help
desk if you need agent-level access control.
- Agent edits are not propagated. The customer keeps the original message; the bot
warns you in the topic.
- Messages from bots in the group are ignored, including messages sent by anonymous
admins, which Telegram delivers as coming from a bot.
- There is no delivery confirmation. A message that went through is left alone; the
bot replies under it only when delivery fails — the customer blocked it, or Telegram
refused — with a ❌ and the reason. Silence means the answer is with the customer.
Storage
A single bbolt file with three buckets: users (keyed by user ID), threads (reverse
index from topic to user) and meta. Back it up by copying the file while the bot is
stopped, or with bbolt snapshots.
The file contains customer IDs and usernames. Keep it out of your repository — the
included .gitignore covers *.db and data/. The layout is versioned: a file
written by a newer schema is refused instead of being misread.
Project layout
.
├── cmd/topicdesk/
│ └── main.go entry point: config, preflight checks, graceful shutdown
└── internal/
├── config/
│ └── config.go environment parsing and validation
├── store/
│ ├── store.go the Store interface
│ └── bolt.go the bbolt implementation
├── bridge/
│ ├── bridge.go update routing, per-conversation queues, user records
│ ├── client.go customer → topic, and customer edits
│ ├── operator.go topic → customer, failure notices
│ ├── commands.go /start, /info, /ban, /unban, /close
│ └── format.go topic titles and the customer card
├── i18n/
│ ├── i18n.go message catalogs, language resolution
│ └── locales/*.json one file per language, embedded into the binary
└── tg/
├── limiter.go rate limits and 429 retries around every API call
└── transport.go long-polling backoff, from 1 up to 30 seconds
Updates are dispatched into one queue per conversation: messages of a single customer
are processed strictly in order (which keeps album attachments in order), while
different conversations move in parallel.
Development
make # list the targets
make build # static binary into bin/
make run # run it locally, loading .env
make check # fmt, vet, lint and the race-enabled tests
make up / logs # the same through docker compose
The tests cover the storage layer and the bridge: the scenarios of the specification
(a topic per customer, a deleted topic being replaced, a blocked customer, ban/unban,
close and reopen, edits in both directions) run against a fake Bot API, so no Telegram
account is needed.
Contributing
Issues and pull requests are welcome. Please open an issue before starting anything
large, so we can agree on the shape first.
License
MIT. See LICENSE.