Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
82851ee
Honour deletes of the bot's own messages from a linked device
claude Nov 9, 2026
dcfe13d
Charts: show_change labels a value chart with its % change
claude Nov 10, 2026
76a8c92
Charts: show the % change on value charts by default
claude Nov 10, 2026
3d5c402
Charts: say in make_chart's description when to turn the % change off
claude Nov 10, 2026
528803b
CHARTS setting: turn the built-in charts off
claude Nov 10, 2026
1c6429a
Charts: change in the subtitle and caption; an axis sent as JSON text
claude Nov 11, 2026
e767635
Log whether the provider searched the web
claude Nov 11, 2026
65dd4bd
Log "server tools used", not "websearch used"; wait for history in a …
claude Nov 11, 2026
1881ba6
Send each reply as one message; keep history in order while it sends
claude Nov 11, 2026
f8388be
Choose the chat network by setting, from those the build has
claude Nov 17, 2026
99dfa39
Move Markdown styling to internal/kit/mdstyle, for a second network
claude Nov 17, 2026
39f5bed
Telegram network: native Bot API long polling, behind notelegram
claude Nov 17, 2026
0ec0d81
Telegram: end-to-end scenarios and docs
claude Nov 17, 2026
1a7ac9c
Telegram: fixes from review
claude Nov 17, 2026
7ef5b9f
Telegram: answer in a group only while a listed user is a member
claude Nov 17, 2026
6f34dd6
Telegram: recheck a group when someone leaves; empty list is a defini…
claude Nov 17, 2026
e344dde
Images: make pictures with GPT Image 2 on OpenRouter
claude Nov 19, 2026
6c67431
Images: fixes from review
claude Nov 19, 2026
d428174
Signal: a reply quoting the bot's picture shows the model the original
claude Nov 19, 2026
a0ff66a
Signal: serve a kept picture only in its chat; byte cap drops only pi…
claude Nov 19, 2026
05cb8fb
Images: technical pictures get their facts worked out first
claude Nov 19, 2026
350f79f
Images: fixes from review of technical prompts
claude Nov 19, 2026
893e22a
Answer a request, not react to it, when its words offered a tool
claude Nov 19, 2026
6c17609
Images: a technical picture's follow-up keeps its requirements
claude Nov 19, 2026
7f5fce4
Tell the model today's date, and to take the user's word on recent news
claude Nov 19, 2026
bae59a0
Images: each thing and label once in a technical picture
claude Nov 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ jobs:
run: |
go vet -tags nocharts ./...
go test -tags nocharts .
if go build -tags nosignal -o /dev/null . 2> /tmp/nosignal.txt; then
go vet -tags nosignal ./... && go test -tags nosignal ./...
go vet -tags notelegram ./... && go test -tags notelegram ./...
if go build -tags nosignal,notelegram -o /dev/null . 2> /tmp/nonet.txt; then
echo "a build with no chat network should fail"; exit 1
fi
grep -q this_build_has_no_chat_network /tmp/nosignal.txt || { cat /tmp/nosignal.txt; exit 1; }
grep -q this_build_has_no_chat_network /tmp/nonet.txt || { cat /tmp/nonet.txt; exit 1; }
- name: memory at real size, too slow under -race
run: go test -run AtRealSize ./internal/kit/img/
- name: sizes
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ If a feature can't be built on these, that's a design finding. Either a port bec
A plain `go build` has everything. A tag leaves a part out, and never adds one, so a forgotten tag can't ship a smaller bot:

