fix: Telegram bot multi-server — route /status and /peers via inline keyboard (#41)
When multiple servers share the same bot token, /status and /peers now show a per-server inline button instead of responding immediately. Only the server whose label matches the tapped callback responds; others silently ignore. Fixes duplicate/endless responses.
This commit is contained in:
58
conduit.sh
58
conduit.sh
@@ -7151,21 +7151,26 @@ except Exception:
|
||||
telegram_answer_callback "$cb_id" "Invalid container"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
telegram_answer_callback "$cb_id" ""
|
||||
;;
|
||||
esac
|
||||
continue
|
||||
fi
|
||||
|
||||
# Handle regular commands
|
||||
local cmd="$field2"
|
||||
case "$cmd" in
|
||||
/status|/status@*)
|
||||
st_*)
|
||||
# Only respond if callback matches this server's label
|
||||
local _lbl="${TELEGRAM_SERVER_LABEL:-$(hostname 2>/dev/null || echo 'server')}"
|
||||
local _cb_lbl=$(echo "$_lbl" | tr -cd 'a-zA-Z0-9_-' | head -c 50)
|
||||
[ -z "$_cb_lbl" ] && _cb_lbl=$(hostname 2>/dev/null | tr -cd 'a-zA-Z0-9_-' | head -c 50)
|
||||
[ -z "$_cb_lbl" ] && _cb_lbl="server"
|
||||
if [ "$cb_data" = "st_${_cb_lbl}" ]; then
|
||||
telegram_answer_callback "$cb_id" "Fetching status..."
|
||||
local report=$(build_report)
|
||||
telegram_send "$report"
|
||||
fi
|
||||
;;
|
||||
/peers|/peers@*)
|
||||
pr_*)
|
||||
# Only respond if callback matches this server's label
|
||||
local _lbl="${TELEGRAM_SERVER_LABEL:-$(hostname 2>/dev/null || echo 'server')}"
|
||||
local _cb_lbl=$(echo "$_lbl" | tr -cd 'a-zA-Z0-9_-' | head -c 50)
|
||||
[ -z "$_cb_lbl" ] && _cb_lbl=$(hostname 2>/dev/null | tr -cd 'a-zA-Z0-9_-' | head -c 50)
|
||||
[ -z "$_cb_lbl" ] && _cb_lbl="server"
|
||||
if [ "$cb_data" = "pr_${_cb_lbl}" ]; then
|
||||
telegram_answer_callback "$cb_id" "Fetching peers..."
|
||||
local total_peers=0
|
||||
local total_cing=0
|
||||
for i in $(seq 1 ${CONTAINER_COUNT:-1}); do
|
||||
@@ -7177,6 +7182,35 @@ except Exception:
|
||||
total_cing=$((total_cing + ${cing:-0}))
|
||||
done
|
||||
telegram_send "👥 Clients: ${total_peers} connected, ${total_cing} connecting"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
telegram_answer_callback "$cb_id" ""
|
||||
;;
|
||||
esac
|
||||
continue
|
||||
fi
|
||||
|
||||
# Handle regular commands
|
||||
local cmd="$field2"
|
||||
case "$cmd" in
|
||||
/status|/status@*)
|
||||
local _lbl="${TELEGRAM_SERVER_LABEL:-$(hostname 2>/dev/null || echo 'server')}"
|
||||
local _cb_lbl=$(echo "$_lbl" | tr -cd 'a-zA-Z0-9_-' | head -c 50)
|
||||
[ -z "$_cb_lbl" ] && _cb_lbl=$(hostname 2>/dev/null | tr -cd 'a-zA-Z0-9_-' | head -c 50)
|
||||
[ -z "$_cb_lbl" ] && _cb_lbl="server"
|
||||
local _lbl_j=$(printf '%s' "$_lbl" | sed 's/\\/\\\\/g; s/"/\\"/g')
|
||||
local kb="{\"inline_keyboard\":[[{\"text\":\"📊 ${_lbl_j}\",\"callback_data\":\"st_${_cb_lbl}\"}]]}"
|
||||
telegram_send_inline_keyboard "Tap to view status:" "$kb"
|
||||
;;
|
||||
/peers|/peers@*)
|
||||
local _lbl="${TELEGRAM_SERVER_LABEL:-$(hostname 2>/dev/null || echo 'server')}"
|
||||
local _cb_lbl=$(echo "$_lbl" | tr -cd 'a-zA-Z0-9_-' | head -c 50)
|
||||
[ -z "$_cb_lbl" ] && _cb_lbl=$(hostname 2>/dev/null | tr -cd 'a-zA-Z0-9_-' | head -c 50)
|
||||
[ -z "$_cb_lbl" ] && _cb_lbl="server"
|
||||
local _lbl_j=$(printf '%s' "$_lbl" | sed 's/\\/\\\\/g; s/"/\\"/g')
|
||||
local kb="{\"inline_keyboard\":[[{\"text\":\"👥 ${_lbl_j}\",\"callback_data\":\"pr_${_cb_lbl}\"}]]}"
|
||||
telegram_send_inline_keyboard "Tap to view peers:" "$kb"
|
||||
;;
|
||||
/uptime|/uptime@*)
|
||||
local ut_msg="⏱ *Uptime Report*"
|
||||
|
||||
Reference in New Issue
Block a user