Skip to content

Telegram as a second chat network; image generation with GPT Image 2; prompt and Signal fixes - #37

Merged
robdevops merged 26 commits into
mainfrom
claude/busy-maxwell-jo5ojy
Nov 19, 2026
Merged

robdevops merged 26 commits into
mainfrom
claude/busy-maxwell-jo5ojy

Conversation

@robdevops

@robdevops robdevops commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Telegram

A native Telegram Bot API adapter (internal/telegram), standard library only, long polling (no webhook or public address needed).

  • Choosing the network: TELEGRAM_BOT_TOKEN set → Telegram, else Signal; both set is a startup error. -tags nosignal / -tags notelegram leave one out; both tags fail to build (network_none.go). CI tests each tag set.
  • Who it answers: DMs from TELEGRAM_DM_USER_IDS. In groups: @mentions, text mentions, replies to the bot, /command and /command@bot, and only while a listed user is a member of the group. Anyone can add a bot to their own group, so the bot checks with getChatMember (cached), checks again when someone leaves, and leaves groups where no listed user is.
  • Sending: Markdown becomes Telegram entities (bold, italic, strike, code/pre, spoiler, text_link with custom link text, and text_mention), with offsets in UTF-16. Replies split at 4096. Charts go as photos or albums with a caption. If Telegram refuses the entities, the text goes plain, and a failed photo send still sends the text. A 429 is retried after its retry_after. A group upgraded to a supergroup is followed to its new ID.
  • Receiving: photos, documents, voice and stickers; quotes; edits; reactions and member changes as events (when a feature has a hook). Forum topics are separate chats (group/topic). Handled updates are confirmed on shutdown.
  • Safety: the token is scrubbed from every error, and a test fails if it reaches the log. Maps are capped against hostile input.
  • Shared code: Markdown styling moved to internal/kit/mdstyle (UTF-16 runs, links, Split, FindAt). Signal's behaviour is unchanged.
  • Docs: README Telegram section (BotFather, privacy mode, /setjoingroups), PRIVACY (not end-to-end encrypted, deletes never reported, group rules), TECHNICAL (Bot API usage), CONFIGURATION, CONTRIBUTING build tags, and an updated docs/architecture.svg.

Images

A make_image tool (internal/features/imagegen) makes pictures with GPT Image 2 (openai/gpt-image-2) through OpenRouter's /api/v1/images endpoint, the only place OpenRouter serves that model.

  • When it's offered: only on messages asking for a picture (draw, sketch, paint, art, diagram, cutaway, cross-section, schematic, exploded view, blueprint, flowchart, org chart, mind map, image, picture, photo, logo, icon, poster, meme, avatar and similar words), then for follow-up replies. The chart tools say diagrams aren't theirs; shared words such as "visualise" offer both.
  • Technical pictures are worked out first: the model sets kind. For technical (diagram, cutaway, schematic, infographic, labelled or educational) it lists the facts the picture must get right. The image model then gets a brief that puts accuracy first and keeps any requested style, the facts as must-haves, and rules for text: exact labels, each once, nothing invented. An artistic prompt is unchanged.
  • Follow-ups: a technical picture's history note keeps its kind and requirements, so "add the other planets" stays to scale.
  • How it's called: a new core port, Host.GenerateImage, keeps the API key in the core and sends data_collection: deny. The picture's cost is added to the reply's, so DAILY_BUDGET counts it. If the model's next request fails, the picture is sent alone rather than lost.
  • Errors and settings: a content-policy refusal (400 or 403) is reported as one. Settings are IMAGE_MODEL (default openai/gpt-image-2, or off) and IMAGE_QUALITY (medium by default). Only on OpenRouter. It makes new pictures only; editing a sent picture would be a follow-up.

Prompt and Signal fixes

  • Full-size quoted pictures: a reply quoting a picture the bot sent on Signal shows the model the picture itself, not signal-cli's small quote thumbnail. The adapter keeps its sent pictures in memory, up to a day and 32 MB. They are served only in their own chat and dropped on a delete from a linked device.
  • No emoji-only answers to requests: a lone emoji, with no tool used, for a message whose words matched a tool's keywords (e.g. "…diagram this to scale") is asked again once rather than sent as a reaction. The prompt also says a request never gets an emoji alone.
  • The date: the system prompt now ends, before the intro, with today's date, so the model stops "correcting" recent news from its training. It also says to take the user's word on anything since its training.

Also on this branch (earlier work in the same session)

  • Honour deletes of the bot's own messages from a linked device.
  • Charts: % change shown by default, in the subtitle and caption with ▲/▼; CHARTS=no turns the built-in charts off; an axis sent as JSON text is handled.
  • Log "server tools used" when the provider searched the web.
  • Send each reply as one message (signal-cli sends long text as an attachment), and keep history in order while it sends.

