mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-28 08:45:01 +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": "查看客戶端用量:/usage 郵箱",
|
||||
"inboundDesc": "搜尋入站:/inbound 備註(管理員)",
|
||||
"restartDesc": "重啟 Xray 核心(管理員)",
|
||||
"broadcastDesc": "向所有客戶端群發訊息(管理員)",
|
||||
"clearallDesc": "重置所有客戶端流量(管理員)"
|
||||
},
|
||||
"messages": {
|
||||
@@ -2481,6 +2482,15 @@
|
||||
"error_add_client": "⚠️ 錯誤:\n\n {{ .error }}",
|
||||
"using_default_value": "好的,我會使用預設值。 😊",
|
||||
"incorrect_input": "您的輸入無效。\n短語應連續輸入,不能有空格。\n正確示例: aaaaaa\n錯誤示例: aaa aaa 🚫",
|
||||
"broadcastAskText": "📤 群發:請把要發給客戶的訊息傳給我 — 文字、照片、影片、檔案或整個相簿都可以。",
|
||||
"broadcastAlreadyRunning": "❗ 已有群發正在進行,請等待其完成。",
|
||||
"broadcastNoRecipients": "❗ 沒有綁定 Telegram ID 的客戶端。",
|
||||
"broadcastPreview": "📤 此訊息將傳送給 {{ .Count }} 位收件人。要傳送嗎?",
|
||||
"broadcastNotCopyable": "❗ 此訊息無法複製用於群發,請傳送其他訊息。",
|
||||
"broadcastUnreachable": "ℹ️ {{ .Count }} 位收件人從未啟動過機器人(或已將其封鎖),無法傳送訊息 — 請請他們按下 Start。",
|
||||
"broadcastProgress": "📤 已傳送 {{ .Sent }}/{{ .Total }}(失敗:{{ .Failed }})\r\n",
|
||||
"broadcastFinished": "✅ 群發完成。\r\n👥 收件人:{{ .Total }}\r\n📨 已送達:{{ .Sent }}\r\n🚫 失敗:{{ .Failed }}\r\n⏭ 已跳過:{{ .Skipped }}\r\n⏱ 費時:{{ .Time }}\r\n",
|
||||
"broadcastCanceled": "🛑 群發已取消。\r\n👥 收件人:{{ .Total }}\r\n📨 已送達:{{ .Sent }}\r\n🚫 失敗:{{ .Failed }}\r\n⏭ 已跳過:{{ .Skipped }}\r\n⏱ 費時:{{ .Time }}\r\n",
|
||||
"AreYouSure": "你確定嗎?🤔",
|
||||
"SuccessResetTraffic": "📧 電子郵件: {{ .ClientEmail }}\n🏁 結果: ✅ 成功",
|
||||
"FailedResetTraffic": "📧 電子郵件: {{ .ClientEmail }}\n🏁 結果: ❌ 失敗 \n\n🛠️ 錯誤: [ {{ .ErrorMessage }} ]",
|
||||
@@ -2499,6 +2509,7 @@
|
||||
"buttons": {
|
||||
"closeKeyboard": "❌ 關閉鍵盤",
|
||||
"cancel": "❌ 取消",
|
||||
"broadcastSend": "📤 立即傳送",
|
||||
"cancelReset": "❌ 取消重置",
|
||||
"cancelIpLimit": "❌ 取消 IP 限制",
|
||||
"confirmResetTraffic": "✅ 確認重置流量?",
|
||||
@@ -2539,6 +2550,9 @@
|
||||
"SortedTrafficUsageReport": "排序過的流量使用報告"
|
||||
},
|
||||
"answers": {
|
||||
"broadcastStarted": "🚀 群發已開始。",
|
||||
"broadcastCanceling": "🛑 群發將在目前收件人之後停止。",
|
||||
"broadcastCanceled": "❌ 群發已取消。",
|
||||
"successfulOperation": "✅ 成功!",
|
||||
"errorOperation": "❗ 操作錯誤。",
|
||||
"getInboundsFailed": "❌ 獲取入站資訊失敗。",
|
||||
|
||||
Reference in New Issue
Block a user