Merge branch XzbestX into main

This commit is contained in:
2026-05-27 11:21:27 +09:00
8 changed files with 318 additions and 32 deletions
+3 -7
View File
@@ -1,6 +1,6 @@
TG_TOKEN=8627237404:AAG8wBzJOrTVpxQul93S98N5F6E513r6ImQ
MAX_TOKEN=f9LHodD0cOKnd3fqVPTcDK3htO_ZkeYXd0YMddIswlYakC0_EwMG7DucyrZh0-E4ki9d5c-WaygJBnQp-8MS
TG_TOKEN=8845243080:AAHUN8uooRapQbH4hBN5gPX9kkZqKj8ixnI
MAX_TOKEN=f9LHodD0cOJYa8zzWI_4KS_mUCnUSIcmxlPIoJXIujjapnGbNMQfreciWRtC_StLAPuzewChQ-BJ2CHokFPL
TG_API_URL=http://dpi-bypass:8443
# Max file size for forwarding (in MB). 0 or not set = unlimited.
# TG→MAX: Telegram getFile API is limited to 20 MB.
@@ -19,10 +19,6 @@ MAX_TOKEN=f9LHodD0cOKnd3fqVPTcDK3htO_ZkeYXd0YMddIswlYakC0_EwMG7DucyrZh0-E4ki9d5c
# WEBHOOK_URL=https://bridge.example.com
# WEBHOOK_PORT=8443
# Локальный Telegram Bot API сервер (снимает лимиты на размер файлов)
# https://github.com/tdlib/telegram-bot-api
# TG_API_URL=http://localhost:8081
# Уровень логирования: debug, info (по умолчанию), warn, error
# LOG_LEVEL=info
+271
View File
@@ -0,0 +1,271 @@
# Changelog
Все значимые изменения проекта [MaxTelegramBridgeBot](https://github.com/BEARlogin/max-telegram-bridge-bot).
---
## [v0.3.20] — 2026-05-13
- Queue expire: notify crosspost owner DM, not the channel
- Веб хуки. Разделение для TG и Max
## [v0.3.19] — 2026-05-08
- Edit messages with media in MAX instead of sending new ones (TG→MAX)
## [v0.3.18] — 2026-05-05
- Forward MAX→TG: relay Link.Message content for repost messages
## [v0.3.17] — 2026-04-30
- Add DISABLE_PREFIX env + default OFF for chats not in pairs
## [v0.3.16] — 2026-04-24
- Fix: video-without-caption TG→MAX rejected as send-message.empty
## [v0.3.15] — 2026-04-24
- Route crosspost error notifications to owner DM, not to the channel
## [v0.3.14] — 2026-04-24
- Preserve links in TG→MAX crossposts; deliver text when video fails
## [v0.3.13] — 2026-04-24
- Add created_at to pairs for pair growth stats
## [v0.3.12] — 2026-04-23
- Simplify upload error hints — user-facing, no config details
## [v0.3.11] — 2026-04-23
- Surface TG→MAX upload errors in chat (not only in log)
- Document /thread_bridge and Part 1 reply routing in README
## [v0.3.10] — 2026-04-23
- Add /thread_bridge: link a single TG forum thread to a separate MAX chat
## [v0.3.9] — 2026-04-23
- Route MAX replies to source TG thread + crosspost/UX fixes
- Default prefix off, clarify admin requirement for TG forum groups
- Treat anonymous admins as admins for /bridge, /thread etc.
## [v0.3.8] — 2026-04-20
- Apply replacements in crosspost forwardTgToMax
## [v0.3.7] — 2026-04-16
- Fix release workflow: pass changelog via file to avoid shell expansion
- Очередь отправки (#34)
- Claude Code Review workflow
- Claude PR Assistant workflow
- Cache-bust favicon in README
- Revert README to plain links with logo and support link
- Redesign README with centered layout, badges and logo
- Add support/donate link to README
## [v0.3.6] — 2026-04-08
- Fix overlapping entities (bold+italic+strike) duplicating text
## [v0.3.5] — 2026-04-08
- Fix formatting in both TG→MAX and MAX→TG directions
## [v0.3.4] — 2026-04-03
- Edit messages with media in MAX instead of sending new ones (TG→MAX)
## [v0.3.3] — 2026-04-03
- **Fix:** Other bots' messages are now forwarded. Previously all bot messages were silently skipped. Now only the bridge bot itself is filtered — messages from any other bot in the group are forwarded normally.
## [v0.3.2] — 2026-04-03 *(текущая локальная версия)*
- **New:** Sync edits toggle — new "✏️ Синк правок" button in crosspost management (both TG and MAX bots). When enabled, edits and deletes sync between linked channels respecting the direction setting. Disabled by default.
## [v0.3.1] — 2026-04-02
- **Fixes:**
- Caption formatting on photo/album crosspost — bold, italic, links and other formatting now preserved when crossposting photos and albums from TG to MAX
- Crosspost direction respected for edits — editing a post in MAX no longer updates the TG post when direction is set to TG→MAX only
- Delete sync disabled for crosspost channels — deleting a post in one channel no longer removes it from the linked channel (only works for regular bridge pairs)
## [v0.3.0] — 2026-04-02
- **Forum topics support:** Messages from MAX are delivered to the correct forum topic in TG groups
- `/thread` command — send it in a topic to route all MAX→TG messages there
- Send `/thread` in General to reset back to default
- Auto-reset when forum topics are disabled on the group
- **TG library migration:** Replaced `go-telegram-bot-api/v5` (2021) with `go-telegram/bot` v1.20.0 (Bot API 9.5)
- New `TGSender` adapter interface — library is fully isolated, easy to swap
- Proper error wrapping with HTTP status codes (403/400/404/429)
- All command responses go to the same topic they were sent from
- Strip @botname from commands in groups
- Auto-migrate TG chat ID when group upgrades to supergroup
## [v0.2.4] — 2026-04-01
- Fix video upload: must upload to CDN even when token is in endpoint
- Fix video download returning 0 bytes: LimitReader overflow
- Add text replacements info to /help in both TG and MAX bots
## [v0.2.3] — 2026-03-29
- Multiple fixes and updates across bridge.go, max.go, telegram.go, format.go, upload.go, queue.go
- Multiple README updates
- Release workflow improvements
## [v0.2.1] — 2026-03-26
- Fix file name lost when forwarding MAX→TG
- Add link to maxtelegrambridge.ru in README
- Update RouterOS.yml
## [v0.2.0] — 2026-03-26
- Add text replacements for crosspost channels
- Add developer section in README
- Add TG_API_URL to README and .env.example
## [v0.1.2] — 2026-03-25
- Fix crosspost channel albums: buffer media groups instead of sending individually
- Fix photo upload: use UploadPhotoFromReader for local TG API
- Fix photo upload for local TG Bot API: download and upload ourselves
- Implement editMessageMedia for MAX→TG media edits
- Fix nil pointer crashes, add video albums, harden ALLOWED_USERS
- Fix multi-image forwarding: send all attachments and group albums
- Add ALLOWED_USERS whitelist to restrict bridge and crosspost setup
- Add configurable log level via LOG_LEVEL env var
- Clarify crosspost instruction: forward to MAX bot DM
- Use HTML parse mode for copyable code blocks in bot messages
- Fix broken crosspost: remove Markdown parsing from bot messages
- Add copyable code blocks and bot links to bridge instructions
- README: update features, add media edit limitation note
- Handle edited messages with media: forward as new message
- Treat 'attachment.not.ready after retries' as permanent error in queue
- Download MAX media to bridge server before sending to TG
- Fix local Bot API file serving: correct URL path + nginx alias
- Support custom TG Bot API server (TG_API_URL env)
- Revert HTTP timeout to 60s — 15s too short for media uploads
- Fix MAX webhook: explicitly subscribe to message_created events
- Remove binary and db backup from repo
- Switch to webhook mode for instant message delivery
- Don't retry permanent errors (403/404) in send queue
- Add retry queue for MAX→TG direction
- Fix nil pointer crash: channel posts have no From field
- Add sticker forwarding MAX→TG
- Auto-create GitHub release on tag push with changelog
- Add GIF (Animation) and Sticker forwarding TG→MAX
- Add user/chat IDs to all log messages for debugging
- Log TG user ID on channel post forward for crosspost
- Track users, dual owner IDs for crosspost (TG + MAX)
- Soft delete for crossposts — track deleted_at and deleted_by
- Filter /crosspost list by owner — show only own links
- Add owner_id to crossposts, restrict management to owner
- Add support link to /start message
- Add retry queue for failed message delivery
- Add CC BY-NC 4.0 license
## [v0.0.16] — 2026-03-25
- Fix photo upload: use UploadPhotoFromReader for local TG API
- Fix photo upload for local TG Bot API: download and upload ourselves
- Implement editMessageMedia for MAX→TG media edits
- Fix nil pointer crashes, add video albums, harden ALLOWED_USERS
- Fix multi-image forwarding: send all attachments and group albums
- Add ALLOWED_USERS whitelist to restrict bridge and crosspost setup
- Add configurable log level via LOG_LEVEL env var
- Clarify crosspost instruction: forward to MAX bot DM
- Use HTML parse mode for copyable code blocks in bot messages
- Fix broken crosspost: remove Markdown parsing from bot messages
- Add copyable code blocks and bot links to bridge instructions
- README: update features, add media edit limitation note
- Handle edited messages with media: forward as new message
- Treat 'attachment.not.ready after retries' as permanent error in queue
- Download MAX media to bridge server before sending to TG
- Fix local Bot API file serving: correct URL path + nginx alias
- Support custom TG Bot API server (TG_API_URL env)
- Revert HTTP timeout to 60s — 15s too short for media uploads
- Fix MAX webhook: explicitly subscribe to message_created events
- Remove binary and db backup from repo
## [v0.0.15] — 2026-03-24
- Implement editMessageMedia for MAX→TG media edits
- Fix nil pointer crashes, add video albums, harden ALLOWED_USERS
- Fix multi-image forwarding: send all attachments and group albums
- Add ALLOWED_USERS whitelist to restrict bridge and crosspost setup
- Add configurable log level via LOG_LEVEL env var
- Clarify crosspost instruction: forward to MAX bot DM
- Use HTML parse mode for copyable code blocks in bot messages
- Fix broken crosspost: remove Markdown parsing from bot messages
- Add copyable code blocks and bot links to bridge instructions
- README: update features, add media edit limitation note
- Handle edited messages with media: forward as new message
- Treat 'attachment.not.ready after retries' as permanent error in queue
- Download MAX media to bridge server before sending to TG
- Fix local Bot API file serving: correct URL path + nginx alias
- Support custom TG Bot API server (TG_API_URL env)
- Revert HTTP timeout to 60s — 15s too short for media uploads
- Fix MAX webhook: explicitly subscribe to message_created events
- Remove binary and db backup from repo
- Switch to webhook mode for instant message delivery
- Don't retry permanent errors (403/404) in send queue
## [v0.0.14] — 2026-03-21
- README: update features, add media edit limitation note
- Handle edited messages with media: forward as new message
- Treat 'attachment.not.ready after retries' as permanent error in queue
- Download MAX media to bridge server before sending to TG
- Fix local Bot API file serving: correct URL path + nginx alias
- Support custom TG Bot API server (TG_API_URL env)
- Revert HTTP timeout to 60s — 15s too short for media uploads
- Fix MAX webhook: explicitly subscribe to message_created events
- Remove binary and db backup from repo
- Switch to webhook mode for instant message delivery
- Don't retry permanent errors (403/404) in send queue
- Add retry queue for MAX→TG direction
- Fix nil pointer crash: channel posts have no From field
- Add sticker forwarding MAX→TG
- Auto-create GitHub release on tag push with changelog
- Add GIF (Animation) and Sticker forwarding TG→MAX
- Add user/chat IDs to all log messages for debugging
- Log TG user ID on channel post forward for crosspost
- Track users, dual owner IDs for crosspost (TG + MAX)
- Soft delete for crossposts — track deleted_at and deleted_by
## [v0.0.13] — 2026-03-20
- Download MAX media to bridge server before sending to TG
- Fix local Bot API file serving: correct URL path + nginx alias
- Support custom TG Bot API server (TG_API_URL env)
- Revert HTTP timeout to 60s — 15s too short for media uploads
- Fix MAX webhook: explicitly subscribe to message_created events
- Remove binary and db backup from repo
- Switch to webhook mode for instant message delivery
- Don't retry permanent errors (403/404) in send queue
- Add retry queue for MAX→TG direction
- Fix nil pointer crash: channel posts have no From field
- Add sticker forwarding MAX→TG
- Auto-create GitHub release on tag push with changelog
- Add GIF (Animation) and Sticker forwarding TG→MAX
- Add user/chat IDs to all log messages for debugging
- Log TG user ID on channel post forward for crosspost
- Track users, dual owner IDs for crosspost (TG + MAX)
- Soft delete for crossposts — track deleted_at and deleted_by
- Filter /crosspost list by owner — show only own links
- Add owner_id to crossposts, restrict management to owner
- Add support link to /start message
---
[v0.3.20]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.20
[v0.3.19]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.19
[v0.3.18]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.18
[v0.3.17]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.17
[v0.3.16]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.16
[v0.3.15]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.15
[v0.3.14]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.14
[v0.3.13]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.13
[v0.3.12]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.12
[v0.3.11]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.11
[v0.3.10]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.10
[v0.3.9]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.9
[v0.3.8]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.8
[v0.3.7]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.7
[v0.3.6]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.6
[v0.3.5]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.5
[v0.3.4]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.4
[v0.3.3]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.3
[v0.3.2]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.2
[v0.3.1]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.1
[v0.3.0]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.3.0
[v0.2.4]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.2.4
[v0.2.3]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.2.3
[v0.2.1]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.2.1
[v0.2.0]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.2.0
[v0.1.2]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.1.2
[v0.0.16]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.0.16
[v0.0.15]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.0.15
[v0.0.14]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.0.14
[v0.0.13]: https://github.com/BEARlogin/max-telegram-bridge-bot/releases/tag/v0.0.13
-7
View File
@@ -8,9 +8,6 @@ services:
depends_on:
postgres:
condition: service_healthy
networks:
- default
- caddy-net
postgres:
image: postgres:17-alpine
@@ -29,7 +26,3 @@ services:
volumes:
pgdata:
networks:
caddy-net:
external: true
+7 -10
View File
@@ -184,10 +184,8 @@ func (b *Bridge) listenMax(ctx context.Context) {
if text == "/whoami" {
m := maxbot.NewMessage().SetChat(chatID).SetText(
"MaxTelegramBridgeBot — мост между Telegram и MAX.\n" +
"Автор: Andrey Lugovskoy (@BEARlogin)\n" +
"Исходники: https://github.com/BEARlogin/max-telegram-bridge-bot\n" +
"Лицензия: CC BY-NC 4.0")
"Бот-мост между MAX и Telegram.\n" +
"Версия: 0.3.2")
b.maxApi.Messages.Send(ctx, m)
continue
}
@@ -221,8 +219,7 @@ func (b *Bridge) listenMax(ctx context.Context) {
" MAX: " + b.cfg.MaxBotURL + "\n" +
"2. В одном из чатов отправьте /bridge\n" +
"3. Бот выдаст ключ — отправьте его в другом чате\n" +
"4. Готово!\n\n" +
"Поддержка: https://github.com/BEARlogin/max-telegram-bridge-bot/issues")
"4. Готово!")
b.maxApi.Messages.Send(ctx, m)
continue
}
@@ -419,11 +416,11 @@ func (b *Bridge) listenMax(ctx context.Context) {
}
// Достаём TG owner ID (кто переслал пост из TG-канала в TG-бот)
b.cpTgOwnerMu.Lock()
tgOwnerID := b.cpTgOwner[tgChannelID]
b.cpTgOwnerMu.Unlock()
b.cpTgOwnerMu.Lock()
tgOwnerID := b.cpTgOwner[tgChannelID]
b.cpTgOwnerMu.Unlock()
if err := b.repo.PairCrosspost(tgChannelID, maxChannelID, msgUpd.Message.Sender.UserId, tgOwnerID); err != nil {
if err := b.repo.PairCrosspost(tgChannelID, maxChannelID, msgUpd.Message.Sender.UserId, tgOwnerID); err != nil {
slog.Error("crosspost pair failed", "err", err)
m := maxbot.NewMessage().SetChat(chatID).SetText("Ошибка при создании связки.")
b.maxApi.Messages.Send(ctx, m)
+20
View File
@@ -0,0 +1,20 @@
@echo off
chcp 65001 > nul
cd /d "%~dp0"
echo [MAX Bridge Bot] Загрузка переменных из .env и запуск...
echo.
powershell -Command ^
Get-Content '.env' ^| ForEach-Object { ^
$parts = $_ -split '=', 2; ^
if ($parts.Count -eq 2) { ^
Set-Item -Path \"env:$($parts[0].Trim())\" -Value $parts[1].Trim() ^
} ^
}; ^
Write-Host '--- Bot started. Press Ctrl+C to stop ---'; ^
go run .
echo.
echo [MAX Bridge Bot] Бот остановлен.
pause
+12
View File
@@ -0,0 +1,12 @@
@echo off
chcp 65001 > nul
cd /d "%~dp0"
echo [MAX Bridge Bot] Остановка бота...
echo.
taskkill /f /im bearlogin-bridge.exe > nul 2>&1
taskkill /f /im go.exe > nul 2>&1
echo [MAX Bridge Bot] Бот остановлен.
pause
+3 -6
View File
@@ -134,10 +134,8 @@ func (b *Bridge) listenTelegram(ctx context.Context) {
if text == "/whoami" {
b.tg.SendMessage(ctx, msg.Chat.ID,
"MaxTelegramBridgeBot — мост между Telegram и MAX.\n"+
"Автор: Andrey Lugovskoy (@BEARlogin)\n"+
"Исходники: https://github.com/BEARlogin/max-telegram-bridge-bot\n"+
"Лицензия: CC BY-NC 4.0", &SendOpts{ThreadID: msg.MessageThreadID})
"Бот-мост между Telegram и MAX.\n"+
"Версия: 0.3.2", &SendOpts{ThreadID: msg.MessageThreadID})
continue
}
@@ -169,8 +167,7 @@ func (b *Bridge) listenTelegram(ctx context.Context) {
"2. В MAX сделайте бота админом группы\n"+
"3. В одном из чатов отправьте /bridge\n"+
"4. Бот выдаст ключ — отправьте /bridge <ключ> в другом чате\n"+
"5. Готово!\n\n"+
"Поддержка: https://github.com/BEARlogin/max-telegram-bridge-bot/issues", &SendOpts{ThreadID: msg.MessageThreadID})
"5. Готово!", &SendOpts{ThreadID: msg.MessageThreadID})
continue
}
+2 -2
View File
@@ -24,7 +24,7 @@ func NewTGBotSender(ctx context.Context, token, apiURL string) (*tgBotSender, er
s := &tgBotSender{
token: token,
apiURL: apiURL,
updates: make(chan TGUpdate, 5000),
updates: make(chan TGUpdate, 100),
}
opts := []bot.Option{
@@ -237,7 +237,7 @@ func (s *tgBotSender) GetFile(ctx context.Context, fileID string) (string, error
func (s *tgBotSender) GetFileDirectURL(filePath string) string {
if s.apiURL != "" {
return s.apiURL + "/file/bot" + s.token + "/" + filePath
return s.apiURL + "/" + filePath
}
return "https://api.telegram.org/file/bot" + s.token + "/" + filePath
}