Testing

  • go vet and go test -race ./... with no tags, -tags nosignal, -tags notelegram and -tags nocharts; the no-network build fails as intended.
  • Telegram: unit tests against a fake Bot API, and end-to-end scenarios running the real bot against fake Bot and model APIs.
  • Images: model-client, feature and scenario tests. Real pictures were tried on Signal: about $0.04 each at medium quality, about 21s.
  • Prompt and Signal fixes: scenarios for a quoted bot picture (and its delete), a lone emoji to a request, and golden prompts with a fixed clock.
  • Each part was reviewed adversarially by subagents, and every surviving finding was fixed with a test.
  • Not yet tried against real Telegram.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN

claude added 18 commits November 9, 2026 23:06
When the account's owner deletes one of the bot's messages for everyone
from a phone or desktop linked to the account, or edits it, the message
now leaves the bot's history, as the app on that device would drop it.

- Network.Send returns the timestamps of the messages it sent: each
  signal-cli send now waits for its result (up to a minute), which also
  logs a recipient it wasn't delivered to as the send returns.
- A reply's history entry, and a delivered post's, keep those
  timestamps as refs under a sender no network ID can be, so the core
  needn't know the account's ID. The reply is added once sent.
- signal-cli's sync message for the account's own delete or edit
  (syncMessage.sentMessage remoteDelete / editMessage) reaches the core
  as bot.Deleted with Bot set, and Forget drops the entry. An edit drops
  it too, so history never holds what the chat no longer shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
A value chart of a price showed the price only; change mode shows % but
loses the price. An axis's new show_change (value mode only) labels each
line's last value with its % change from its first point, so a price
chart carries both: beside the end dot on a single series (on a line of
its own, as beside the value it would run off the image), after the value
in each label on a chart of several. The bot computes it, and shows none
from a start of 0 or less.

The model decides, as only it knows whether a % change of the numbers
means anything: the option's description says to set it for prices,
indexes, revenue and populations, always for a stock or fund price, and
never for temperatures, rates or values already in %. The summary the
model reads carries the same number.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
Off by default, show_change never appeared: asked "chart NVDA 1m", the
model drew a value chart and left the option unset, as models do with
optional settings. It is now on unless the model sets it false, which
its description says to do where a % change means nothing (temperatures,
rates, values already in %); a series starting at 0 or below still shows
none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
Models read a tool's description more reliably than a nested property's,
so the line that value charts show the period's % change, and to set
show_change false for temperatures, rates or values already in %, is
now in make_chart's description too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
CHARTS (default on) set to no registers no chart tools, for anyone who
doesn't want charts or wishes to use their own charts MCP server; it
logs "charts: off (CHARTS)" at startup. The nocharts build tag still
leaves them out of the binary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
- A single series' subtitle is drawn in the line's colour (red or
  green), led by its change over the chart with an arrow, "▼ 15.2%",
  when there is one to show (change mode included); the caption becomes
  the title with that change in place of the subtitle.
- An axis sent as a string holding its JSON ("y_axis": "{\"mode\": …}")
  was taken for an axis title and drawn under the subtitle as raw JSON;
  only a plain string is a title now, and the JSON is decoded as the
  axis.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
Web search runs on the provider's side, so it never gets a tool line,
and a chart drawn from searched pages looked the same in the journal as
one drawn from an MCP data tool. Each request's debug line now ends
"websearch used: yes" when the reply cites a page (a url_citation
annotation) or its usage counts a web search request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
…test

- The core may not name a feature (TestNoFeatureWordsInTheCore), and
  never names a server tool, so the request line now reads "server tools
  used: yes" (web search being the server tool that runs today): a
  url_citation annotation, or any use counted in server_tool_use.
- TestDisappearingHistory checked history the moment the reply was
  seen, but history is added once Send returns, since the linked-device
  delete change; it now waits for it, as it was flaky under -race.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
- A reply over 2,000 characters was split into several messages, as if
  2,000 were Signal's limit. signal-cli 0.14.10 already sends what is
  past 2,000 bytes as a long-text attachment, as Signal's apps do, shown
  as one message with Read more (ManagerImpl.applyMessage). So a reply
  is now always one message, still capped at 8,000 characters; the
  system prompt's Signal line now says to put the answer first, as a
  long message shows only its start until Read more. Goldens re-pinned.
- Since history was added only after Send returned, and Send now waits
  for signal-cli, a group message arriving meanwhile landed before the
  turn in history. History is added before the send again, with a
  placeholder ref that chats.Store.Retag swaps for the sent timestamps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