- **`nocharts`** leaves out charts and their fonts. A feature that can be left out is a variable from a pair of files, `features_<name>.go` (`//go:build !no<name>`, the feature's `Register`) and `features_no<name>.go` (`//go:build no<name>`, nil). Its place in `features.go` stays, so the order is still set in one list; `enabled()` drops the nils. A scenario that needs it starts with `skipWithout(t, <name>Feature)`, and CI runs the tests with the tag too.
- **`nosignal`** leaves the build with no chat network, so `network_none.go` stops it with a compile error rather than making a bot that answers no one. A second network gets a `network_<name>.go` of its own, and that file's tag becomes `nosignal && no<name>`.
- **`nosignal`** and **`notelegram`** each leave out a chat network. A network registers itself from `network_<name>.go` (`//go:build !no<name>`), and `network.go` chooses one at startup from its settings. With both tags `network_none.go` stops the build with a compile error rather than making a bot that answers no one; a third network adds its tag to that file's. Each network's scenarios carry its tag, and CI runs the tests under each.

Give a feature a tag only for a real saving, such as a dependency; a runtime setting (like `FILES`) is the way to turn a feature off.

Expand Down
21 changes: 18 additions & 3 deletions PRIVACY.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ When a message that addresses the bot has a link, or replies to one with a link,

Charts are drawn on the bot's own machine from the numbers the model passes in; nothing extra leaves it.

When asked for a picture, the model writes a prompt for the image model, which can quote anything above, such as a name or what someone said. The prompt goes to OpenRouter's images endpoint, with the same `data_collection: deny` request, and on to the image model's provider (OpenAI's, for GPT Image 2). The picture comes back to the bot and is sent to the chat; the bot keeps only a note of the prompt in history, as above, and logs neither.

With MCP tools configured, the model may call them. A call sends the arguments the model wrote, which can quote anything above, to that tool's MCP server, and the tool's result goes to the model's API with the next request.

Every request to OpenRouter tells it to use only model providers that do not collect data (`data_collection: deny`). That is a request the bot cannot check or enforce, so read OpenRouter's policy and the model provider's. Other APIs get no such request, since it is OpenRouter's own; read their data policy. A local server, such as Ollama on the same machine, keeps everything on it.
Expand All @@ -27,14 +29,14 @@ Every request to OpenRouter tells it to use only model providers that do not col

- **With no model, no history at all.** The bot keeps no messages, not even group context, since nothing would read them.
- **History lives in memory only.** It is kept per chat, up to `HISTORY_MAX` messages and 500 chats, for at most 24 hours, or until a shorter disappearing-messages timer runs out. A restart clears it, and the bot never writes it to disk. In groups it holds messages not addressed to the bot too (their text only), unless `GROUP_CONTEXT=false`. Photos are not kept at all: the history notes that one was sent, and the bot fetches a photo from signal-cli only while answering a message that includes it.
- **Deletes and edits.** The bot honours deletes and edits as the Signal app does: from whoever wrote the message, even someone no longer allowed to DM the bot, and a group admin's delete of anyone's message. As in the app, a blocked person's deletes don't reach it, since signal-cli drops everything from them. A message deleted for everyone is dropped from the bot's history, along with any turn that quoted it, and its attachments from the recent ones below. If it is still waiting to be answered it is never sent to the model; if the model is answering it at that moment, the answer is sent but neither is kept. An edited message replaces the original in history the same way: the bot keeps only the message as it now reads. The bot's own replies stay until they expire.
- **Deletes and edits.** The bot honours deletes and edits as the Signal app does: from whoever wrote the message, even someone no longer allowed to DM the bot, and a group admin's delete of anyone's message. As in the app, a blocked person's deletes don't reach it, since signal-cli drops everything from them. A message deleted for everyone is dropped from the bot's history, along with any turn that quoted it, and its attachments from the recent ones below. If it is still waiting to be answered it is never sent to the model; if the model is answering it at that moment, the answer is sent but neither is kept. An edited message replaces the original in history the same way: the bot keeps only the message as it now reads. The bot's own messages stay until they expire, unless the account's owner deletes or edits one from a linked device, which drops it.
- **View-once photos and files** sent to the bot are shown to the model like any other, and remembered as below like any other attachment: the bot is a participant, and sees what it is sent.
- **No swap or core dumps.** The included systemd unit and Docker command forbid both, so history cannot reach disk that way.
- **Memory is freed, not wiped.** An expired message is dropped and Go's garbage collector reclaims its memory, but the bytes may linger until overwritten, and someone with root access to the host could read them from the running process.
- **What features save, on disk.** Features save state only through the core, one file each in the state directory (`/var/lib/private/signalbot`), so everything the bot keeps on disk is listed here.
- **Schedules are kept on disk.** Each `/schedule` saves, in `schedules.json` in the state directory (`/var/lib/private/signalbot`), the scheduling user's ID, the group's ID and its name when scheduled (if it's for a group), the time and repeat, and the text to post, until the user deletes it with `/schedule del`. The file also keeps, for each user who has scheduled, the last schedule number they were given, so numbers are never reused; it stays after their schedules are deleted. A one-off dropped because the bot was down is deleted, and its user is told in their DM, with the first 80 characters of its text. Besides today's spending (below), nothing else the bot keeps is written to disk.
- **Today's spending, on disk.** With a daily budget (`DAILY_BUDGET`, on by default), `budget.json` in the state directory holds today's date and, for each chat that used the model today, what it spent and whether it was told it reached the limit. Chats are stored under a SHA-256 hash of their ID, so the file holds no phone numbers, account IDs or group IDs as such. A hash of a phone number could be matched by trying every number, so treat the file as you would the schedules. Each day's file replaces the last.
- **Recent attachments, in memory only.** So that "@bot summarise this" in reply to someone's file can fetch the original, the bot remembers, for each group message and each DM from an allowed sender with attachments, the attachments' IDs, file names, types and sizes, never their content, under the chat, sender and time. Each is forgotten after a day, or sooner when 2,000 newer messages are remembered, and a restart clears them all.
- **Recent attachments, in memory only.** So that "@bot summarise this" in reply to someone's file can fetch the original, the bot remembers, for each group message and each DM from an allowed sender with attachments, the attachments' IDs, file names, types and sizes, never their content, under the chat, sender and time. Each is forgotten after a day, or sooner when 2,000 newer messages are remembered, and a restart clears them all. On Signal the bot also keeps a copy of each picture it sent (a chart, a picture it made), content and all, for at most a day and 32 MB in all, since signal-cli keeps none: a reply quoting it then shows the model the picture rather than Signal's small thumbnail. A delete of that message from the account's linked device drops it, and a restart clears them all.
- **Names.** The bot keeps a copy of signal-cli's contact list (names and IDs) in memory, so it can show and mention people by name. It reloads the list at startup, after reconnecting, when a group changes, and at least daily when in use, replacing what it had, so people who leave a group are forgotten. It also keeps the name of anyone who sends it an addressed message. It never keeps what anyone wrote.

## What the bot logs
Expand All @@ -58,10 +60,23 @@ Logs go to the journal or Docker's log driver and are kept as long as your setti

In a group, signal-cli passes every message to the bot, which checks each one for whether it is addressed to it. Messages not addressed to it are never logged and never answered. Their text, with the sender's display name, is kept in that group's history as context, the same way and for the same time as everything else there, unless `GROUP_CONTEXT=false`, in which case they are dropped on the spot. In DMs, the bot answers only the IDs listed in `SIGNAL_DM_USER_IDS`.

## Telegram

On Telegram (`TELEGRAM_BOT_TOKEN` set) the above holds, with these differences:

- **Not end-to-end encrypted.** Telegram's servers see every message in a bot's chats, and every reply. Telegram's own policy applies to them.
- **Deletes don't reach the bot.** The Bot API never tells a bot a message was deleted, so a deleted message stays in the bot's history until it expires (at most a day, or the chat's auto-delete timer). An edit does reach it, and replaces the original as on Signal.
- **What the bot sees.** With privacy mode on (the default), a group sends the bot only messages addressed to it, so it keeps no group context. With privacy mode off, or as an admin, it gets every message, kept as context as above.
- **Names and groups.** The Bot API has no contact list or member list. The bot keeps, in memory, the names of people it has seen post and the groups it has seen, and asks Telegram whether someone is still in a group when it needs to; a restart clears them.
- **Photos and files** are fetched from Telegram's servers by file ID, only while answering the message that has them.
- **Who it answers in groups.** Anyone can add a Telegram bot to a group, so the bot answers in a group only while someone in `TELEGRAM_DM_USER_IDS` is a member, and leaves one where no one is. Until it has checked, a stranger's group can briefly reach it: such messages are never answered, and chatter is dropped once the check is done.
- **Topics.** In a group with topics, each topic keeps its own history.
- **The token** is in every request's URL; the bot takes it out of every error before logging it.

## What this does not cover

- **The provider.** Once a message is sent, the model provider's retention, logging and sub-processors apply.
- **End-to-end encryption.** Signal's encryption protects messages between people. The bot is a participant: signal-cli decrypts what it receives, and what it answers goes to the provider. People in a chat should know the bot is there.
- **End-to-end encryption.** On Signal, its encryption protects messages between people. The bot is a participant: signal-cli decrypts what it receives, and what it answers goes to the provider. People in a chat should know the bot is there.
- **signal-cli's own data.** The account keys and whatever else signal-cli stores sit in its data directory, which the bot does not read. Keep it private (see the [README](README.md#prerequisites)).
- **Anyone on the host, with the default TCP connection.** signal-cli listens on `127.0.0.1:7583`, and any local user or process can connect to it and read or send messages as the Signal account. On a shared host, use signal-cli's [Unix socket](docs/SOCKET.md), which only a Unix group can use; then anyone in that `signal-cli` group (not a Signal group) can drive the account, so keep it to just the bot.
- **The host.** Root users can read process memory, and log backups keep what the logs contain.
Expand Down
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# signalbot

A small, [privacy-conscious](PRIVACY.md) chat bot that connects to a running [signal-cli](https://github.com/AsamK/signal-cli) daemon and answers using a model from [OpenRouter](https://openrouter.ai) or a [compatible provider](docs/MODELS.md).
A small, [privacy-conscious](PRIVACY.md) chat bot for Signal, through a running [signal-cli](https://github.com/AsamK/signal-cli) daemon, or for [Telegram](#telegram), that answers using a model from [OpenRouter](https://openrouter.ai) or a [compatible provider](docs/MODELS.md).

- [Features](#features)
- [Use cases](#use-cases)
Expand All @@ -9,13 +9,14 @@ A small, [privacy-conscious](PRIVACY.md) chat bot that connects to a running [si
- [Configuration](#configuration)
- [Install as a systemd service](#install-as-a-systemd-service)
- [Install as a Docker container](#install-as-a-docker-container)
- [Telegram](#telegram)
- [Test](#test)
- [Docs](#docs)

## Features

- Responds to @mentions, replies to its messages, and DMs from whitelisted contacts
- Tools: web search, line and pie charts, and your own [MCP connectors](docs/FILES_LINKS_TOOLS_MCP.md#mcp-connectors)
- Tools: web search, line and pie charts, [pictures](docs/FILES_LINKS_TOOLS_MCP.md#images) (drawings, art, diagrams) with GPT Image 2, and your own [MCP connectors](docs/FILES_LINKS_TOOLS_MCP.md#mcp-connectors)
- [`/schedule`](docs/SCHEDULING.md) a message or command, once or repeating
- Understands [files](docs/FILES_LINKS_TOOLS_MCP.md#files) (PDFs, text and code, Word, Excel and PowerPoint) and the [pages you link to](docs/FILES_LINKS_TOOLS_MCP.md#links), and if the model supports it, images, stickers, voice notes and other audio
- Typing indicators, reactions, stickers, @mentions and replies
Expand Down Expand Up @@ -121,9 +122,9 @@ docker logs -f signalbot

Logs go to journald where the host has it, otherwise to Docker's rotating `local` driver; `docker logs` reads both. Under journald, `journalctl CONTAINER_NAME=signalbot -p err` shows warnings and errors.

### Build without charts
### Build without charts, Signal or Telegram

Charts and their fonts can be left out of the binary (about 0.7 MB of 10 MB) with a build tag: `go build -tags nocharts`, or for Docker, add `TAGS=nocharts` after `sudo` in the build command above. To stop files reaching the model without rebuilding, set `FILES=off` instead (see [Configuration](docs/CONFIGURATION.md)).
Charts and their fonts can be left out of the binary (about 0.7 MB of 10 MB) with a build tag: `go build -tags nocharts`, or for Docker, add `TAGS=nocharts` after `sudo` in the build command above. Likewise `nosignal` or `notelegram` leaves out a chat network, and tags combine with commas (`-tags nocharts,notelegram`); leaving out both networks fails to build. To stop files reaching the model without rebuilding, set `FILES=off` instead (see [Configuration](docs/CONFIGURATION.md)).

### Block someone, or other signal-cli chores

Expand All @@ -140,6 +141,21 @@ With Docker, it is in the image: `docker exec signalbot /signalctl blocked`. Und

A block is Signal's own, as on a phone: signal-cli drops everything from that person or group from then on, including their deletes of messages the bot already holds, and the block syncs to linked devices. `call` sends any method in signal-cli's [JSON-RPC docs](https://github.com/AsamK/signal-cli/blob/master/man/signal-cli-jsonrpc.5.adoc). The daemon also sends signalctl's connection the messages it receives; signalctl skips them unread, so it never prints anyone's text.

### Telegram

The same bot can answer on Telegram instead, talking to Telegram's Bot API directly (long polling, so it needs no public address). A bot answers on one network: to run on both, run two, each with its own config and state directory.

1. In Telegram, message [@BotFather](https://t.me/BotFather), send `/newbot`, and copy the token it gives you.
2. In `/etc/signalbot.env`, set `TELEGRAM_BOT_TOKEN` to the token, and `TELEGRAM_DM_USER_IDS` to the user IDs allowed to DM the bot (a user can find theirs by messaging a bot such as [@userinfobot](https://t.me/userinfobot)). Leave `SIGNALCLI_SOCKET` unset. The token is a password: anyone with it controls the bot.
3. Install as above, skipping signal-cli and its socket.
4. Add the bot to a group and @mention it, or reply to one of its messages.

Anyone on Telegram can find a bot by its username and add it to a group of their own, so the bot answers in a group only while someone in `TELEGRAM_DM_USER_IDS` is a member, and leaves a group where no one is. To stop it being added at all, send BotFather `/setjoingroups` and choose Disable once it is in your groups. In a group with topics, each topic is its own conversation, with its own history, and the bot answers in the topic it was asked in.

**Privacy mode.** By default Telegram sends a bot in a group only the messages addressed to it, so the bot has no group context. To give it the conversation, send BotFather `/setprivacy` and choose Disable, then remove the bot from the group and add it again; or make it a group admin. As admin it also sees reactions and members joining and leaving.

Telegram differs from Signal in a few ways: bot chats are not end-to-end encrypted, the Bot API never tells a bot about deleted messages, and a reply is capped at 4,096 characters a message. See [PRIVACY.md](PRIVACY.md#telegram).

### Test

Add the bot's account to a group and @mention it, reply to one of its messages, or DM it from an allowed sender. Send it `/intro` or `/help` to see its introduction.
Expand All @@ -148,7 +164,7 @@ Add the bot's account to a group and @mention it, reply to one of its messages,

- [Configuration](docs/CONFIGURATION.md)
- [Unix socket](docs/SOCKET.md)
- [Files, Links, Tools, and MCP connectors](docs/FILES_LINKS_TOOLS_MCP.md)
- [Files, Links, Images, Tools, and MCP connectors](docs/FILES_LINKS_TOOLS_MCP.md)
- [Language models](docs/MODELS.md)
- [Scheduling](docs/SCHEDULING.md)
- [Troubleshooting](docs/TROUBLESHOOTING.md)
Loading
Loading