Files
ewoooc/scripts/tg_notify.sh
ogt 4cdf0793a4 fix(review): 修復 /review 機制的 7 個審查問題
必修:
- 路由表新增 .sh → critic、.yaml/.yml → tool-expert 兩條規則
- refactor-specialist 改為並行(不取代 critic),確保 vuln-verifier 觸發條件正確
- Phase B 觸發條件從 'critic 含 🔴' 改為 '任一主審 Agent 含 🔴'

選修:
- Stage 0 新增 >2000 行 diff 保護(降級為 --stat 摘要)
- Stage 2.5 移除 '立即' 矛盾描述,改為 'Phase A 全回報後逐一發送'
- tg_notify.sh: 新增 CHAT_IDS 解析後空值守衛
- tg_notify.sh: 改用 printf | --data-urlencode 'text@-' 支援多行訊息

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 01:39:39 +08:00

51 lines
1.3 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# scripts/tg_notify.sh — Code Review Telegram 告警工具
# 用法bash scripts/tg_notify.sh <info|warn|error> "<HTML 訊息>"
set -euo pipefail
LEVEL="${1:-info}"
MESSAGE="${2:-}"
TOKEN="${TELEGRAM_BOT_TOKEN:-}"
CHAT_IDS_RAW="${TELEGRAM_CHAT_IDS:-}"
if [[ -z "$TOKEN" ]]; then
echo "[tg_notify] TELEGRAM_BOT_TOKEN 未設定,跳過通知" >&2
exit 0
fi
if [[ -z "$CHAT_IDS_RAW" ]]; then
echo "[tg_notify] TELEGRAM_CHAT_IDS 未設定,跳過通知" >&2
exit 0
fi
case "$LEVEL" in
info) PREFIX="" ;;
warn) PREFIX="⚠️" ;;
error) PREFIX="🚨" ;;
*) PREFIX="📌" ;;
esac
FULL_MSG="${PREFIX} ${MESSAGE}"
# 解析 CHAT_IDS JSON 陣列
if command -v jq &>/dev/null; then
CHAT_IDS=$(echo "$CHAT_IDS_RAW" | jq -r '.[]' 2>/dev/null)
else
CHAT_IDS=$(echo "$CHAT_IDS_RAW" | tr -d '[]" ' | tr ',' '\n')
fi
if [[ -z "$CHAT_IDS" ]]; then
echo "[tg_notify] CHAT_IDS 解析結果為空,跳過通知" >&2
exit 0
fi
while IFS= read -r CHAT_ID; do
[[ -z "$CHAT_ID" ]] && continue
printf '%s' "$FULL_MSG" | curl -s --max-time 10 -X POST \
"https://api.telegram.org/bot${TOKEN}/sendMessage" \
-d "chat_id=${CHAT_ID}" \
--data-urlencode "text@-" \
-d "parse_mode=HTML" > /dev/null || \
echo "[tg_notify] 發送到 ${CHAT_ID} 失敗(不阻斷流程)" >&2
done <<< "$CHAT_IDS"