network.go holds a registry each network_<name>.go fills in from init,
behind its build tag, and newNetwork picks the network whose setting is
set (TELEGRAM_BOT_TOKEN or SIGNALCLI_SOCKET), else Signal. Both set, or
one the build leaves out, is a startup error saying what to do. Signal
is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
The Markdown converter, styled text, @name finding and UTF-16 offsets
move from internal/signal to kit, as Telegram will use them too. New:
a Link a network can show under its own text (Signal keeps writing
"text (url)"), style runs in UTF-16 units, and Split, which cuts at the
last line break or space past halfway (Telegram has no long-text
attachment). Signal behaves as before; its tests pass unchanged apart
from names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
internal/telegram talks to the Bot API with the standard library:
getUpdates long polling, entities for Markdown, photos and albums,
reactions, typing, file downloads, Delivered, Groups and events. The
token is scrubbed from every error. TELEGRAM_BOT_TOKEN chooses it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
scenario_telegram_test.go runs the real bot against a fake Bot API and
model: a group mention with context and entities, DMs and an edit, a
photo, a chart, a reaction and /intro. README, PRIVACY, TECHNICAL,
CONTRIBUTING and the architecture diagram cover the second network.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
Leave a group added by someone not in TELEGRAM_DM_USER_IDS; send the
text when pictures fail and captions without refused entities; confirm
handled updates on shutdown; forum topics as chats of their own; follow
a group to its supergroup ID; retry a rate-limited send once; react's
text fallback only for REACTION_INVALID; cap the client's maps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
Leaving on the add event alone failed open: one failed leaveChat, a
restricted re-add, or a lost update let a stranger's group in. The bot
now checks membership of a TELEGRAM_DM_USER_IDS user before answering
(cached; checked in the background when a group is first seen) and
leaves, retrying, where there is none. Also: is_member for restricted
statuses; group changes reach each forum topic; membership checks
follow a migrated group; sent messages are noted at the new ID; a
failed last poll is confirmed on shutdown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
…te no

A cached yes outlived a listed user leaving; with no one listed the
check was skipped, so the bot neither left nor dropped chatter; and
events in a quiet group were dropped once the cached yes expired.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
A make_image tool, offered when a message asks for a drawing, art, a
diagram, a logo or the like (imagegen). The core keeps the key: a new
Host.GenerateImage port posts to OpenRouter's /images, with
data_collection deny, and adds the cost to the reply whose tool asked,
so DAILY_BUDGET counts it. IMAGE_MODEL (default openai/gpt-image-2, or
off) and IMAGE_QUALITY (default medium).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
Keep pictures a tool made when the model's next request fails; more
picture and diagram words (photo, meme, avatar, banner, flowchart, org
chart, mind map, visualise); report a 403 moderation refusal as one;
the chart tools say diagrams aren't theirs; make_image says one picture
a call, at most 4, and that it can't edit a sent picture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
@robdevops robdevops changed the title Telegram as a second chat network, behind build tags; chart and send fixes Telegram as a second chat network; image generation with GPT Image 2; chart and send fixes Nov 19, 2026
signal-cli gives a quote only a small thumbnail, and keeps no copy of
what the bot sent, so the model saw its own charts and pictures too
small to read. The adapter now keeps the pictures it sent, in memory, up
to a day and 32 MB, and serves them for a quote; a delete from a linked
device drops them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
…ctures

Two chats' sends can share a timestamp, so a kept picture is looked up
in the quoting chat alone. Over 32 MB, the oldest of the bot's pictures
go, not other people's attachment records, which hold no bytes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
make_image takes a kind. For a technical one (diagram, cutaway,
schematic, infographic, labelled or educational picture) the model lists
the facts it must get right before writing the prompt, and the image
model gets a brief that puts accuracy first, those facts as must-haves,
and rules for exact, legible labels. An artistic prompt is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
Offer the image tool on cutaway, cross-section, schematic, exploded view
and blueprint; the technical brief keeps a style the user asked for; the
text rules keep a requested title or caption.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
A message that opened with news and asked for a diagram got a lone
emoji, sent as a reaction. A lone emoji, with no tool used, for a
message whose words matched a tool group's keywords is asked again once,
told the message asks for something; the prompt also says a request
never gets an emoji alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
History kept only 400 characters of a picture's prompt, so "add the
other planets" redrew a to-scale diagram without its scale. A technical
picture's note now keeps its kind, up to 1,200 characters of prompt and
its requirements, and the tool tells the model to start a change from
that note, keeping every requirement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
It "corrected" a user about Voyager 1 from what it learned in training.
The system prompt now ends, before the intro, with today's date in the
bot's time zone (late, so the prefix stays cached all day), and the
built-in prompt says its knowledge ends with its training.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
A to-scale diagram drew Earth and the Sun twice: as separate points and
again as one "Earth / Sun". The brief now says to draw each thing once,
with things too close to tell apart sharing one mark and label, and the
text rules that each label appears once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbGfzi38exq5AFMGFUMRMN
@robdevops robdevops changed the title Telegram as a second chat network; image generation with GPT Image 2; chart and send fixes Telegram as a second chat network; image generation with GPT Image 2; prompt and Signal fixes Nov 19, 2026
@robdevops
robdevops merged commit 3b93ad9 into main Nov 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants