mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-31 18:25:00 +03:00
feat(tgbot): add /broadcast to relay an admin message to all clients (#6510)
* feat(tgbot): add /broadcast to relay an admin message to all clients Admins had no way to reach every client at once: notifications only cover exhausted quotas, so an operator had to copy a message to each client chat by hand. Add an admin-only /broadcast flow to the bot: - /broadcast asks for a message; any message the admin sends — text, rich text, photo, video, file, sticker or a whole album — becomes the broadcast by reference (admin chat + message ids), and a preview self-copy shows the admin exactly what recipients will get while rejecting content Telegram cannot copy before the run starts. - The draft references the original instead of parsing its content, so copyMessage/copyMessages deliver everything 1:1 on behalf of the bot with no forward header (the admin's identity stays private), no caption length pitfalls, and future Telegram message types work without new parsing. - A media group arrives as separate updates; its ids are buffered with a short debounce, sorted, and delivered as one copyMessages call so recipients see the original album. - Delivery runs in a background goroutine (common.GoRecover): sequential sends with a small pause, 429 retry_after honored per recipient, failures counted without stopping the run, progress edited into one card at most every 25 sends or 3 seconds, a cancel button checked between sends, and a final delivered/failed/skipped summary. The summary is edited into the card (only sent separately if the card is gone), so it is never duplicated. - Recipients repeat the notifyExhausted walk: clients with a linked tg_id, deduplicated, admins excluded — they already receive the reports. The message content is never logged. New i18n keys are added to all 13 locales. * fix(tgbot): harden broadcast composition per review - Key the composition per admin chat instead of one process-wide draft: two admins can now compose at once without dropping each other's drafts, and one admin's /broadcast no longer wipes another chat's half-collected album. - Bind each preview card to its own draft via a random token carried in the confirm callback, so a stale Send tap is answered with an error instead of delivering a newer, unapproved draft. - Ignore non-admin senders while a chat composes: the awaiting state is keyed by chat id, and in a group that chat is shared. - Check the cancel flag inside the flood-control retry loop, so a 429 with a long retry_after no longer holds the single broadcast slot after the admin cancelled. - Scale the per-recipient pause by the copied batch size, so an album keeps the same per-second ceiling as a single message. - Trim the comment blocks that exceeded the two-line cap. * fix(tgbot): reset broadcast state on stop and classify 403 as skipped - Clear compositions and cancel the active run from StopBot, next to the per-chat draft resets: an album debounce timer, a confirmable token or a held runner slot must not outlive the receiver that created them. - Sleep flood-control waits in 5 s slices and re-check cancel and bot state between them, so a minutes-long retry_after no longer parks the single-runner slot after the admin cancelled or the bot stopped. - Count Telegram 403 (the chat never started the bot, or blocked it) as skipped instead of failed, log it at debug rather than one warning per recipient, and append one line to the summary naming the reason. - Trim the remaining comment blocks over the two-line cap. * fix(tgbot): count unreachable recipients in broadcast progress throttle The progress card refresh was keyed on sent+failed, which a 403 does not advance since unreachable chats were split out of the failure count. A streak of unreachable recipients while that sum sat on a multiple of broadcastProgressEvery (0 included, so from the very first recipient) edited the card once per chat, doubling the request rate the send delay is sized for and defeating the throttle. Count processed recipients. * fix(tgbot): key broadcast compositions by admin, not chat After #6604 moved conversation state to the admin (chatUser), the broadcast draft map stayed keyed by chat. Two admins composing in one group then shared a slot: the second admin's message dropped the first admin's draft, whose Send tap answered "went wrong" while only the other draft could go out - the same class #6604 fixed for the add-client wizard. Drafts, album buffers and confirm tokens now live under the admin who ran /broadcast. The router now hands handleBroadcastInput only the admin whose own /broadcast is awaiting input, so its sender re-check and the test that fed it a non-admin message directly (an input no route can deliver) are removed. --------- Co-authored-by: MHSanaei <ho3ein.sanaei@gmail.com>
This commit is contained in:
@@ -2425,6 +2425,7 @@
|
||||
"usageDesc": "Xem mức dùng của khách: /usage email",
|
||||
"inboundDesc": "Tìm inbound: /inbound tên (quản trị)",
|
||||
"restartDesc": "Khởi động lại lõi Xray (quản trị)",
|
||||
"broadcastDesc": "Gửi tin nhắn tới tất cả khách hàng (quản trị)",
|
||||
"clearallDesc": "Đặt lại lưu lượng mọi khách hàng (quản trị)"
|
||||
},
|
||||
"messages": {
|
||||
@@ -2481,6 +2482,15 @@
|
||||
"error_add_client": "⚠️ Lỗi:\n\n {{ .error }}",
|
||||
"using_default_value": "Được rồi, tôi sẽ sử dụng giá trị mặc định. 😊",
|
||||
"incorrect_input": "Dữ liệu bạn nhập không hợp lệ.\nCác chuỗi phải liền mạch và không có dấu cách.\nVí dụ đúng: aaaaaa\nVí dụ sai: aaa aaa 🚫",
|
||||
"broadcastAskText": "📤 Phát tin: gửi cho tôi tin nhắn để chuyển tới khách hàng của bạn — văn bản, ảnh, video, tệp hoặc cả bộ ảnh.",
|
||||
"broadcastAlreadyRunning": "❗ Một bản phát đang chạy, hãy đợi nó hoàn tất.",
|
||||
"broadcastNoRecipients": "❗ Không có khách hàng nào gắn Telegram ID.",
|
||||
"broadcastPreview": "📤 Tin nhắn này sẽ được gửi tới {{ .Count }} người nhận. Gửi chứ?",
|
||||
"broadcastNotCopyable": "❗ Không thể sao chép tin nhắn này để phát. Hãy gửi tin nhắn khác.",
|
||||
"broadcastUnreachable": "ℹ️ {{ .Count }} người nhận chưa từng bắt đầu bot (hoặc đã chặn nó) nên không thể nhắn tin — hãy đề nghị họ nhấn Start.",
|
||||
"broadcastProgress": "📤 Đã gửi {{ .Sent }}/{{ .Total }} (thất bại: {{ .Failed }})\r\n",
|
||||
"broadcastFinished": "✅ Phát tin hoàn tất.\r\n👥 Người nhận: {{ .Total }}\r\n📨 Đã gửi: {{ .Sent }}\r\n🚫 Thất bại: {{ .Failed }}\r\n⏭ Bỏ qua: {{ .Skipped }}\r\n⏱ Thời gian: {{ .Time }}\r\n",
|
||||
"broadcastCanceled": "🛑 Đã hủy phát tin.\r\n👥 Người nhận: {{ .Total }}\r\n📨 Đã gửi: {{ .Sent }}\r\n🚫 Thất bại: {{ .Failed }}\r\n⏭ Bỏ qua: {{ .Skipped }}\r\n⏱ Thời gian: {{ .Time }}\r\n",
|
||||
"AreYouSure": "Bạn có chắc không? 🤔",
|
||||
"SuccessResetTraffic": "📧 Email: {{ .ClientEmail }}\n🏁 Kết quả: ✅ Thành công",
|
||||
"FailedResetTraffic": "📧 Email: {{ .ClientEmail }}\n🏁 Kết quả: ❌ Thất bại \n\n🛠️ Lỗi: [ {{ .ErrorMessage }} ]",
|
||||
@@ -2499,6 +2509,7 @@
|
||||
"buttons": {
|
||||
"closeKeyboard": "❌ Đóng Bàn Phím",
|
||||
"cancel": "❌ Hủy",
|
||||
"broadcastSend": "📤 Gửi ngay",
|
||||
"cancelReset": "❌ Hủy Đặt Lại",
|
||||
"cancelIpLimit": "❌ Hủy Giới Hạn IP",
|
||||
"confirmResetTraffic": "✅ Xác Nhận Đặt Lại Lưu Lượng?",
|
||||
@@ -2539,6 +2550,9 @@
|
||||
"SortedTrafficUsageReport": "Báo cáo sử dụng lưu lượng đã sắp xếp"
|
||||
},
|
||||
"answers": {
|
||||
"broadcastStarted": "🚀 Đã bắt đầu phát tin.",
|
||||
"broadcastCanceling": "🛑 Bản phát sẽ dừng sau người nhận hiện tại.",
|
||||
"broadcastCanceled": "❌ Đã hủy phát tin.",
|
||||
"successfulOperation": "✅ Thành công!",
|
||||
"errorOperation": "❗ Lỗi Trong Quá Trình Thực Hiện.",
|
||||
"getInboundsFailed": "❌ Không Thể Lấy Được Inbounds",
|
||||
|
||||
Reference in New Issue
Block a user