Repository navigation
Conversation
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.
What changed
Gemini model selection via env (5a0c8fc)
Before: the Gemini model list was hardcoded in
config/models.go. Every time Gemini added a new model or deprecated an old one, the flow was: edit code → push → rebuild Docker image → redeploy — slow and wasteful for a 4-line change.After: the model list is read from the
GEMINI_MODELSenvironment variable at startup:GEMINI_MODELS=gemini-3.5-flash-lite,gemini-3.7-flash,gemini-3.6-flash,gemini-3.5-flashsync.Onceand cached for the process lifetimeWhat this means day-to-day:
To switch/add/remove models, just set/update
GEMINI_MODELS(in.envor viadocker run -e GEMINI_MODELS=...) and restart the container:No code change, no push, no image rebuild, no redeploy — just restart
Only restart is needed because the env is read once at startup (models are process-lifetime config, so hot-reloading wasn't worth the complexity)
Other notes:
.env.exampleupdated with GEMINI_MODELSSummarization prompt improved (5a0c8fc)
Before: the summarization prompt was a 60+ line inline string inside
SummarizeContentWithGemini(), makingsummarize.gohard to read and review, and the prompt itself had a few loose ends.After:
internal/service/prompt.go—summarize.gonow just doesfmt.Sprintf(summarizePrompt, content), so the summarization logic and the prompt text are cleanly separated"(không có nội dung)"instead of truly empty, which slipped past thesummary == ""check and got sent to users.No behavior change expected for normal articles; mostly cleaner code + fewer edge-case failures.
Sending reliability fixes (d509dac)
1. HTML-escape before sending
The bot sends messages in Telegram HTML mode (
ModeHTML). Title, summary, and link were inserted raw into the message. If an article title from RSS/API contained<,&, or unbalanced tags, Telegram rejected the message and the user silently lost that news item. Now title/summary/link all go throughhtml.EscapeString()before formatting, so malformed text renders as literal characters instead of breaking the send.2. Auto-unsubscribe unreachable users
Every 10-minute cycle, the bot tries to send to all subscribed users. If a user blocked the bot (or deleted their account), every send fails with a 403 and the error was just logged — meaning endless retry+log spam forever for a user who will never receive anything again. Now
SendTeledetects the 403 errors (ErrBlockedByUser,ErrUserIsDeactivated,ErrNotStartedByUser) and callsrepository.UnsubscribeUserright away →is_subscribed = false. That user is excluded from all future cycles until they/subscribeagain manually. Logic lives ininternal/service/handle_unreachable_user.go.3. Retry failed content fetches instead of dropping them
Before: if
GetContentFromURLfailed (site slow/down), the worker immediately sent the title-only fallback message and saved the article to DB. The article was then marked "sent" and never processed again — a transient outage permanently degraded that news item into a bare link.After: fetch failures are retried on subsequent cron cycles:
internal/service/retry_fetch.gotracks attempts per URLRetryable, and the handler skips both sending and saving — the article stays "new", so it's picked up again next cycleNote: the counter is in-memory only, so it resets on bot restart. If retry state needs to survive restarts later, a
retry_countcolumn in the DB schema would be the natural next step.Docs (76ce8ac)
GEMINI_MODELSto the.envexample and a short explanation (optional, comma-separated, tried in order, built-in default used when unset)Testing
go build ./...,go vet ./...,gofmt -l .all passgo test ./... -v