Skip to content

feat(telegram): support forum topic via native message_thread_id - #142

Merged
appleboy merged 1 commit into
masterfrom
feat/message-thread-id
Aug 14, 2026
Merged

feat(telegram): support forum topic via native message_thread_id#142
appleboy merged 1 commit into
masterfrom
feat/message-thread-id

Conversation

@appleboy

Copy link
Copy Markdown
Owner

Summary

Adds Telegram forum topic support (message_thread_id) using the Bot API's native parameter instead of the HTTP-transport query-injection workaround proposed in #141.

The old go-telegram-bot-api v4.6.4+incompatible (2018, upstream archived) has no message_thread_id support, which is why #141 had to patch it in at the http.RoundTripper level. This PR migrates to the community-maintained OvyFlash/telegram-bot-api fork (the one recommended by the archived upstream), where every chat config embeds BaseChat.MessageThreadID — the parameter is only sent when non-zero, and only on actual send requests.

Changes:

  • Dependency: go-telegram-bot-api/telegram-bot-api v4.6.4+incompatibleOvyFlash/telegram-bot-api (tracks current Bot API).
  • New setting: message_thread_id (PLUGIN_MESSAGE_THREAD_ID / TELEGRAM_MESSAGE_THREAD_ID / INPUT_MESSAGE_THREAD_ID), applied to all message types: text, photo, document, sticker, audio, voice, video, location, venue.
  • API migration (mechanical): New*Upload(user, path)New*(user, tgbotapi.FilePath(path)), DisableWebPagePreviewLinkPreviewOptions.IsDisabled, NewBotAPIWithClientNewBotAPIWithOptions(token, WithHTTPClient(...)) (non-deprecated form; SOCKS5 proxy path preserved).
  • Docs: DOCS.md gains a forum-topic example and a message_thread_id parameter reference entry.

Related issues

Architecture / flow

flowchart LR
    subgraph main.go
        F["--message.thread.id flag<br/>PLUGIN_MESSAGE_THREAD_ID"]
    end
    subgraph plugin.go
        C["Config.MessageThreadID"]
        E["Exec: per-recipient send loops<br/>(text/photo/document/sticker/<br/>audio/voice/video/location/venue)"]
    end
    subgraph "OvyFlash/telegram-bot-api"
        B["BaseChat.MessageThreadID<br/>AddNonZero(message_thread_id)"]
    end
    T["Telegram Bot API"]
    F --> C --> E --> B --> T
    style F fill:#d4edda,stroke:#28a745
    style C fill:#d4edda,stroke:#28a745
    style E fill:#fff3cd,stroke:#ffc107
    style B fill:#d4edda,stroke:#28a745
Loading

Green = new, yellow = modified (library migration).

AI authorship

  • No AI was used
  • AI was used
    • Tool / model: Claude Code (claude-fable-5)
    • AI-authored files: plugin.go, main.go, DOCS.md, go.mod, go.sum
    • Human line-by-line reviewed: None — not yet reviewed by a human.

Change classification

  • Leaf change
  • Core change — the library swap touches every message-send path of the plugin.

Plan reference

Replace the http.RoundTripper query-injection approach of #141 with the library's native MessageThreadID field, taking the opportunity to move off the archived v4 dependency.

Verification

  • Automated: go build ./... ✅, go vet ./... ✅, go test ./... (13 tests) ✅, golangci-lint run ./... ✅ (all local)
  • Manual: none
  • Not run: live send to a forum supergroup topic (requires a real bot token + forum group; existing integration tests that need TELEGRAM_TOKEN run in CI)

Security check

  • No secrets in the diff
  • External inputs are validated (thread id parsed as int by urfave/cli; zero value omits the parameter)
  • Errors do not leak internals (existing token-redaction in Send unchanged)
  • N/A — no auth/permission interface changed

Risk and rollback

  • Risk: the dependency migration changes the request-encoding layer for all sends (multipart upload handling, param serialization). A behavioral regression would affect every notification type, not just forum topics. Note: when message_thread_id is set and to includes non-forum chats, Telegram rejects those sends with "message thread not found" — inherent to a global thread id setting.
  • Rollback: revert the single commit; no schema, config, or wire-format migration involved.

Reviewer guide

  • Read carefully: plugin.go — bot construction (SOCKS5 path) and the nine send loops; confirm each sets MessageThreadID and the constructor migration is faithful.
  • Spot-check: main.go flag wiring, DOCS.md wording, go.mod/go.sum (dependency swap drops technoweenie/multipartstreamer).

🤖 Generated with Claude Code

* migrate from go-telegram-bot-api v4.6.4+incompatible to the maintained
  OvyFlash/telegram-bot-api fork (recommended by the archived upstream)
* add message_thread_id setting (PLUGIN_MESSAGE_THREAD_ID) and set the
  native BaseChat.MessageThreadID field on every outgoing message type
* replace deprecated constructors: New*Upload -> New* with FilePath,
  NewBotAPIWithClient -> NewBotAPIWithOptions, and
  DisableWebPagePreview -> LinkPreviewOptions.IsDisabled
* document message_thread_id in DOCS.md

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 14, 2026 14:30
@appleboy
appleboy merged commit 8349723 into master Aug 14, 2026
13 of 15 checks passed
@appleboy
appleboy deleted the feat/message-thread-id branch August 14, 2026 14:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds Telegram forum-topic support by introducing a message_thread_id setting and migrating the plugin from the archived go-telegram-bot-api dependency to the maintained OvyFlash/telegram-bot-api fork so the native message_thread_id parameter can be sent without HTTP transport hacks.

Changes:

  • Swaps Telegram Bot API Go dependency to github.com/OvyFlash/telegram-bot-api and updates message-send call sites accordingly.
  • Adds a new message_thread_id configuration/flag/env var and applies it across all outbound message types.
  • Updates documentation to include the new setting and an example for forum topics.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
plugin.go Migrates Bot API usage, wires MessageThreadID and link preview options into all send paths.
main.go Adds CLI flag/env var wiring for message.thread.idConfig.MessageThreadID.
go.mod Replaces archived Telegram Bot API library with OvyFlash/telegram-bot-api.
go.sum Updates dependency checksums for the new Telegram library and removed transitive deps.
DOCS.md Documents message_thread_id and adds a forum-topic example.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread plugin.go
for _, user := range ids {
for _, txt := range renderedMessages {
msg := tgbotapi.NewMessage(user, txt)
msg.MessageThreadID = p.Config.MessageThreadID
Comment thread plugin.go
for _, user := range ids {
for _, txt := range renderedMessages {
msg := tgbotapi.NewMessage(user, txt)
msg.MessageThreadID = p.Config.MessageThreadID
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