feat: add BotHostWithHTTPClient and TelegramRedirectTransport - #56
Merged
Conversation
Production BotHost() hardcodes http.DefaultClient, so nothing can redirect a bot's outbound Bot API calls. The only redirect implementation lived test-only in a Sneat consumer repo. Promote that pattern to exported, reusable code here: BotHostWithHTTPClient(client) is an additive constructor alongside BotHost() (which keeps returning http.DefaultClient exactly as before), and TelegramRedirectTransport is an http.RoundTripper that rewrites api.telegram.org requests to a caller-supplied base URL and rejects every other destination, closing the network boundary rather than opening a general-purpose proxy. This lets a caller (e.g. a dev/test host wired to a Chatwright Telegram Platform Emulator) redirect outbound Telegram traffic without touching bots-api-telegram's hardcoded APIEndpoint constant, which all production Sneat bots depend on. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SkkrXdtf8mU2GRo2hHsHT1 Signed-off-by: Alexander Trakhimenok <alex@trakhimenok.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BotHost()hardcodeshttp.DefaultClientforGetHTTPClient, so nothing running this host can redirect its outbound Bot API calls anywhere else. The only implementation that redirects Telegram traffic lived test-only, inside a Sneat consumer repo (sneat-go/pkg/bots/botinit/listus_branching_host_test.go), driven only throughgo test, never as reusable/production code.BotHostWithHTTPClient(client *http.Client) botHostInterface— additive, alongsideBotHost().BotHost()is unchanged and still always returnshttp.DefaultClient; existing callers see no behaviour change.TelegramRedirectTransport, an exportedhttp.RoundTripper(viaNewTelegramRedirectTransport(baseURL, base)) that rewrites requests bound forapi.telegram.orgto a caller-supplied base URL and rejects every other destination — a closed network boundary, not a general HTTP proxy. Modeled directly on the proven test-onlylistusBranchingTelegramTransportinsneat-go.Why
Sneat's Listus bot needs to be reachable by a Chatwright Telegram Platform Emulator for AI-goal exploration.
bots-api-telegram'stgbotapi.APIEndpointis a hardcodedconst(no override), and changing it would touch a framework every production Sneat bot depends on — out of scope. The only viable seam isbotsfw.BotHost.GetHTTPClient, and this repo's productionBotHost()had no way to control it. This closes that gap in the shared, owned dependency instead of building a local workaround downstream (sneat-gogets only wiring — see its own PR).Test plan
gofmt -l .cleanGOWORK=off go vet ./...GOWORK=off go test -race ./...— all pass, including new tests forBotHostWithHTTPClientandTelegramRedirectTransport(nil-baseURL rejection, incomplete-baseURL rejection, non-Telegram-host rejection, correct rewrite/forward,BotHost()unaffected)golangci-lint run ./...cleanVersioning
Not tagged yet — see the companion
sneat-goPR / session report for what tag this needs beforesneat-gocan consume it as a real (non-replace) dependency.🤖 Generated with Claude Code
https://claude.ai/code/session_01SkkrXdtf8mU2GRo2hHsHT1